fix changelog entry
[tails.git] / auto / scripts / apt-snapshots-serials
blob67f352148238f87e876a60314c5940875ffb960a
1 #!/bin/bash
2 set -e
3 set -u
5 set -o pipefail
7 BASE_URL=http://time-based.snapshots.deb.tails.boum.org/
8 CONFIG=config/APT_snapshots.d
9 SERIAL_ONLY=
10 APT_SNAPSHOTS_SERIALS=
11 FREEZE_EXCEPTIONS=debian-security
13 get_latest_serial() {
14 origin=$1
15 wget -q "$BASE_URL/$origin/project/trace/$origin" -O - \
16 | awk -F': ' '/^Archive serial: / {print $2}'
19 list_origins () {
20 find "$CONFIG" -mindepth 1 -maxdepth 1 -type d -printf '%f\n'
23 if [ $# -eq 0 ]; then
24 action="cat"
25 ORIGINS="$(list_origins)"
26 else
27 action="${1}"
28 shift
29 if [ "${1:-}" = --print-serials-only ]; then
30 SERIAL_ONLY=yes
31 shift
33 if [ "${1:-}" = --freeze-debian-security ]; then
34 FREEZE_EXCEPTIONS=
35 shift
37 case "$action" in
38 prepare-build)
39 if [ $# -eq 1 ]; then
40 APT_SNAPSHOTS_SERIALS="${1}"
41 shift
44 cat-json)
45 if [ $# -eq 1 ]; then
46 CONFIG="${1}"
47 shift
50 cat|get-latest|freeze|thaw)
51 if [ $# -eq 0 ]; then
52 ORIGINS="$(list_origins)"
53 else
54 ORIGINS="${@}"
57 esac
60 case "$action" in
61 cat)
62 for origin in $ORIGINS; do
63 [ -z "${SERIAL_ONLY}" ] && echo -n "$origin: "
64 cat "$CONFIG/$origin/serial"
65 done
67 cat-json)
68 "$(dirname "$0")"/apt-snapshots-serials-cat-json "$CONFIG"
70 get-latest)
71 for origin in $ORIGINS; do
72 [ -z "${SERIAL_ONLY}" ] && echo -n "$origin: "
73 get_latest_serial "$origin"
74 done
76 freeze)
77 for origin in $ORIGINS; do
78 serial_file="$CONFIG/$origin/serial"
79 git=$(cat "$serial_file")
80 # shellcheck disable=SC2254
81 case "$origin" in
82 ${FREEZE_EXCEPTIONS})
83 new=latest
86 new=$(get_latest_serial "$origin")
87 esac
88 printf "Origin %s:\n old: %s\n new: %s\n" \
89 "$origin" "$git" "$new"
90 echo "$new" > "$serial_file"
91 done
92 printf "\nAll files (%s/*/serial) have been updated with new serials\n" "$CONFIG" >&2
94 thaw)
95 for origin in $ORIGINS; do
96 serial_file="$CONFIG/$origin/serial"
97 git=$(cat "$serial_file")
98 printf "Origin %s:\n old: %s\n new: latest\n" \
99 "$origin" "$git"
100 echo 'latest' > "$serial_file"
101 done
103 prepare-build)
104 rm -rf tmp/APT_snapshots.d
105 mkdir -p tmp
106 cp -r config/APT_snapshots.d tmp/
107 if [ "${APT_SNAPSHOTS_SERIALS}" ]; then
108 "$(dirname "$0")"/apt-snapshots-serials-load-json \
109 "$APT_SNAPSHOTS_SERIALS" \
110 > tmp/cached_APT_snapshots_serials
111 else
112 $0 get-latest > tmp/cached_APT_snapshots_serials
114 for origin_dir in tmp/APT_snapshots.d/*; do
115 origin=$(basename "$origin_dir")
116 if grep -qs '^latest$' "$origin_dir"/serial; then
117 awk -F': ' "/^$origin: / {print \$2}" \
118 tmp/cached_APT_snapshots_serials \
119 > "$origin_dir"/serial
121 done
124 printf "unknown action (%s), use either 'cat', 'cat-json', 'get-latest', 'prepare-build', 'freeze' or 'thaw'\n" "$action" >&2
125 exit 1
127 esac