]> git.decadent.org.uk Git - dak.git/blob - scripts/debian/byhand-di
Merge branch 'gps' into merge
[dak.git] / scripts / debian / byhand-di
1 #!/bin/sh -ue
2
3 if [ $# -lt 4 ]; then
4         echo "Usage: $0 filename version arch changes_file"
5         exit 1
6 fi
7
8 TARBALL="$1"    # Tarball to read, compressed with gzip
9 VERSION="$2"
10 ARCH="$3"
11 CHANGES="$4"    # Changes file for the upload
12
13 error() {
14         echo "$*"
15         exit 1
16 }
17
18 # Check validity of version number
19 # Expected are: YYYYMMDD, YYYYMMDD.x, YYYYMMDD<suite>x and the +b[0-9] on the end
20 if ! echo "$VERSION" | grep -Eq "^[0-9]{8}(|(\.|[a-z]+)[0-9]+)(\+b[0-9])?$"; then
21         error "Invalid version: '$VERSION'"
22 fi
23
24 # Get the target suite from the Changes file
25 # NOTE: it may be better to pass this to the script as a parameter!
26 SUITE="$(grep "^Distribution:" "$CHANGES" | awk '{print $2}')"
27 case $SUITE in
28     "")
29         error "Error: unable to determine suite from Changes file"
30         ;;
31     unstable|sid)
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 VERSIONREGEXP="$(echo $VERSION | sed 's@+@\\\+@')"
55
56 # We know all data to be in ./installer-<arch>/<version>; see if there's
57 # anything else in the tarball except that and the 'current' symlink
58 if tar tzf "$TARBALL" | \
59    grep -Eqv "^\./(installer-$ARCH/($VERSIONREGEXP/.*|current|)|)$"; then
60         error "Tarball contains unexpected contents"
61 fi
62
63 # Create a temporary directory where to store the images
64 umask 002
65 TMPDIR="$(mktemp -td byhand-di.XXXXXX)"
66
67 # If we fail somewhere, cleanup the temporary directory
68 cleanup() {
69         rm -rf "$TMPDIR"
70 }
71 trap cleanup EXIT
72
73 # Extract the data into the temporary directory
74 tar xzf "$TARBALL" --directory="$TMPDIR" "./installer-$ARCH/"
75
76 # Check the 'current' symlink
77 if [ ! -L $TMPDIR/installer-$ARCH/current ]; then
78         error "Missing 'current' symlink"
79 elif [ X"$(readlink "$TMPDIR/installer-$ARCH/current")" != X"$VERSION" ]; then
80         error "Incorrect 'current' symlink"
81 fi
82
83 # We should have an MD5SUMS file; use that for a final check
84 if [ -r "$TMPDIR/installer-$ARCH/$VERSION/images/MD5SUMS" ]; then
85         (
86                 cd "$TMPDIR/installer-$ARCH/$VERSION/images"
87                 md5sum -c --status MD5SUMS || error "Error while checking MD5SUMS"
88         )
89 else
90         error "Missing MD5SUMS file"
91 fi
92
93 # Move the data to the final location
94 mv "$TMPDIR/installer-$ARCH/$VERSION" "$TARGET"
95 mv "$TMPDIR/installer-$ARCH/current"  "$TARGET"
96
97 # Fixup permissions
98 find "$TARGET/$VERSION" -type d -exec chmod 755 {} +
99 find "$TARGET/$VERSION" -type f -exec chmod 644 {} +
100
101 # Make sure nothing symlinks outside of the ftpdir
102 # Shouldnt happen, but better be sure.
103 symlinks -d -r /srv/ftp-master.debian.org/ftp
104
105 trap - EXIT
106 cleanup
107
108 exit 0