User:Ncopa/Alpine Mirror with MQTT

From Alpine Linux
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
dl-1:~# cat /etc/conf.d/mqtt-exec.alpine-mirror 
#
mqtt_topics="rsync/rsync.alpinelinux.org/#"
exec_user=buildozer   
exec_command=/usr/local/bin/alpine-mirror

dl-1:~# cat /usr/local/bin/alpine-mirror 
#!/bin/sh -x

# make sure we never run 2 rsync at the same time
lockfile="/tmp/alpine-mirror.lock"
if [ -z "$flock" ] ; then
	exec env flock=1 flock $lockfile $0 "$@"
fi

rsync_opts=
while getopts "vP" opt; do
	case $opt in
	v|P) rsync_opts="$rsync_opts -$opt";;
	esac
done
shift $(( $OPTIND - 1 ))

topic=$1
dir=$2

#src=rsync://rsync.alpinelinux.org/alpine/ 
src=rsync://nl.alpinelinux.org/alpine/
dest=/var/www/localhost/htdocs/alpine/

if [ -n "$dir" ] && [ -d "$dest/${dir%/*}" ]; then
	src="${src}${dir%/}/"
	dest="${dest}${dir%/}/"
fi

# uncomment this to only include v1.8 or newer
#exclude="--exclude v1.[1-7]"

mkdir -p "$dest"
/usr/bin/rsync -prua \
        $exclude \
        --delete \
        --timeout=600 \
        --delay-updates \
        --delete-after \
	$rsync_opts \
        "$src" "$dest"
dl-1:~#