Skip to content

Instantly share code, notes, and snippets.

@jkcgs
Created October 3, 2019 14:46
Show Gist options
  • Save jkcgs/9181829becb747750c791f7b2339ecb7 to your computer and use it in GitHub Desktop.
Save jkcgs/9181829becb747750c791f7b2339ecb7 to your computer and use it in GitHub Desktop.
Script mirror UFRO
#!/bin/bash
set -e
log() {
DATENOW=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$DATENOW] $1"
}
if [ "${REPONAME}x" = "x" ]; then
>&2 echo REPONAME is not set
exit 1
fi
MIRROR_URI=$(/opt/mirror/mirror_uri.sh)
MIRROR_CMD=$(/opt/mirror/mirror_cmd.sh)
MIRROR_BASE="/srv/mirror"
USAGE_FILE="$MIRROR_BASE/$REPONAME.usage.txt"
MIRROR_PATH="$MIRROR_BASE/$REPONAME"
if [ ! "${MIRROR_URI}x" = "x" ]; then
RSYNC_OPTS="-rtlpvH --delete-after --delay-updates --safe-links --progress"
log "Mirror URI: $MIRROR_URI"
log "Syncing $REPONAME repo..."
rsync $RSYNC_OPTS ${MIRROR_URI} ${MIRROR_PATH}
EXITCODE="$?"
log "Exit code: $EXITCODE"
elif [ ! "${MIRROR_CMD}x" = "x" ]; then
log "Running $REPONAME script: $MIRROR_CMD"
. $MIRROR_CMD
else
>&2 echo "Unknown repository"
exit 1
fi
log "Updating usage file..."
du -bs $MIRROR_PATH > $USAGE_FILE
log "$(cat $USAGE_FILE)"
log "Sync finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment