Skip to content

Instantly share code, notes, and snippets.

@ThisCatLikesCrypto
Last active September 2, 2025 14:06
Show Gist options
  • Select an option

  • Save ThisCatLikesCrypto/2fd5864db19bfee27c4f6b73545c54f8 to your computer and use it in GitHub Desktop.

Select an option

Save ThisCatLikesCrypto/2fd5864db19bfee27c4f6b73545c54f8 to your computer and use it in GitHub Desktop.
Script to check if the lastupdate file on the chaotic AUR main mirror server has changed, and if yes to synchronise from it.
#!/usr/bin/env bash
set -e
target="/srv/repo/chaotic"
tmp="/tmp/chaotic-tmp"
lock="/tmp/.chaotic-sync-lock"
bwlimit=0
source_url='rsync://builds.garudalinux.org/chaotic/'
lastupdate_url='https://builds.garudalinux.org/repos/chaotic-aur/lastupdate'
[ ! -d "${target}" ] && mkdir -p "${target}"
[ ! -d "${tmp}" ] && mkdir -p "${tmp}"
exec 9>"${lock}"
flock -n 9 || exit
rsync_cmd() {
local -a cmd=(rsync -rlptH --delete-delay --delay-updates --safe-links --max-delete=1000 \
"--timeout=600" "--contimeout=60" --no-motd "--temp-dir=${tmp}")
if stty &>/dev/null; then
cmd+=(-h -v --progress)
else
cmd+=(--quiet)
fi
if ((bwlimit>0)); then
cmd+=("--bwlimit=$bwlimit")
fi
"${cmd[@]}" "$@"
}
# Only run when there are changes
if [[ -f "$target/chaotic-aur/lastupdate" ]] && diff -b <(curl -Ls "$lastupdate_url") "$target/chaotic-aur/lastupdate" >/dev/null; then
exit 0
fi
rsync_exclude=("--exclude=/info")
rsync_exclude+=("--exclude=/lastsync")
rsync_cmd \
"${rsync_exclude[@]}" \
"${source_url}" \
"${target}"
date -u "+%s" > "$target/chaotic-aur/lastsync"
echo "Last sync was $(date -d @"$(cat ${target}/chaotic-aur/lastsync)" --rfc-3339=seconds -u)" > "${target}/info"
echo "Last update was $(date -d @"$(cat ${target}/chaotic-aur/lastupdate)" --rfc-3339=seconds -u)" >> "${target}/info"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment