blob: ab9e0ef546e90e303d3b64f5031bb7c28bc0f57c (
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
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
|
#!/bin/sh
# Outputs APT configuration data
set -e
self="$(basename "$0")"
# TODO
# - handle enabling/disabling deb-src
# - 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 [--arch=<arch>] [--components=<comp1>,<comp2>] [--mirror=<mirror>] [--suite=<suite>] [--pockets=<pocket1>,<pocket2>]" >&2
log "$self [--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
bpo)
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
;;
*)
die "Unknown mirror for vendor=$vendor"
;;
esac
}
getopt_output="`getopt -o "" -l arch:,components:,mirror:,suite:,pockets:,profile: -n "$self" -s sh -- "$@"`"
eval set -- "$getopt_output"
arch="`dpkg --print-architecture`"
components="main"
mirror=""
suite=""
pockets=""
vendor=""
profile=""
while :; do
case "$1" in
--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 "Internal error: unhandled arg $1=$2"
;;
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
if [ -n "$profile" ]; then
base_dist="${profile%%-*}"
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"
mirror="$base_mirror"
;;
*-backports)
vendor="bpo"
mirror="`guess_vendor_arch_mirror "$vendor" "$arch"`"
;;
*-proposed-updates)
mirror="$base_mirror"
;;
*)
if [ "$base_dist" != "$profile" ]; then
die "Unknown Debian based profile=$profile"
fi
;;
esac
echo "deb $base_mirror $base_dist $components"
if [ -n "$mirror" ]; then
echo "deb $mirror $profile $components"
fi
;;
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
echo "deb $base_mirror $base_dist $components"
for pocket in $pockets; do
echo "deb $base_mirror $base_dist-$pocket $components"
done
;;
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
echo "deb $mirror $suite $components"
exit 0
fi
|