#! /bin/bash if [[ ! -f $HOME/etc/debian-cd-mirror.conf ]]; then echo "No $HOME/etc/debian-cd-mirror.conf !" exit 4 fi . $HOME/etc/debian-cd-mirror.conf export RSYNC_PASSWORD PATH=${HOME}/bin:/usr/gnu/bin:/usr/local/bin:/usr/bin:/bin export PATH HOST=`hostname -f` LOCK="${TO}/Archive-Update-in-Progress-${HOST}" LOGFILE=$LOGDIR/debian-cd-mirror.log # Get in the right directory and set the umask to be group writable # cd $HOME umask 022 # Check to see if another sync is in progress if lockfile -! -l 43200 -r 0 "$LOCK"; then echo ftp is unable to start rsync, lock file exists exit 1 fi trap 'rm -f $LOCK > /dev/null 2>&1; echo -n "Done at " >> $LOGFILE; date >> $LOGFILE; savelog $LOGFILE > /dev/null' EXIT # Deleting the images before the run if DELETEFIRST is set. if [ $DELETEFIRST ]; then echo "Removing images not on the other host:" >> $LOGFILE let NRSYNCS++ rsync -av --delete --ignore-existing --existing --exclude "$EXCLUDE" \ $RSYNC_USER@$RSYNC_HOST::${MODULE} ${TO} >>$LOGFILE 2>&1 if [ `grep -c '^total size is' $LOGFILE ` -ne $NRSYNCS ]; then ( echo "Eeek. Debian jigdo rsync broke down... Check logs.."; \ egrep '^write failed|@ERROR' $LOGFILE ) | mail -s "Debian-cd sync failed" $ERRORMAIL echo "Eeek. Debian jigdo rsync broke down..." >> $LOGFILE exit 1 fi fi let NRSYNCS++ rsync -avH --delete --delete-after \ --timeout 7200 \ --exclude "Archive-Update-in-Progress-${HOST}" \ --exclude "project/trace/${HOST}" \ --exclude "project/trace/cdimage.debian.org" \ --exclude "$EXCLUDE" \ --exclude "*.iso" \ $RSYNC_USER@$RSYNC_HOST::${MODULE} ${TO} >> $LOGFILE 2>&1 if [ `grep -c '^total size is' $LOGFILE ` -ne $NRSYNCS ]; then ( echo "Eeek. Debian jigdo rsync broke down... Check logs.."; \ egrep '^write failed|@ERROR' $LOGFILE ) | mail -s "Debian-cd sync failed" $ERRORMAIL echo "Eeek. Debian jigdo rsync broke down..." >> $LOGFILE exit 1 fi echo -n "jigdo rsync done, now generating images. at " >> $LOGFILE date >> $LOGFILE typeset currentVersion=`ls -l ${TO}/current` currentVersion="${currentVersion##* -> }" versionDir="${TO}/${currentVersion}" for a in ${versionDir}/*/; do arch=`basename $a` sets=`cat ${TO}/project/build/${currentVersion}/${arch}` for s in $sets; do typeset jigdoDir=${TO}/${currentVersion}/${arch}/jigdo-${s} typeset imageDir=${TO}/${currentVersion}/${arch}/iso-${s} if [[ ! -d $imageDir ]]; then echo "Creating $imageDir" >> $LOGFILE mkdir -p $imageDir fi cp $jigdoDir/MD5SUMS $imageDir/MD5SUMS echo "jigdoDir=$jigdoDir" > $jigdoConf.$arch.$s echo "imageDir=$imageDir" >> $jigdoConf.$arch.$s echo "tmpDir=$tmpDirBase/$arch.$s" >> $jigdoConf.$arch.$s echo "logfile=${LOGDIR}/$arch.$s.log" >> $jigdoConf.$arch.$s cat ${jigdoConf}.in >> $jigdoConf.$arch.$s echo -n "jigdoing $arch-$s, starting at " >>$LOGFILE date >> $LOGFILE jigdo-mirror $jigdoConf.$arch.$s >>$LOGFILE done done savelog ${LOGDIR}/*.log >> $LOGFILE echo -n "jigdo-mirror done, now doing final rsync. at " >> $LOGFILE date >> $LOGFILE let NRSYNCS++ rsync -avH -n --delete --delete-after \ --timeout 7200 --size-only\ --exclude "Archive-Update-in-Progress-${HOST}" \ --exclude "project/trace/${HOST}" \ --exclude "$EXCLUDE" \ $RSYNC_USER@$RSYNC_HOST::$MODULE/. $TO/. >> $LOGFILE 2>&1 if [ `grep -c '^total size is' $LOGFILE ` -ne $NRSYNCS ]; then ( echo "Eeek. Debian cdimage rsync broke down... Check logs.."; \ egrep '^write failed|@ERROR' $LOGFILE ) | mail -s "Debian-cd sync failed" $ERRORMAIL echo "Eeek. Debian cdimage rsync broke down..." >> $LOGFILE exit 2 fi echo -n "second sync with delete done at " >> $LOGFILE date >> $LOGFILE rm -f $LOCK > /dev/null 2>&1 date -u > "${TO}/project/trace/${HOST}"