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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
#!/bin/sh
# Outputs APT configuration data
set -e
self="$(basename "$0")"
# TODO
# - currently only handles a single --suite or --profile; allow multiple ones?
# - nicer error messages
# - default output when neither --suite nor --profile is set?
# - support getting/setting --vendor?
# - support setting --mirror-map (for --profile)
# - list Ubuntu security pocket? Debian security entries?
log() {
echo "$@" >&2
}
usage() {
log "$self [--with-sources=[yes|no|disabled]] [--arch=<arch>] [--components=<comp1>,<comp2>] [--mirror=<mirror>] [--suite=<suite>] [--pockets=<pocket1>,<pocket2>]" >&2
log "$self [--with-sources=[yes|no|disabled]] [--arch=<arch>] [--components=<comp1>,<comp2>] [--profile=<profile>]" >&2
}
die() {
log "$@"
exit 1
}
guess_dist_vendor() {
local dist="$1"
case "$dist" in
etch|lenny|squeeze|sid|testing|unstable|experimental)
echo "debian"
;;
hardy|intrepid|jaunty|karmic|lucid)
echo "ubuntu"
;;
*)
die "Unknown vendor for dist=$dist"
;;
esac
}
guess_vendor_arch_mirror() {
local vendor="$1"
local arch="$2"
case "$vendor" in
backports.org)
echo "http://www.backports.org/backports.org/"
;;
debian)
echo "http://ftp.us.debian.org/debian/"
;;
ubuntu)
case "$arch" in
amd64|i386)
echo "http://archive.ubuntu.com/ubuntu/"
;;
armel|hppa|ia64|lpia|powerpc|sparc)
echo "http://ports.ubuntu.com/ubuntu-ports/"
;;
*)
die "Unknown mirror for Ubuntu and arch=$arch"
;;
esac
;;
volatile)
echo "http://volatile.debian.org/debian-volatile/"
;;
*)
die "Unknown mirror for vendor=$vendor"
;;
esac
}
output_sources() {
local with_sources="$1"
local mirror="$2"
local dist="$3"
local components="$4"
case "$with_sources" in
yes)
echo "deb $mirror $dist $components"
echo "deb-src $mirror $dist $components"
;;
disabled)
echo "deb $mirror $dist $components"
echo "#deb-src $mirror $dist $components"
;;
no)
echo "deb $mirror $dist $components"
;;
*)
die 'with_sources must be either "yes", "disabled", or "no"'
;;
esac
}
getopt_output="`getopt -o "" -l with-sources::,arch:,components:,mirror:,suite:,pockets:,profile: -n "$self" -s sh -- "$@"`"
eval set -- "$getopt_output"
with_sources="disabled"
arch="`dpkg --print-architecture`"
components="main"
mirror=""
suite=""
pockets=""
vendor=""
profile=""
while :; do
case "$1" in
--with-sources)
case "$2" in
"")
with_sources="yes"
;;
yes|no|disabled)
with_sources="$2"
;;
*)
die '--with-sources must be either "yes", "disabled", or "no"'
;;
esac
shift 2
;;
--arch)
arch="$2"
shift 2
;;
--components)
components="$2"
shift 2
;;
--mirror)
mirror="$2"
shift 2
;;
--suite)
if [ -z "$2" ]; then
die "Need a suite for --suite"
fi
if [ -n "$profile" ]; then
die "Can't set --suite after --profile"
fi
suite="$2"
shift 2
;;
--pockets)
pockets="$2"
shift 2
;;
--vendor)
vendor="$2"
shift 2
;;
--profile)
if [ -z "$2" ]; then
die "Need a profile for --profile"
fi
if [ -n "$suite" ]; then
die "Can't set --profile after --suite"
fi
profile="$2"
shift 2
;;
--)
shift
break
;;
*)
die "Unhandled arg=$1"
;;
esac
done
case $# in
0)
command="sources"
;;
1)
command="$1"
;;
2)
usage
exit 1
;;
esac
if [ -z "$suite" ] && [ -z "$profile" ]; then
die "Please pass --suite or --profile"
fi
components="$(echo "$components" | tr , " ")"
pockets="$(echo "$pockets" | tr , " ")"
if [ -n "$profile" ]; then
base_dist="${profile%%/*}"
base_dist="${base_dist%%-*}"
base_vendor="`guess_dist_vendor "$base_dist"`"
base_mirror="`guess_vendor_arch_mirror "$base_vendor" "$arch"`"
case "$base_vendor" in
debian)
case "$profile" in
experimental)
base_dist="unstable"
output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
output_sources "$with_sources" "$base_mirror" "$profile" "$components"
;;
*/volatile|*/volatile-sloppy)
if [ "$base_dist" != "${profile%%/*}" ]; then
die "Unknown Volatile based profile=$profile"
fi
vendor="volatile"
mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`"
volatile_dist=${profile%%-*}
output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
output_sources "$with_sources" "$mirror" "$volatile_dist" "$components"
if [ "$volatile_dist" != "$profile" ]; then
output_sources "$with_sources" "$mirror" "$profile" "$components"
fi
;;
*-backports)
vendor="backports.org"
mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`"
output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
output_sources "$with_sources" "$mirror" "$profile" "$components"
;;
*-proposed-updates)
output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
output_sources "$with_sources" "$base_mirror" "$profile" "$components"
;;
*)
if [ "$base_dist" != "$profile" ]; then
die "Unknown Debian based profile=$profile"
fi
output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
;;
esac
;;
ubuntu)
case "$profile" in
*-backports)
pockets="updates backports"
;;
*-proposed)
pockets="updates proposed"
;;
*-updates|*-security)
pockets="updates"
;;
*)
if [ "$base_dist" != "$profile" ]; then
die "Unknown Ubuntu based profile=$profile"
fi
;;
esac
output_sources "$with_sources" "$base_mirror" "$base_dist" "$components"
for pocket in $pockets; do
output_sources "$with_sources" "$base_mirror" "$base_dist-$pocket" "$components"
done
;;
*)
die "Unknown profile for base_vendor=$base_vendor"
;;
esac
exit 0
fi
if [ -n "$suite" ]; then
if [ -z "$mirror" ]; then
if [ -z "$vendor" ]; then
vendor="`guess_dist_vendor "$suite"`"
fi
mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`"
fi
output_sources "$with_sources" "$mirror" "$suite" "$components"
exit 0
fi
|