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