Various changes to mirror.

* Use --no-user and --no-group when syncing.
* Introduce a test to make sure the script is run from the wrapper.
* Introduce a test to make sure the script is being run by the correct user.
* Do all testing before locking.
This commit is contained in:
Darren 'Tadgy' Austin 2026-05-23 23:41:42 +01:00
commit 0ef6396933

26
mirror
View file

@ -17,7 +17,7 @@ MAX_RUNS="3" # Maximum number of runs
IPV4="5.101.171.215"
DATADIR="/data/depository"
RSYNC_COMMAND="/usr/bin/rsync"
RSYNC_REMOTE_OPTIONS=('-4' "--address=$IPV4" '--no-motd' '--contimeout=30' '--timeout=60' '-aH' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates')
RSYNC_REMOTE_OPTIONS=('-4' "--address=$IPV4" '--no-motd' '--contimeout=30' '--timeout=60' '-aH' '--no-owner' '--no-group' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delete-delay' '--delay-updates')
RSYNC_LOCAL_OPTIONS=('-aH' '--chmod=go-w,+rX' '--partial' '--partial-dir=.rsync-tmp' '--delay-updates')
# RSYNC_VERBOSE=('--verbose' '--human-readable')
# RSYNC_VERBOSE=('--progress' '--verbose' '--stats' '--human-readable')
@ -163,6 +163,24 @@ SLACKARCHIVE_FILTER=('--exclude=source/' '--include=/slackware-15.0' '--include=
#######################################################################################################################################
# Only allow the script to be run from the wrapper.
[[ ! -v MIRRORING_USER ]] && {
echo "ERROR: this script should only be run by mirror-wrapper" >&2
exit 1
}
# Make sure the users match.
[[ "$(whoami)" != "$MIRRORING_USER" ]] && {
echo "ERROR: this script should be run by the '$MIRRORING_USER' only - use su to run manually" >&2
exit 1
}
# Move to the depository directory.
cd "$DATADIR" >/dev/null 2>&1 || {
echo "ERROR: $DATADIR does not exist." >&2
exit 1
}
# Only allow one copy of the script to run at any time.
# shellcheck disable=SC2154
if [[ "$FLOCK" != "$0" ]]; then
@ -178,12 +196,6 @@ if [[ "$FLOCK" != "$0" ]]; then
fi
fi
# Move to the depository directory.
cd "$DATADIR" >/dev/null 2>&1 || {
echo "ERROR: $DATADIR does not exist." >&2
exit 1
}
# Variables
declare -a LFTP_LIST RSYNC_LIST