summaryrefslogtreecommitdiffstats
path: root/auto/scripts/apt-mirror
blob: 4d4ccad070a4ef98cbe57b48f7f28d0c75e4a122 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash

set -e
set -u

. "$(dirname $0)/utils.sh"

ARCHIVE="$1"

output_tagged_snapshot() {
   local archive="$1"
   local tag="$2"
   echo "http://tagged.snapshots.deb.tails.boum.org/$tag/$archive"
}

output_time_based_snapshot() {
   local archive="$1"
   local serial="$2"
   echo "http://time-based.snapshots.deb.tails.boum.org/$archive/$serial"
}

### Sanity checks

[ -n "$ARCHIVE" ] || exit 1

### Main

SERIAL=$(cat "config/APT_snapshots.d/$ARCHIVE/serial")
RESOLVED_SERIAL=$(cat "tmp/APT_snapshots.d/$ARCHIVE/serial")

if [ "$(base_branch)" = stable ]; then
    if version_was_released "$(version_in_changelog)"; then
        [ "$(current_branch)" = stable ] \
            || fatal "Not building from stable, but last version in changelog" \
                     "was released"
        output_tagged_snapshot "$ARCHIVE" "$(version_in_changelog)"
    else
       version_was_released "$(previous_version_in_changelog)" \
           || fatal "None of the two last version in changelog were released"
       case "$ARCHIVE" in
          debian-security)
             [ "$SERIAL" = latest ] \
                 || fatal "APT snapshots are frozen for debian-security, which" \
                          "should not happen on a branch based on stable"
             output_time_based_snapshot "$ARCHIVE" "$RESOLVED_SERIAL"
             ;;
          *)
             if [ "$SERIAL" = latest ]; then
                # In this case, "latest" means "do what I mean", that is stick
                # to previous release's tagged snapshot
                output_tagged_snapshot "$ARCHIVE" "$(previous_version_in_changelog)"
             else
                output_time_based_snapshot "$ARCHIVE" "$SERIAL"
             fi
       esac
    fi
elif [ "$(base_branch)" = testing ]; then
    if version_was_released "$(version_in_changelog)"; then
        [ "$(current_branch)" = testing ] \
            || fatal "Not building from testing, but last version in changelog" \
                     "was released"
        [ "$ARCHIVE" = debian-security ] || [ "$SERIAL" != latest ] \
            || fatal "APT snapshots for $ARCHIVE are not frozen, which should" \
                     "not happen on a tagged testing branch"
        output_tagged_snapshot "$ARCHIVE" "$(version_in_changelog)"
    else
        output_time_based_snapshot "$ARCHIVE" "$RESOLVED_SERIAL"
    fi
else
    if [ "$(base_branch)" = devel ] && [ "$SERIAL" != latest ]; then
        fatal "APT snapshots are frozen, which should not happen on a branch" \
              "based on the devel one"
    fi
    output_time_based_snapshot "$ARCHIVE" "$RESOLVED_SERIAL"
fi