This repository has been archived by the owner on Apr 4, 2019. It is now read-only.
forked from tianon/docker-brew-debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·156 lines (140 loc) · 3.72 KB
/
update.sh
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
set -eo pipefail
cd "$(readlink -f "$(dirname "$BASH_SOURCE")")"
declare -A codenameCache=()
codename() {
local suite="$1"; shift
if [ -z "${codenameCache[$suite]}" ]; then
local ret="$(curl -fsSL "http://httpredir.debian.org/debian/dists/$suite/Release" | awk -F ': ' '$1 == "Codename" { print $2 }' || true)"
codenameCache[$suite]="${ret:-$suite}"
fi
echo "${codenameCache[$suite]}"
}
declare -A backports=(
[stable]=1
[oldstable]=1
[$(codename stable)]=1
[$(codename oldstable)]=1
)
declare -A unstableSuites=(
[unstable]=1
[testing]=1
[$(codename unstable)]=1
[$(codename testing)]=1
)
versions=( "$@" )
if [ ${#versions[@]} -eq 0 ]; then
branch="$(git describe --contains --all HEAD)"
case "$branch" in
dist-stable)
for suite in */; do
suite="${suite%/}"
[ -z "${unstableSuites[$suite]}" ] || continue
versions+=( "$suite" )
done
;;
dist-unstable)
for suite in "${!unstableSuites[@]}"; do
if [ -d "$suite" ]; then
versions+=( "$suite" )
fi
done
;;
*)
versions=( */ )
;;
esac
fi
versions=( "${versions[@]%/}" )
get_part() {
dir="$1"
shift
part="$1"
shift
if [ -f "$dir/$part" ]; then
cat "$dir/$part"
return 0
fi
if [ -f "$part" ]; then
cat "$part"
return 0
fi
if [ $# -gt 0 ]; then
echo "$1"
return 0
fi
return 1
}
repo="$(get_part . repo '')"
if [ "$repo" ]; then
origRepo="$repo"
if [[ "$repo" != */* ]]; then
user="$(docker info | awk '/^Username:/ { print $2 }')"
if [ "$user" ]; then
repo="$user/$repo"
fi
fi
fi
latest="$(get_part . latest '')"
for version in "${versions[@]}"; do
dir="$(readlink -f "$version")"
variant="$(get_part "$dir" variant 'minbase')"
components="$(get_part "$dir" components 'main')"
include="$(get_part "$dir" include '')"
arch="$(get_part "$dir" arch '')"
suite="$(get_part "$dir" suite "$version")"
mirror="$(get_part "$dir" mirror '')"
script="$(get_part "$dir" script '')"
args=( -d "$dir" debootstrap )
[ -z "$variant" ] || args+=( --variant="$variant" )
[ -z "$components" ] || args+=( --components="$components" )
[ -z "$include" ] || args+=( --include="$include" )
[ -z "$arch" ] || args+=( --arch="$arch" )
debootstrapVersion="$(debootstrap --version)"
debootstrapVersion="${debootstrapVersion##* }"
if dpkg --compare-versions "$debootstrapVersion" '>=' '1.0.69'; then
args+=( --force-check-gpg )
fi
args+=( "$suite" )
if [ "$mirror" ]; then
args+=( "$mirror" )
if [ "$script" ]; then
args+=( "$script" )
fi
fi
mkimage="$(readlink -f "${MKIMAGE:-"mkimage.sh"}")"
{
echo "$(basename "$mkimage") ${args[*]/"$dir"/.}"
echo
echo 'https://github.com/docker/docker/blob/master/contrib/mkimage.sh'
} > "$dir/build-command.txt"
sudo nice ionice -c 3 "$mkimage" "${args[@]}" 2>&1 | tee "$dir/build.log"
sudo chown -R "$(id -u):$(id -g)" "$dir"
if [ "$repo" ]; then
( set -x && docker build -t "${repo}:${suite}" "$dir" )
if [ "$suite" != "$version" ]; then
( set -x && docker tag "${repo}:${suite}" "${repo}:${version}" )
fi
if [ "$suite" = "$latest" ]; then
( set -x && docker tag -f "$repo:$suite" "$repo:latest" )
fi
docker run --rm "${repo}:${suite}" bash -xc '
cat /etc/apt/sources.list
echo
cat /etc/os-release 2>/dev/null
echo
cat /etc/lsb-release 2>/dev/null
echo
cat /etc/debian_version 2>/dev/null
true
'
docker run --rm "${repo}:${suite}" dpkg-query -f '${Package}\t${Version}\n' -W > "$dir/build.manifest"
if [ "${backports[$suite]}" ]; then
mkdir -p "$dir/backports"
echo "FROM $origRepo:$suite" > "$dir/backports/Dockerfile"
cat >> "$dir/backports/Dockerfile" <<-'EOF'
RUN awk '$1 ~ "^deb" { $3 = $3 "-backports"; print; exit }' /etc/apt/sources.list > /etc/apt/sources.list.d/backports.list
EOF
fi
fi
done