summaryrefslogtreecommitdiffstats
path: root/auto/scripts/apt-mirror
blob: 78fc0889cdbcc35f780a695a8c86ace8060f457d (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
#!/bin/bash

set -e
set -u

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

ARCHIVE="$1"

output_tagged_snapshot() {
   local archive="$1"
   local tag="$2"
   local snapshot=$(branch_name_to_suite "$tag")
   echo "http://tagged.snapshots.deb.tails.boum.org/$snapshot/$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")
BASE_BRANCH=$(base_branch)
CURRENT_BRANCH=$(current_branch)

if [ "$BASE_BRANCH" = stable ] \
       || [ "$BASE_BRANCH" = testing ] \
       || [ "$CURRENT_BRANCH" = feature/stretch ] \
       || ( on_a_tag && [ "$BASE_BRANCH" = feature/stretch ] ) \
then
    case "$ARCHIVE" in
       debian-security)
          [ "$SERIAL" = latest ] \
              || fatal "APT snapshots are frozen for the debian-security archive," \
                       "which should happen neither on feature/stretch nor on"     \
                        "a branch based on $BASE_BRANCH"
          ;;
       *)
          [ "$SERIAL" != latest ] \
              || fatal "APT snapshots are not frozen for the $ARCHIVE archive," \
                       "which should happen neither on feature/stretch nor on"  \
                        "a branch based on $BASE_BRANCH"
    esac
    if version_was_released "$(version_in_changelog)"; then
        on_a_tag \
            || fatal "Not building from a tag, but last version in changelog" \
                     "was released"
        output_tagged_snapshot "$ARCHIVE" "$(version_in_changelog)"
    else
       if [ "$BASE_BRANCH" = stable ] ; then
           version_was_released "$(previous_version_in_changelog)" \
               || fatal "None of the two last version in changelog were released"
       fi
       output_time_based_snapshot "$ARCHIVE" "$RESOLVED_SERIAL"
    fi
else
    if [ "$BASE_BRANCH" = devel ] || [ "$CURRENT_BRANCH" = feature/stretch ]; then
        if [ "$SERIAL" != latest ]; then
            fatal "APT snapshots are frozen, which should happen neither on" \
                  "feature/stretch nor on a branch based on the devel one"
        fi
    fi
    output_time_based_snapshot "$ARCHIVE" "$RESOLVED_SERIAL"
fi