diff options
| author | emmett1 <me@emmett1.my> | 2026-05-29 23:40:06 +0800 |
|---|---|---|
| committer | emmett1 <me@emmett1.my> | 2026-05-29 23:40:06 +0800 |
| commit | 49717b9544bacbcd38a10b791adcb4a4aa2e9162 (patch) | |
| tree | d032595b7f70de43df9e485ce7da196bb125aee3 /reposync | |
| parent | 53900763c5574fe60beb877dda57ea76941f7cec (diff) | |
| download | autils-49717b9544bacbcd38a10b791adcb4a4aa2e9162.tar.gz autils-49717b9544bacbcd38a10b791adcb4a4aa2e9162.zip | |
updates
Diffstat (limited to 'reposync')
| -rwxr-xr-x | reposync | 63 |
1 files changed, 31 insertions, 32 deletions
@@ -1,19 +1,15 @@ #!/bin/sh -e # -# script to sync repos -# required /etc/reposync.conf -# -# /etc/reposync.conf format: -# <git url>|<branch>|<local path to sync> +# repo sync script (env-based: REPOSYNC_*) # log() { msg="$1" if [ "$LOG" ]; then - echo "$(date +'%Y-%m-%d %H:%M:%S') $msg" | tee -a "$LOGFILE" - else - echo "$msg" - fi + echo "$(date +'%Y-%m-%d %H:%M:%S') $msg" | tee -a "$LOGFILE" + else + echo "$msg" + fi } run_cmd() { @@ -29,27 +25,21 @@ syncrepo() { url=$1 branch=$2 path=$3 - - # if url is empty, do nothing - if [ ! "$url" ]; then - exit 0 - fi - - # if $path empty, your format is wrong - if [ ! "$path" ]; then - echo "/etc/reposync.conf format: <git url>|<branch>|<local path to sync>" - exit - fi - - if [ "$FORCE" ]; then - if [ -d "$path" ]; then - log "=> Force removing repo directory $path..." - run_cmd "rm -rf \"$path\"" - fi + + [ -z "$url" ] && return 0 + + if [ -z "$path" ]; then + log "error: invalid repo format (missing path)" + return 1 + fi + + if [ "$FORCE" ] && [ -d "$path" ]; then + log "=> Force removing repo directory $path..." + run_cmd "rm -rf \"$path\"" fi if [ ! -d "$path/.git" ]; then - log "=> Sync repo $path..." + log "=> Cloning repo into $path..." run_cmd "mkdir -p \"$path\"" run_cmd "git clone --branch \"$branch\" --single-branch \"$url\" \"$path\"" else @@ -68,6 +58,7 @@ usage() { exit 1 } +# --- args --- while [ "$1" ]; do case "$1" in -n) DRY_RUN=1;; @@ -78,20 +69,28 @@ while [ "$1" ]; do shift done +# --- checks --- command -v git >/dev/null 2>&1 || { echo "error: git is not installed." >&2 exit 1 } LOGFILE="/var/log/reposync.log" -CONFFILE="/etc/reposync.conf" -if [ ! -f "$CONFFILE" ]; then - echo "error: config file not found: $CONFFILE" >&2 - exit 1 +REPOS=$(env | grep '^REPOSYNC_' | sort || true) + +if [ -z "$REPOS" ]; then + echo "error: no REPOSYNC_* variables found." >&2 + exit 1 fi -grep -Ev '^#|^$' "$CONFFILE" | while IFS='|' read -r url branch path _; do +echo "$REPOS" | while IFS='=' read -r name value; do + IFS='|' read -r url branch path _ <<EOF +$value +EOF + + [ -z "$url" ] && continue + syncrepo "$url" "$branch" "$path" done |