| 1 | #! /bin/bash |
| 2 | |
| 3 | set -e |
| 4 | set -u |
| 5 | |
| 6 | # psuhpdo script for Debian |
| 7 | # |
| 8 | # Copyright (C) 2008 Joerg Jaspert <joerg@debian.org> |
| 9 | # |
| 10 | # This program is free software; you can redistribute it and/or |
| 11 | # modify it under the terms of the GNU General Public License as |
| 12 | # published by the Free Software Foundation; version 2. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, but |
| 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | # General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this program; if not, write to the Free Software |
| 21 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | |
| 23 | # In case the admin somehow wants to have this script located someplace else, |
| 24 | # he can set BASEDIR, and we will take that. If it is unset we take ${HOME} |
| 25 | BASEDIR=${BASEDIR:-"${HOME}"} |
| 26 | |
| 27 | NAME="`basename $0`" |
| 28 | |
| 29 | |
| 30 | # Read our config file |
| 31 | . "${BASEDIR}/etc/${NAME}.conf" |
| 32 | |
| 33 | # Source our common functions |
| 34 | . "${BASEDIR}/etc/common" |
| 35 | |
| 36 | # Set sane defaults if the configfile didn't do that for us. |
| 37 | # The directory for our logfiles |
| 38 | LOGDIR=${LOGDIR:-"${BASEDIR}/log"} |
| 39 | # Our own logfile |
| 40 | LOG=${LOG:-"${LOGDIR}/${NAME}.log"} |
| 41 | # How many logfiles to keep |
| 42 | LOGROTATE=${LOGROTATE:-14} |
| 43 | # Our mirrorfile |
| 44 | MIRRORS=${MIRRORS:-"${BASEDIR}/etc/${NAME}.mirror"} |
| 45 | # used by log() |
| 46 | PROGRAM=${PROGRAM:-"${NAME}-$(hostname -s)"} |
| 47 | # extra ssh options we might want hostwide |
| 48 | SSH_OPTS=${SSH_OPTS:-""} |
| 49 | # Which ssh key to use? |
| 50 | KEYFILE=${KEYFILE:-".ssh/pushpackages"} |
| 51 | # which path to "mirror" |
| 52 | MIRRORPATH=${MIRRORPATH:-"/org/packages.debian.org/mirror/"} |
| 53 | # where to send mails to |
| 54 | if [ "x$(hostname -s)x" != "x${MIRRORNAME%%.debian.org}x" ]; then |
| 55 | # We are not on a debian.org host |
| 56 | MAILTO=${MAILTO:-"root"} |
| 57 | else |
| 58 | # Yay, on a .debian.org host |
| 59 | MAILTO=${MAILTO:-"mirrorlogs@debian.org"} |
| 60 | fi |
| 61 | |
| 62 | if ! [ -f "${BASEDIR}/${KEYFILE}" ]; then |
| 63 | error "SSH Key ${BASEDIR}/${KEYFILE} does not exist" >> ${LOG} |
| 64 | exit 5 |
| 65 | fi |
| 66 | |
| 67 | # Some sane defaults |
| 68 | cd ${BASEDIR} |
| 69 | umask 022 |
| 70 | |
| 71 | # Make sure we have our log and lock directories |
| 72 | mkdir -p "${LOGDIR}" |
| 73 | |
| 74 | trap 'log "Pdopush done" >> ${LOG}; savelog "${LOG}" > /dev/null' EXIT |
| 75 | |
| 76 | log "Pushing pdo mirrors" >> ${LOG} |
| 77 | |
| 78 | # From here on we do *NOT* want to exit on errors. We don't want to |
| 79 | # stop pushing mirrors just because we can't reach one of them. |
| 80 | set +e |
| 81 | |
| 82 | |
| 83 | # Now read our mirrorfile and push the mirrors defined in there. |
| 84 | # We use grep to easily sort out all lines having a # in front of them or are empty. |
| 85 | egrep -v '^[[:space:]]*(#|$)' "${MIRRORS}" | |
| 86 | while read MLNAME MHOSTNAME MUSER MPROTO MKEYFILE; do |
| 87 | # Process the two options that can be left blank in the config |
| 88 | if [ -z ${MPROTO} ]; then |
| 89 | MPROTO=2 |
| 90 | fi |
| 91 | if [ -z ${MKEYFILE} ]; then |
| 92 | MKEYFILE="${BASEDIR}/${KEYFILE}" |
| 93 | fi |
| 94 | # Now, people can do stupid things and leave out the protocol, but |
| 95 | # define a keyfile... |
| 96 | if [ ${MPROTO} -ne 1 ] && [ ${MPROTO} -ne 2 ]; then |
| 97 | error "Need a correct ssh protocol version for ${MLNAME}, skipping" >> ${LOG} |
| 98 | continue |
| 99 | fi |
| 100 | |
| 101 | # And finally, push the mirror |
| 102 | log "Pushing ${MLNAME}" >> ${LOG} |
| 103 | # This needs a limited ssh key on the other side, something like |
| 104 | # no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty,command="rsync --server -vlogDtpr . /srv/mirrors/packages.debian.org/",from="87.106.64.223,2001:8d8:80:11::35d,powell.debian.org" ssh-rsa..... |
| 105 | rsync -e "ssh -i ${MKEYFILE} -${MPROTO} ${SSH_OPTS}" -av --stats "${MIRRORPATH}" ${MUSER}@${MHOSTNAME}:/does/not/matter >"${LOGDIR}/${MLNAME}.log" |
| 106 | log "Pushing ${MLNAME} done" >> ${LOG} |
| 107 | savelog ${LOGDIR}${MLNAME}.log |
| 108 | |
| 109 | set +e |
| 110 | done |
| 111 | |
| 112 | exit 0 |