The magic command has to be run from inside Tails (#16289)
[tails.git] / bin / tag-apt-snapshots
blobc67a7806b5bdacf49094ed97a26ba0cbceb3d38c
1 #!/bin/sh
3 set -e
4 set -u
6 TIME_BASED_SNAPSHOTS_HOST='apt.lizard'
7 TIME_BASED_SNAPSHOTS_USER='reprepro-time-based-snapshots'
8 TIME_BASED_SNAPSHOTS_USER_AT_HOST="${TIME_BASED_SNAPSHOTS_USER}@${TIME_BASED_SNAPSHOTS_HOST}"
10 fail_with_usage() {
11 echo "$(basename $0) BUILD_MANIFEST TAG" >&2
14 [ $# -eq 2 ] || fail_with_usage
16 BUILD_MANIFEST="$1"
17 TAG="$2"
19 [ -r "$BUILD_MANIFEST" ] || fail_with_usage
20 [ -n "$TAG" ] || fail_with_usage
22 echo "I: Preparing a workspace on ${TIME_BASED_SNAPSHOTS_HOST}"
23 ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" install -d '$HOME'/tmp
24 REMOTE_BUILD_MANIFEST=$(ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
25 mktemp --tmpdir='$HOME'/tmp)
26 REMOTE_DEST_DIR=$(ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
27 mktemp -d --tmpdir='$HOME'/tmp)
29 echo "I: Sending build manifest to ${TIME_BASED_SNAPSHOTS_HOST}"
30 scp "$BUILD_MANIFEST" \
31 "${TIME_BASED_SNAPSHOTS_USER_AT_HOST}:${REMOTE_BUILD_MANIFEST}"
33 echo "I: Preparing reprepro configuration"
34 ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
35 tails-prepare-tagged-apt-snapshot-import \
36 "$REMOTE_BUILD_MANIFEST" \
37 "$REMOTE_DEST_DIR"
39 echo "I: Pulling packages from the time-based snapshots into the tagged ones"
40 for archive in $(ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
41 ls "$REMOTE_DEST_DIR") ; do
42 echo "I: - $archive"
43 ssh "$TIME_BASED_SNAPSHOTS_USER_AT_HOST" \
44 reprepro --basedir "${REMOTE_DEST_DIR}/${archive}" update
45 done
47 echo "I: Publishing the tagged APT snapshot"
48 ssh "${TIME_BASED_SNAPSHOTS_USER}@${TIME_BASED_SNAPSHOTS_HOST}" \
49 sudo -n /usr/local/sbin/tails-publish-tagged-apt-snapshot \
50 "$REMOTE_DEST_DIR" "$TAG"
52 echo "I: Cleaning up"
53 ssh "${TIME_BASED_SNAPSHOTS_USER}@${TIME_BASED_SNAPSHOTS_HOST}" \
54 rm "$REMOTE_BUILD_MANIFEST"