Skip to content

Instantly share code, notes, and snippets.

@kakwa
Last active November 18, 2021 18:56
Show Gist options
  • Save kakwa/0968c2e6004da6f924d2 to your computer and use it in GitHub Desktop.
Save kakwa/0968c2e6004da6f924d2 to your computer and use it in GitHub Desktop.
#!/bin/sh
MIRROR="rsync://mirror.yandex.ru/mirrors/jenkins/plugins/"
OUT="./"
help(){
cat <<EOF
usage: `basename $0` [-o <out>] [-m <mirror>]
Recover only the latest version of all the jenkins plugins
arguments:
-o <out>: output directory
default: $OUT
-m <mirror>: the rsync mirror to use
default: $MIRROR
EOF
exit 1
}
while getopts ":ho:m:" opt; do
case $opt in
h)
help
;;
o)
OUT="$OPTARG"
;;
m)
MIRROR="$OPTARG"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
help
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
help
exit 1
;;
esac
done
# Recover all the 'latest' symlinks
mkdir -p "$OUT/"
rsync -lK -uvma --include='**/latest***' --include='**/' --exclude='**/**' "$MIRROR/" "$OUT/"
# Recover the actual latest version (from the symlink destination)
find "$OUT/" -type l -name "latest" | while read line; do
# recover the version and the plugin name
versionpath=`readlink -f "$line"` ;
version=`basename "$versionpath"`
pluginpath=`dirname "$versionpath"`
plugin=`basename "$pluginpath"`
# create the destination directory
mkdir -p "$versionpath"
# synchronize the plugin
rsync -uvma "$MIRROR/$plugin/$version/" "$versionpath"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment