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

set -e

APT_MIRROR_URL="http://deb.tails.boum.org/"
DEFAULT_COMPONENTS="main"

git_tag_exists() {
	local tag="$1"

	test -f ".git/refs/tags/$tag"
}

version_was_released() {
	local version="$1"

	git_tag_exists "$version"
}

version_in_changelog() {
	dpkg-parsechangelog | awk '/^Version: / { print $2 }'
}

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

	echo "deb $APT_MIRROR_URL $suite $components"
}

current_branch() {
	git branch | awk '/^\* / { print $2 }'
}

on_topic_branch() {
	current_branch | grep -qE '^(feature|bug|bugfix)/'
}

branch_name_to_suite() {
	local branch="$1"

	echo "$branch" | sed -e 's,[^a-z0-9-],-,ig'  | tr '[A-Z]' '[a-z]'
}


if version_was_released "$(version_in_changelog)"; then
	output_apt_binary_source "$(version_in_changelog)"
elif [ "$(current_branch)" = "testing" ]; then
	output_apt_binary_source testing
elif [ "$(current_branch)" = "experimental" ]; then
	output_apt_binary_source experimental
else
	output_apt_binary_source devel
fi

if on_topic_branch; then
	output_apt_binary_source "$(branch_name_to_suite $(current_branch))"
fi