#!/bin/bash NO_FORMAT="\e[0m" C_RED="\e[38;5;9m" PC=$(uname -n | awk '{print $1}') #Verify if root if [ "$UID" -ne 0 ]; then echo -e "${C_RED}This script must be run as root.${NO_FORMAT}" exit 1 fi rsync_cmd() { local -a cmd=(rsync -rlptH --safe-links --delete-delay --delay-updates "--timeout=600" "--contimeout=60" --no-motd) if stty &>/dev/null; then cmd+=(-h -v --progress) else cmd+=(--quiet) fi if ((bwlimit>0)); then cmd+=("--bwlimit=$bwlimit") fi "${cmd[@]}" "$@" } if [ "$PC" = "Nasperon" ] then target="/mnt/POOL3/Mirrors/archlinux/data" lock="/mnt/POOL3/Mirrors/archlinux/syncrepo.lck" else target="/mnt/POOL1/Mirrors/archlinux/data" lock="/mnt/POOL1/Mirrors/archlinux/syncrepo.lck" fi bwlimit=0 source_url='rsync://delta:874/archlinux' lastupdate_url='https://delta:18650/archlinux/lastupdate' [ ! -d "${target}" ] && mkdir -p "${target}" exec 9>"${lock}" flock -n 9 || exit find "${target}" -name '.~tmp~' -exec rm -r {} + if ! tty -s && [[ -f "$target/lastupdate" ]] && diff -b <(curl -Ls "$lastupdate_url") "$target/lastupdate" >/dev/null; then rsync_cmd "$source_url/lastsync" "$target/lastsync" exit 0 fi rsync_cmd \ --exclude='*.links.tar.gz*' \ --exclude='/other' \ --exclude='/sources' \ "${source_url}" \ "${target}" echo "Last sync was $(date -d @$(cat ${target}/lastsync))" if [ "$PC" = "Nasperon" ] then chmod 775 -R /mnt/POOL3/Mirrors chown 1000:1002 -R /mnt/POOL3/Mirrors else chmod 775 -R /mnt/POOL1/Mirrors chown 1000:1001 -R /mnt/POOL1/Mirrors fi exit