summaryrefslogtreecommitdiff
path: root/hurd/running/debian/creating_image_tarball/anonftpsync-ports
blob: 0988dbdec6210bc065ae9ac15aadcb757a41da43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#! /bin/sh
set -e

# This script originates from http://www.debian.org/mirror/anonftpsync
# modified by Martin Zobel-Helas <zobel@debian.org>, 2005-01-16
# 	these modifications are published under the terms of the GNU GPL
# Modifications:
# + some more documentation about variables
# + added ARCH_EXCLUDE
# + mirror in a safe way, first /pool, then /dists and the rest
# modified by Aurelien Jarno <aurel32@debian.org>, 2007-12-02
# 	these modifications are published under the terms of the GNU GPL
# + modifications to mirror debia,-ports.org
# Version: $Id: anonftpsync,v 1.18 2005/10/28 15:25:54 aba Exp $ 


# Note: You MUST have rsync 2.0.16-1 or newer, which is available in slink
# and all newer Debian releases, or at http://rsync.samba.org/

# Set the variables below to fit your site. You can then use cron to have
# this script run daily to automatically update your copy of the archive.

# Don't forget:
# chmod 744 anonftpsync

# TO is the destination for the base of the Debian mirror directory
# (the dir that holds dists/ and ls-lR).
# (mandatory)

TO=/home/foo/rsync-debian-ports

# RSYNC_HOST is the site you have chosen from the mirrors file.
# (http://www.debian-ports.org/mirrors)
# (mandatory)

RSYNC_HOST=rsync.debian-ports.org

# RSYNC_DIR is the directory given in the "Packages over rsync:" line of
# the mirrors file for the site you have chosen to mirror.
# (mandatory)

RSYNC_DIR=debian/

# LOGDIR is the directory where the logs will be written to
# (mandatory)

LOGDIR=/var/log/rsync-debian-ports

# ARCH_EXCLUDE can be used to exclude a complete architecture from
# mirrorring. Please use as space seperated list.
# Possible values are:
# armel hurd-i386 kfreebsd-amd64 kfreebsd-i386
#
# There is one special value: source
# This is not an architecture but will exclude all source code in /pool
#
# eg.
# ARCH_EXCLUDE="hurd-i386"
# 
# With a blank ARCH_EXCLUDE you will mirror all availible architectures
# (optional)

ARCH_EXCLUDE="armel kfreebsd-amd64 kfreebsd-i386 m68k"

# EXCLUDE is a list of parameters listing patterns that rsync will exclude.
# The following example would exclude mostly everything:
#EXCLUDE="\
#  --exclude binary-hurd-i386/ --exclude binary-kfreebsd-i386/
#  --exclude *_hurd-i386.deb --exclude *_knetbsd-i386.deb \
#  --exclude stable/ --exclude testing/ --exclude unstable/ \
#  --exclude source/ \
#  --exclude *.orig.tar.gz --exclude *.diff.gz --exclude *.dsc \
#  --exclude /base/ --exclude /bochs/ --exclude /obsolete/ \
# "

# With a blank EXCLUDE you will mirror the entire archive.
# (optional)

EXCLUDE="--exclude binary-kfreebsd-i386/ --exclude *_knetbsd-i386.deb \
         --exclude source/ --exclude *.orig.tar.gz --exclude *.diff.gz \
         --exclude /bochs/ --exclude /obsolete/ \
         --exclude *kfreebsd* --exclude *m68* --exclude *sh* \
	 "

# MAILTO is the address to send logfiles to;
# if it is not defined, no mail will be sent
# (optional)

MAILTO=

# There should be no need to edit anything below this point, unless there
# are problems.

#-----------------------------------------------------------------------------#

# Check for some environment variables
if [ -z $TO ] || [ -z $RSYNC_HOST ] || [ -z $RSYNC_DIR ] || [ -z $LOGDIR ]; then
	echo "One of the following variables seems to be empty:"
	echo "TO, RSYNC_HOST, RSYNC_DIR or LOGDIR"
	exit 2
fi

if ! [ -d ${TO}/project/trace/ ]; then
	# we are running mirror script for the first time
	mkdir -p ${TO}/project/trace
fi

# Note: on some non-Debian systems, hostname doesn't accept -f option.
# If that's the case on your system, make sure hostname prints the full
# hostname, and remove the -f option. If there's no hostname command,
# explicitly replace `hostname -f` with the hostname.
HOSTNAME=`hostname -f`

LOCK="${TO}/Archive-Update-in-Progress-${HOSTNAME}"

# Exclude architectures defined in $ARCH_EXCLUDE
for ARCH in $ARCH_EXCLUDE; do
	EXCLUDE=$EXCLUDE"\
		--exclude binary-$ARCH/ \
		--exclude disks-$ARCH/ \
		--exclude installer-$ARCH/ \
		--exclude Contents-$ARCH \
		--exclude Contents-$ARCH.gz \
		--exclude *_$ARCH.deb \
		--exclude *_$ARCH.udeb \
		--exclude pool-$ARCH/"
	if [ "$ARCH" == "source" ]; then
		SOURCE_EXCLUDE="\
		--exclude *.tar.gz \
		--exclude *.diff.gz \
		--exclude *.dsc "
	fi
done

# Logfile
LOGFILE=$LOGDIR/debian-mirror-ports.log

# Get in the right directory and set the umask to be group writable
# 
cd $HOME
umask 002

# Check to see if another sync is in progress
if lockfile -! -l 10800 -r 0 "$LOCK"; then
  echo ${HOSTNAME} is unable to start rsync, lock file exists
  exit 1
fi
# Note: on some non-Debian systems, trap doesn't accept "exit" as signal
# specification. If that's the case on your system, try using "0".
trap "rm -f $LOCK > /dev/null 2>&1" exit

set +e

# First sync /pool-*
rsync --recursive --links --hard-links --times --verbose \
     $EXCLUDE $SOURCE_EXCLUDE \
     $RSYNC_HOST::$RSYNC_DIR/pool-* $TO >> $LOGFILE 2>&1
result=$?

if [ 0 = $result ]; then
	# Now sync the remaining stuff
	rsync --recursive --links --hard-links --times --verbose --delete-after \
	     --exclude "Archive-Update-in-Progress-${HOSTNAME}" \
	     --exclude "project/trace/" \
	     --exclude "/pool-*/" \
	     $EXCLUDE \
	     $RSYNC_HOST::$RSYNC_DIR $TO >> $LOGFILE 2>&1

	date -u > "${TO}/project/trace/${HOSTNAME}"
else
	echo "ERROR: Help, something weird happened" | tee -a $LOGFILE
	echo "mirroring /pool-* exited with exitcode" $result | tee -a $LOGFILE
fi


if ! [ -z $MAILTO ]; then
	mail -s "debian ports archive synced" $MAILTO < $LOGFILE
fi

savelog $LOGFILE