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