Retidy
[grml-infrastructure.git] / deb.grml.org-mirrorscript
1 #! /bin/sh
2 set -e
3
4 echo "Please configure me!" 
5 exit
6 # This script originates from http://www.debian.org/mirror/anonftpsync
7 # modified by Martin Zobel-Helas <zobel@debian.org>, 2005-01-16
8 #       these modifications are published under the terms of the GNU GPL
9 # Modifications:
10 # + some more documentation about variables
11 # + added ARCH_EXCLUDE
12 # + mirror in a safe way, first /pool, then /dists and the rest
13
14 # Version: $Id: anonftpsync,v 1.19 2005/11/30 14:14:03 jfs Exp $ 
15
16
17 # Note: You MUST have rsync 2.0.16-1 or newer, which is available in slink
18 # and all newer Debian releases, or at http://rsync.samba.org/
19
20 # Set the variables below to fit your site. You can then use cron to have
21 # this script run daily to automatically update your copy of the archive.
22
23 # Don't forget:
24 # chmod 744 anonftpsync
25
26 # TO is the destination for the base of the Debian mirror directory
27 # (the dir that holds dists/ and ls-lR).
28 # (mandatory)
29 t
30 TO=/WHERE/TO/STORE
31
32 # RSYNC_HOST is the site you have chosen from the mirrors file.
33 # (http://www.debian.org/mirror/list-full)
34 # (mandatory)
35
36 RSYNC_HOST=deb.grml.org
37
38 # RSYNC_DIR is the directory given in the "Packages over rsync:" line of
39 # the mirrors file for the site you have chosen to mirror.
40 # (mandatory)
41
42 RSYNC_DIR=grml/
43
44 # LOGDIR is the directory where the logs will be written to
45 # (mandatory)
46
47 LOGDIR=/YOUR/LOGDIR/
48
49 # ARCH_EXCLUDE can be used to exclude a complete architecture from
50 # mirrorring. Please use as space seperated list.
51 # Possible values are:
52 # alpha, amd64, arm, hppa, hurd-i386, i386, ia64, m68k, mipsel, mips, powerpc, s390, sh and sparc
53 #
54 # There is one special value: source
55 # This is not an architecture but will exclude all source code in /pool
56 #
57 # eg.
58 # ARCH_EXCLUDE="alpha arm hppa hurd-i386 ia64 m68k mipsel mips s390 sparc"
59
60 # With a blank ARCH_EXCLUDE you will mirror all available architectures
61 # (optional)
62
63 ARCH_EXCLUDE=
64
65 # EXCLUDE is a list of parameters listing patterns that rsync will exclude.
66 # The following example would exclude mostly everything:
67 #EXCLUDE="\
68 #  --exclude binary-alpha/ --exclude binary-arm/ --exclude binary-i386/ \
69 #  --exclude binary-m68k/ --exclude binary-powerpc/ --exclude binary-sparc/ \
70 #  --exclude binary-ia64/ --exclude binary-mips*/ --exclude binary-hppa/ \
71 #  --exclude binary-sh/ --exclude binary-s390/ \
72 #  --exclude binary-hurd-i386/ \
73 #  --exclude *_alpha.deb --exclude *_arm.deb --exclude *_i386.deb \
74 #  --exclude *_m68k.deb --exclude *_powerpc.deb --exclude *_sparc.deb \
75 #  --exclude *_ia64.deb --exclude *_hppa.deb --exclude *_sh.deb \
76 #  --exclude *_mips.deb --exclude *_mipsel.deb --exclude *_s390.deb \
77 #  --exclude *_hurd-i386.deb \
78 #  --exclude disks-alpha/ --exclude disks-arm/ --exclude disks-i386/ \
79 #  --exclude disks-ia64/ --exclude disks-m68k/ --exclude disks-mips*/  \
80 #  --exclude disks-powerpc/  --exclude disks-s390/  --exclude disks-sparc/ \
81 #  --exclude stable/ --exclude testing/ --exclude unstable/ \
82 #  --exclude source/ \
83 #  --exclude *.orig.tar.gz --exclude *.diff.gz --exclude *.dsc \
84 #  --exclude /contrib/ --exclude /non-free/ \
85 # "
86
87 # With a blank EXCLUDE you will mirror the entire archive.
88 # (optional)
89
90 EXCLUDE=
91
92 # MAILTO is the address to send logfiles to;
93 # if it is not defined, no mail will be sent
94 # (optional)
95
96 MAILTO=YOUR@EMAIL
97
98 # There should be no need to edit anything below this point, unless there
99 # are problems.
100
101 #-----------------------------------------------------------------------------#
102
103 # Check for some environment variables
104 if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
105         echo "One of the following variables seems to be empty:"
106         echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
107         exit 2
108 fi
109
110 # Note: on some non-Debian systems, hostname doesn't accept -f option.
111 # If that's the case on your system, make sure hostname prints the full
112 # hostname, and remove the -f option. If there's no hostname command,
113 # explicitly replace `hostname -f` with the hostname.
114 HOSTNAME=`hostname -f`
115
116 LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"
117
118 # Exclude architectures defined in $ARCH_EXCLUDE
119 for ARCH in $ARCH_EXCLUDE; do
120         EXCLUDE=$EXCLUDE"\
121                 --exclude binary-$ARCH/ \
122                 --exclude disks-$ARCH/ \
123                 --exclude installer-$ARCH/ \
124                 --exclude Contents-$ARCH.gz \
125                 --exclude *_$ARCH.deb \
126                 --exclude *_$ARCH.udeb "
127         if [ "$ARCH" == "source" ]; then
128                 SOURCE_EXCLUDE="\
129                 --exclude *.tar.gz \
130                 --exclude *.diff.gz \
131                 --exclude *.dsc "
132         fi
133 done
134
135 # Logfile
136 LOGFILE=$LOGDIR/deb.grml.org.log
137
138 # Get in the right directory and set the umask to be group writable
139
140 cd $HOME
141 umask 002
142
143 # Check to see if another sync is in progress
144 if lockfile -! -l 43200 -r 0 "$LOCK"; then
145   echo ${HOSTNAME} is unable to start rsync, lock file exists
146   exit 1
147 fi
148 # Note: on some non-Debian systems, trap doesn't accept "exit" as signal
149 # specification. If that's the case on your system, try using "0".
150 trap "rm -f $LOCK > /dev/null 2>&1" exit
151
152 set +e
153
154 # First sync /pool
155 rsync --recursive --links --hard-links --times --verbose --delete --timeout=600\
156      $EXCLUDE $SOURCE_EXCLUDE \
157      $RSYNC_HOST::$RSYNC_DIR/pool/ $TO/pool/ >> $LOGFILE 2>&1
158 result=$?
159
160 if [ 0 = $result ]; then
161         # Now sync the remaining stuff
162         rsync --recursive --links --hard-links --times --verbose --delete-after --delay-updates \
163              --exclude "Archive-Update-in-Progress-${HOSTNAME}" \
164              --exclude "sync-${HOSTNAME}" \
165              --exclude "/pool/" \
166              $EXCLUDE \
167              $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1
168
169         date -u > "${TO}/sync-${HOSTNAME}"
170 else
171         echo "ERROR: Help, something weird happened" | tee -a $LOGFILE
172         echo "mirroring /pool exited with exitcode" $result | tee -a $LOGFILE
173 fi
174
175
176 if ! [ -z $MAILTO ]; then
177         mail -s "grml archive synced" $MAILTO < $LOGFILE
178 fi
179
180 savelog -q $LOGFILE
181