summaryrefslogtreecommitdiffstats
path: root/auto/scripts/tails-custom-apt-sources
blob: 4face16203c28b49c59d3d171ec20c7ae084dac7 (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
#!/bin/bash

set -e
set -u

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

APT_MIRROR_URL="http://deb.tails.boum.org/"
DEFAULT_COMPONENTS="main contrib non-free"
BASE_BRANCHES="stable testing devel feature/jessie"

output_apt_binary_source() {
	local suite="$1"
	local components="${2:-$DEFAULT_COMPONENTS}"

	echo "deb $APT_MIRROR_URL $suite $components"
}

output_overlay_apt_binary_sources() {
	for suite in $(ls config/APT_overlays.d) ; do
		output_apt_binary_source "$suite"
	done
}

on_base_branch() {
	local current_branch=$(current_branch)

	for base_branch in $BASE_BRANCHES ; do
		if [ "$current_branch" = "$base_branch" ] ; then
			return 0
		fi
	done

	return 1
}

### Sanity checks

[ -d config/APT_overlays.d ] || fatal 'config/APT_overlays.d/ does not exist'
[ -e config/base_branch  ]   || fatal 'config/base_branch does not exist'

[ "$(cat config/base_branch | wc -l)" -eq 1 ] \
    || fatal 'config/base_branch must contain exactly one line'

if on_base_branch && ! [ "$(base_branch)" = "$(current_branch)" ] ; then
	echo "base_branch: $(base_branch)" >&2
	echo "current_branch: $(current_branch)" >&2
	fatal "In a base branch, config/base_branch must match the current branch."
fi

### Main

if version_was_released "$(version_in_changelog)"; then
	if [ -n "$(ls config/APT_overlays.d)" ]; then
		fatal 'config/APT_overlays.d/ must be empty while releasing'
	fi
	output_apt_binary_source "$(branch_name_to_suite "$(version_in_changelog)")"
else
	output_apt_binary_source "$(branch_name_to_suite "$(base_branch)")"
	output_overlay_apt_binary_sources
fi