31 lines
981 B
Bash
31 lines
981 B
Bash
#!/usr/bin/with-contenv bashio
|
|
RECIPES_PATH=/config/recipes
|
|
|
|
exec 9>/tmp/git-sync.lock
|
|
flock -n 9 || { bashio::log.info "Synchro déjà en cours"; exit 0; }
|
|
|
|
REPO=$(bashio::config 'git_repository')
|
|
BRANCH=$(bashio::config 'git_branch')
|
|
USERNAME=$(bashio::config 'git_username')
|
|
PASSWORD=$(bashio::config 'git_password')
|
|
|
|
if [ -z "$REPO" ]; then
|
|
bashio::log.info "Aucun dépôt Git configuré."
|
|
exit 0
|
|
fi
|
|
|
|
AUTH_URL="$REPO"
|
|
if [ -n "$USERNAME" ] && [ -n "$PASSWORD" ]; then
|
|
STRIPPED="${REPO#https://}"; STRIPPED="${STRIPPED#http://}"
|
|
AUTH_URL="https://${USERNAME}:${PASSWORD}@${STRIPPED}"
|
|
fi
|
|
|
|
if [ ! -d "$RECIPES_PATH/.git" ]; then
|
|
bashio::log.info "Premier clone du dépôt..."
|
|
git clone --branch "$BRANCH" "$AUTH_URL" "$RECIPES_PATH"
|
|
else
|
|
bashio::log.info "Mise à jour du dépôt existant..."
|
|
git -C "$RECIPES_PATH" fetch origin "$BRANCH"
|
|
git -C "$RECIPES_PATH" reset --hard "origin/$BRANCH"
|
|
fi
|
|
bashio::log.info "Synchronisation Git terminée." |