summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Jaspert <joerg@debian.org>2008-09-27 16:49:49 +0200
committerJoerg Jaspert <joerg@debian.org>2008-09-27 16:49:49 +0200
commit089f3fa85ae2d128b5e5b190ee6c99d0b9ca499a (patch)
tree2e9ef334d43af7566945ff6ffdb50c107d4282a0
parent83c5a8c6a5b21081a9d665817342edee53fc10b9 (diff)
runmirrors
add a script to push leaf mirrors Signed-off-by: Joerg Jaspert <joerg@debian.org>
-rwxr-xr-xbin/runmirrors89
-rw-r--r--etc/runmirrors.conf8
-rw-r--r--etc/runmirrors.mirror17
3 files changed, 114 insertions, 0 deletions
diff --git a/bin/runmirrors b/bin/runmirrors
new file mode 100755
index 0000000..ed6ead4
--- /dev/null
+++ b/bin/runmirrors
@@ -0,0 +1,89 @@
+#! /bin/bash
+
+set -e
+
+# runmirrors script for Debian
+# Based losely on existing scripts, written by an unknown number of
+# different people over the years.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# Read our config file
+NAME="`basename $0`"
+. ${HOME}/etc/${NAME}.conf
+
+# Make sure some variables are always in the environment
+export HOME LOGNAME USER PATH
+
+# Source our common functions
+. ${HOME}/etc/common
+
+# Set sane defaults if the configfile didn't do that for us.
+LOGDIR=${LOGDIR:-"${HOME}/log"}
+LOG=${LOG:-"${LOGDIR}/$0.log"}
+SAVELOG=${SAVELOG:-"savelog -t -c 14"}
+# used by log()
+PROGRAM=${PROGRAM:-"ftpsync-$(hostname -s)"}
+
+
+# Make sure we have our log directory
+mkdir -p ${LOG}
+
+# Some sane defaults
+cd ${HOME}
+umask 002
+
+trap 'log "Mirrorpush done"; ${SAVELOG} "${LOG}" > /dev/null' EXIT
+
+# Start log by redirecting everything there.
+exec >"${LOG}" 2>&1
+
+log "Pushing leaf mirrors"
+
+# Set the HOOKSCRIPT variable in the config file if you want to run an
+# extra script right before the mirrors get pushed
+if [ -n ${HOOKSCRIPT} ]; then
+ log "Running hook ${HOOKSCRIPT}"
+ ${HOOKSCRIPT}
+ log "Hook finished with errorcode $?"
+fi
+
+# From here on we do *NOT* want to exit on errors. We don't want to
+# stop pushing mirrors just because we can't reach one atm.
+set +e
+
+# Now read our mirrorfile and push the mirrors defined in there.
+# We use grep to easily sort out all lines having a # in front of them.
+grep -v ^# ${HOME}/etc/runmirrors.mirror |
+while read MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do
+ # Process the two options that can be left blank in the config
+ if [ -z ${MPROTO} ]; then
+ MPROTO=2
+ fi
+ if [ -z ${MKEYFILE} ]; then
+ MKEYFILE="${HOME}/${KEYFILE}"
+ fi
+ # Now, people can do stupid things and leave out the protocol, but
+ # define a keyfile...
+ if [ ${MPROTO} -ne 1 ] && [ ${MPROTO} -ne 2 ]; then
+ error "Need a correct ssh protocol version for ${MLNAME}, skipping"
+ continue
+ fi
+
+ # And finally, push the mirrors
+ log "Trigger ${MLNAME}"
+ signal ${MLNAME} ${MHOSTNAME} ${MUSER} ${MPROTO} ${MKEYFILE}
+done
+
+exit 0
diff --git a/etc/runmirrors.conf b/etc/runmirrors.conf
new file mode 100644
index 0000000..da7404d
--- /dev/null
+++ b/etc/runmirrors.conf
@@ -0,0 +1,8 @@
+HOME=~archvsync
+LOGNAME="archvsync"
+USER="archvsync"
+MAIL=
+PATH="/bin:/usr/bin:$HOME"
+HOOKSCRIPT=
+KEYFILE=${HOME}/.ssh/pushmirror
+LOG=${HOME}/log/
diff --git a/etc/runmirrors.mirror b/etc/runmirrors.mirror
new file mode 100644
index 0000000..7fa7a38
--- /dev/null
+++ b/etc/runmirrors.mirror
@@ -0,0 +1,17 @@
+# Definition of mirror hosts we push.
+# One mirror per line, with the following fields defined.
+#
+# ShortName HostName User SSHProtocol SSHKeyFile
+#
+# ShortName will be used as a shorthand in logfile outputs and for the logfile
+# where every ssh output gets redirected to.
+#
+# If no SSHKeyFile is given, the default from the config file applies.
+# If SSHProtocol is empty, it will default to 2, but if you want to
+# define a keyfile you HAVE TO set protocol too!
+#
+# Example:
+# eu.puccini puccini.debian.org archvsync 2 ~/.ssh/push_puccini
+#
+# will push puccini.debian.org, user archvsync, using ssh protocol 2 and the specified ssh key.
+