summaryrefslogtreecommitdiffstats
path: root/bin/tag-apt-snapshots
blob: c67a7806b5bdacf49094ed97a26ba0cbceb3d38c (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
#!/bin/sh

set -e
set -u

TIME_BASED_SNAPSHOTS_HOST='apt.lizard'
TIME_BASED_SNAPSHOTS_USER='reprepro-time-based-snapshots'
TIME_BASED_SNAPSHOTS_USER_AT_HOST="${TIME_BASED_SNAPSHOTS_USER}@${TIME_BASED_SNAPSHOTS_HOST}"

fail_with_usage() {
   echo "$(basename $0) BUILD_MANIFEST TAG" >&2
}

[ $# -eq 2 ] || fail_with_usage

BUILD_MANIFEST="$1"
TAG="$2"

[ -r "$BUILD_MANIFEST" ] || fail_with_usage
[ -n "$TAG" ]            || fail_with_usage

echo "I: Preparing a workspace on ${TIME_BASED_SNAPSHOTS_HOST}"
ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" install -d '$HOME'/tmp
REMOTE_BUILD_MANIFEST=$(ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
			    mktemp --tmpdir='$HOME'/tmp)
REMOTE_DEST_DIR=$(ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
		      mktemp -d --tmpdir='$HOME'/tmp)

echo "I: Sending build manifest to ${TIME_BASED_SNAPSHOTS_HOST}"
scp "$BUILD_MANIFEST" \
    "${TIME_BASED_SNAPSHOTS_USER_AT_HOST}:${REMOTE_BUILD_MANIFEST}"

echo "I: Preparing reprepro configuration"
ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
    tails-prepare-tagged-apt-snapshot-import \
    "$REMOTE_BUILD_MANIFEST" \
    "$REMOTE_DEST_DIR"

echo "I: Pulling packages from the time-based snapshots into the tagged ones"
for archive in $(ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
		     ls "$REMOTE_DEST_DIR") ; do
   echo "I: - $archive"
   ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
       reprepro --basedir "${REMOTE_DEST_DIR}/${archive}" update
done

echo "I: Publishing the tagged APT snapshot"
ssh "${TIME_BASED_SNAPSHOTS_USER}@${TIME_BASED_SNAPSHOTS_HOST}" \
    sudo -n /usr/local/sbin/tails-publish-tagged-apt-snapshot \
            "$REMOTE_DEST_DIR" "$TAG"

echo "I: Cleaning up"
ssh "${TIME_BASED_SNAPSHOTS_USER}@${TIME_BASED_SNAPSHOTS_HOST}" \
    rm "$REMOTE_BUILD_MANIFEST"