mirror-functions	rsync mirror() function in bash.
	Uses: basename, cat, date, df, echo, printf and stat (all six in
	  coreutils), bc, gawk, lockfile (procmail), sed, uptime (procps).
	Features:
	- can be run from cron or by hand,
	- locking,
	- mirrors of several packages can be defined in one script,
	- a separate frequency limit for each package in the script can be set
	  (gap=HOURS),
	- dry run (-n option) to show the actual rsync command,
	- running only nth mirror() in the script can be forced overriding the
	  gap value (e.g. -f 5) or even overriding the load limit too (-F …),
	  it does not override locking,
	- remembers when the recent mirroring of a package took place and if
	  it was successful (using .… files in ~ directory),
	- an rsync filter is created from the arguments on mirror call line,
	  uses ~ directory,
	- the mirroring can be completely blocked by creating ~/MIRROR_OFF
	  file (its contents will be shown in mirrors logs),
	- minfree variable defines minimum free space the mirror will run
	  with.

mirrormail		simple script to use with crontab which sets subject
			of an e-mail; the recipient is hardcoded as "mirror",
			create such an alias or change it in the script

~/.mirror-functions	variables; default values are in mirror-functions
			script, ~/.mirror-functions overrides them, they can
			be changed before every mirror() call


linux-debian		sample rsync scripts; use -h option to see help
linux-debian.output	output of the script
linux-archlinux
linux-redhat

rzm@sunsite3:/private/rzm/sunsite/2021-09,0> /local/scripts/mirror/linux-debian -h
RUNNING /local/scripts/mirror/linux-debian -h    Versions: 2021-09-08 00:05:08 (the current script), 2021-09-11 23:58:25 (mirror-functions)
/local/scripts/mirror/linux-debian [-h] [-f [NUM]] [-n]
Script for mirroring rsync packages backed by mirror-functions library.
-h              this help
-f [NUM]        mirror even if the gap time set in the script have not passed.
                With NUM converns only package number NUM (conting from 1)
-F [NUM]        as -f and bypass the load limit by setting it to 1000
-n              dry run - do not execute rsync commans


Syntax:
# sourcing the function
. /local/scripts/mirror/mirror-functions
  
# before each call to the mirror() function one can set non-default
# - rsync program path (rsync=…; default: rsync),
# - options (options=…; default can be read from $defoptions variable),
# - e-mail for error messages (email=…; default: `whoami`),
# - time gap (gap=…; default: 2 [hours]) which limits frequency of mirroring - not sooner than gap after last successfull mirroring
# At first mirroring attempt mirror() assumes that the previous one was 100000 hours ago.

# example of "options" setting:
options="-rtlvH --delete-after --delay-updates --safe-links --max-delete=1000 --timeout=3600"   # official? + timeout
# changing time gap (can be done before each mirror() call
gap=24 #h
# actual call: mirror SOURCE_RSYNC_URL [DESTINATION_DIRECTORY [FILTER...]]
# the $p variable contains our default path to all packages defined in
# mirror-functions or ~/.mirror-functions file but it does not have to be
# used
# with no DESTINATION_DIRECTORY the default is $p/DIR, where DIR is the last
# part of the SOURCE_RSYNC_URL (if it is ended with / or not),
# this call includes one entry for rsync filter
mirror	rsync://ftp5.gwdg.de/pub/linux/archlinux/	$p/linux-archlinux	"- **~tmp~**"


# sample crontab entries:
# Debian mirrors except those mirrored with Debian ftpsync script, run every two hours
51 */2		* * *	/local/scripts/mirror/linux-debian			2>&1 | ~/bin/mirrormail linux-debian
# randomized start
0 *		* * *	echo | awk 'END { t=55*60*rand(); system("sleep "t) }'; /local/scripts/mirror/linux-archlinux	2>&1 | ~/bin/mirrormail linux-archlinux
