diff --git a/script/ArchInitializeMirrorSync.sh b/script/ArchInitializeMirrorSync.sh new file mode 100644 index 0000000..c9b8c58 --- /dev/null +++ b/script/ArchInitializeMirrorSync.sh @@ -0,0 +1,76 @@ +#!/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 + +verifymasterstatus + +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://frankfurt.mirror.pkgbuild.com/packages/' + +lastupdate_url='https://frankfurt.mirror.pkgbuild.com/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 + + diff --git a/script/VerifyUpstreamPuller.sh b/script/VerifyUpstreamPuller.sh new file mode 100644 index 0000000..e018439 --- /dev/null +++ b/script/VerifyUpstreamPuller.sh @@ -0,0 +1,21 @@ +#!/bin/bash +RSYNC_URL="rsync://delta:874/archlinux" +attempt=1 +max_attempts=3 +reached=false + +while [ $attempt -le $max_attempts ] && [ "$reached" = false ]; do + if rsync --dry-run --timeout=10 "$RSYNC_URL" 2>/dev/null; then + reached=true + echo "OK" + else + echo "$attempt KO" + attempt=$((attempt + 1)) + sleep 10 + fi +done + +if [ "$reached" = false ]; then + exit 1 +fi +exit 0