]> git.decadent.org.uk Git - dak.git/blob - scripts/debian/byhand-di
f8e5f6ba4d5796e975c092db795fa3aa6a38bdbb
[dak.git] / scripts / debian / byhand-di
1 #!/bin/sh
2
3 set -u
4 set -e
5
6 if [ $# -lt 4 ]; then
7         echo "Usage: $0 filename version arch changes_file"
8         exit 1
9 fi
10
11 TARBALL="$1"    # Tarball to read, compressed with gzip
12 VERSION="$2"
13 ARCH="$3"
14 CHANGES="$4"    # Changes file for the upload
15
16 error() {
17         echo "$*"
18         exit 1
19 }
20
21 # Check validity of version number
22 # Expected are: YYYYMMDD, YYYYMMDD.x, YYYYMMDD<suite>x, YYYYMMDD+<suite>x and the +b[0-9] on the end
23 if ! echo "$VERSION" | grep -Eq "^[0-9]{8}(|(\.|\+?[a-z]+)[0-9]+)(\+b[0-9])?$"; then
24         error "Invalid version: '$VERSION'"
25 fi
26
27 # Get the target suite from the Changes file
28 # NOTE: it may be better to pass this to the script as a parameter!
29 SUITE="$(grep "^Distribution:" "$CHANGES" | awk '{print $2}')"
30 case $SUITE in
31     "")
32         error "Error: unable to determine suite from Changes file"
33         ;;
34     unstable|sid)
35         : # nothing to do
36         ;;
37     *)
38         SUITE="${SUITE}-proposed-updates"
39         ;;
40 esac
41
42 # This must end with /
43 TARGET="/srv/ftp-master.debian.org/ftp/dists/$SUITE/main/installer-$ARCH/"
44
45 # Check validity of the target directory
46 # This could fail, for example for new architectures; doing
47 # a regular BYHAND is safer in that case
48 if [ ! -d "$TARGET" ]; then
49         mkdir -p "$TARGET"
50 fi
51 # Check that there isn't already a directory for this version
52 if [ -d "$TARGET/$VERSION" ]; then
53         error "Directory already exists: $TARGET/$VERSION"
54 fi
55
56 # We know the VERSION is sane by here, we just need to make sure we escape the + in +b1 (if any)
57 # It needs 'g' as well as we may have +$DIST+b[0-9]
58 VERSIONREGEXP="$(echo $VERSION | sed 's@+@\\\+@g')"
59
60 # We know all data to be in ./installer-<arch>/<version>; see if there's
61 # anything else in the tarball except that and the 'current' symlink
62 if tar tzf "$TARBALL" | \
63    grep -Eqv "^\./(installer-$ARCH/($VERSIONREGEXP/.*|current|)|)$"; then
64         error "Tarball contains unexpected contents"
65 fi
66
67 # Create a temporary directory where to store the images
68 umask 002
69 TMPDIR="$(mktemp -td byhand-di.XXXXXX)"
70
71 # If we fail somewhere, cleanup the temporary directory
72 cleanup() {
73         rm -rf "$TMPDIR"
74 }
75 trap cleanup EXIT
76
77 # Extract the data into the temporary directory
78 tar xzf "$TARBALL" --directory="$TMPDIR" "./installer-$ARCH/"
79
80 # Check the 'current' symlink
81 if [ ! -L $TMPDIR/installer-$ARCH/current ]; then
82         error "Missing 'current' symlink"
83 elif [ X"$(readlink "$TMPDIR/installer-$ARCH/current")" != X"$VERSION" ]; then
84         error "Incorrect 'current' symlink"
85 fi
86
87 # We should have an MD5SUMS file; use that for a final check
88 if [ -r "$TMPDIR/installer-$ARCH/$VERSION/images/MD5SUMS" ]; then
89         (
90                 cd "$TMPDIR/installer-$ARCH/$VERSION/images"
91                 md5sum -c --status MD5SUMS || error "Error while checking MD5SUMS"
92         )
93 else
94         error "Missing MD5SUMS file"
95 fi
96
97 # Move the data to the final location
98 mv "$TMPDIR/installer-$ARCH/$VERSION" "$TARGET"
99 mv "$TMPDIR/installer-$ARCH/current"  "$TARGET"
100
101 # Fixup permissions
102 find "$TARGET/$VERSION" -type d -exec chmod 755 {} +
103 find "$TARGET/$VERSION" -type f -exec chmod 644 {} +
104
105 # Make sure nothing symlinks outside of the ftpdir
106 # Shouldnt happen, but better be sure.
107 symlinks -d -r /srv/ftp-master.debian.org/ftp
108
109 trap - EXIT
110 cleanup
111
112 exit 0