Skip to content

Commit e63483f

Browse files
committed
Use deb822 sources format everywhere
1 parent 6083745 commit e63483f

File tree

5 files changed

+182
-45
lines changed

5 files changed

+182
-45
lines changed

chroot-script

Lines changed: 154 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,139 @@ markauto() {
9292
}
9393
# }}}
9494

95+
# write a deb822 sources stanza to a file {{{
96+
writesource() {
97+
local file types uris suites components signed_by
98+
99+
file="${1:-}"
100+
types="${2:-}"
101+
uris="${3:-}"
102+
suites="${4:-}"
103+
components="${5:-}"
104+
signed_by="${6:-}"
105+
106+
mkdir -p "$(dirname "${file}")"
107+
108+
if [ -f "$file" ]; then
109+
## stanzas need a space between them and the previous stanza
110+
echo '' >> "$file"
111+
fi
112+
113+
echo "Types: $types" >> "$file"
114+
echo "URIs: $uris" >> "$file"
115+
echo "Suites: $suites" >> "$file"
116+
echo "Components: $components" >> "$file"
117+
if [ -n "$signed_by" ]; then
118+
echo "Signed-By: $signed_by" >> "$file"
119+
fi
120+
}
121+
# }}}
122+
123+
# delete deb822 sources stanzas from a file if they match the specified
124+
# variables {{{
125+
deletesource() {
126+
local file types uris suites components signed_by
127+
128+
file="${1:-}"
129+
types="${2:-}"
130+
uris="${3:-}"
131+
suites="${4:-}"
132+
components="${5:-}"
133+
signed_by="${6:-}"
134+
135+
local stanza_contents current_types current_uris current_suites \
136+
current_components current_signed_by line do_omit file_contents
137+
stanza_contents=""
138+
current_types=""
139+
current_uris=""
140+
current_suites=""
141+
current_components=""
142+
current_signed_by=""
143+
do_omit='y'
144+
file_contents=""
145+
146+
while read -r line; do
147+
if [[ "$line" =~ ^[:space:]*# ]]; then
148+
if [ -z "$stanza_contents" ]; then
149+
file_contents+="$line"$'\n'
150+
else
151+
stanza_contents+="$line"$'\n'
152+
fi
153+
continue
154+
fi
155+
156+
line="$(sed 's/^[[:space:]]*//; s/[[:space:]]*$//;' <<< "$line")"
157+
if [ -z "$line" ]; then
158+
if [ -n "$types" ] \
159+
&& [ "$types" != "$current_types" ]; then
160+
do_omit='n'
161+
elif [ -n "$uris" ] \
162+
&& [ "$uris" != "$current_uris" ]; then
163+
do_omit='n'
164+
elif [ -n "$suites" ] \
165+
&& [ "$suites" != "$current_suites" ]; then
166+
do_omit='n'
167+
elif [ -n "$components" ] \
168+
&& [ "$components" != "$current_components" ]; then
169+
do_omit='n'
170+
elif [ -n "$signed_by" ] \
171+
&& [ "$signed_by" != "$current_signed_by" ]; then
172+
do_omit='n'
173+
elif [ -z "$current_types" ] \
174+
&& [ -z "$current_uris" ] \
175+
&& [ -z "$current_suites" ] \
176+
&& [ -z "$current_components" ] \
177+
&& [ -z "$current_signed_by" ]; then
178+
do_omit='n'
179+
fi
180+
181+
if [ "$do_omit" = 'n' ]; then
182+
file_contents+="$stanza_contents"$'\n'
183+
fi
184+
185+
stanza_contents=""
186+
current_types=""
187+
current_uris=""
188+
current_suites=""
189+
current_components=""
190+
current_signed_by=""
191+
do_omit='y'
192+
193+
continue
194+
fi
195+
196+
stanza_contents+="$line"$'\n'
197+
if [[ "$line" =~ ^Types: ]]; then
198+
current_types="$(cut -d' ' -f2- <<< "$line")"
199+
continue
200+
fi
201+
if [[ "$line" =~ ^URIs: ]]; then
202+
current_uris="$(cut -d' ' -f2- <<< "$line")"
203+
continue
204+
fi
205+
if [[ "$line" =~ ^Suites: ]]; then
206+
current_suites="$(cut -d' ' -f2- <<< "$line")"
207+
continue
208+
fi
209+
if [[ "$line" =~ ^Components: ]]; then
210+
current_components="$(cut -d' ' -f2- <<< "$line")"
211+
continue
212+
fi
213+
if [[ "$line" =~ ^Signed-By: ]]; then
214+
current_signed_by="$(cut -d' ' -f2- <<< "$line")"
215+
continue
216+
fi
217+
218+
# Extra echo piped in so that the variable parsing code runs for the last
219+
# stanza
220+
done < <(cat "$file"; echo '')
221+
222+
# Strip leading and trailing newliens
223+
file_contents="$(sed -z 's/^\n*//; s/\n*$//;' <<< "$file_contents")"
224+
echo "$file_contents" > "$file"
225+
}
226+
# }}}
227+
95228
# define chroot mirror {{{
96229
chrootmirror() {
97230
if [ "$KEEP_SRC_LIST" = "yes" ] ; then
@@ -105,8 +238,11 @@ chrootmirror() {
105238
echo "Using repository components $COMPONENTS"
106239

107240
if [ -n "$MIRROR" ] ; then
108-
echo "Adjusting sources.list for mirror (${MIRROR})."
109-
echo "deb $MIRROR $RELEASE $COMPONENTS" > /etc/apt/sources.list
241+
echo "Deleting obsolete sources.list"
242+
rm -f /etc/apt/sources.list
243+
244+
echo "Adjusting sources.list.d/debian.sources for mirror (${MIRROR})."
245+
writesource '/etc/apt/sources.list.d/debian.sources' 'deb' "$MIRROR" "$RELEASE" "$COMPONENTS" '/usr/share/keyrings/debian-archive-keyring.gpg'
110246
fi
111247

112248
# add security.debian.org:
@@ -115,8 +251,8 @@ chrootmirror() {
115251
*)
116252
# bullseye and newer releases use a different repository layout, see
117253
# https://lists.debian.org/debian-devel-announce/2019/07/msg00004.html
118-
echo "Adding security.debian.org/debian-security to sources.list."
119-
echo "deb http://security.debian.org/debian-security ${RELEASE}-security $COMPONENTS" >> /etc/apt/sources.list
254+
echo "Adding security.debian.org/debian-security to sources.list.d/debian.sources."
255+
writesource '/etc/apt/sources.list.d/debian.sources' 'deb' 'http://security.debian.org/debian-security' "${RELEASE}-security" "$COMPONENTS" '/usr/share/keyrings/debian-archive-keyring.gpg'
120256
;;
121257
esac
122258
}
@@ -130,11 +266,10 @@ remove_chrootmirror() {
130266
fi
131267

132268
if [ -n "$MIRROR" ] && echo "$MIRROR" | grep -q 'file:' ; then
133-
echo "Removing local mirror (${MIRROR}) from sources.list."
134-
TMP_MIRROR="${MIRROR//\//\\\/}"
135-
sed -i "/deb $TMP_MIRROR $RELEASE $COMPONENTS/ D" /etc/apt/sources.list
136-
echo "Adding fallback mirror entry (${FALLBACK_MIRROR}) to sources.list instead."
137-
echo "deb $FALLBACK_MIRROR $RELEASE $COMPONENTS" >> /etc/apt/sources.list
269+
echo "Removing local mirror (${MIRROR}) from sources.list.d/debian.sources."
270+
deletesource '/etc/apt/sources.list.d/debian.sources' 'deb' "$MIRROR" "$RELEASE" "$COMPONENTS"
271+
echo "Adding fallback mirror entry (${FALLBACK_MIRROR}) to sources.list.d/debian.sources instead."
272+
writesource '/etc/apt/sources.list.d/debian.sources' 'deb' "$FALLBACK_MIRROR" "$RELEASE" "$COMPONENTS" '/usr/share/keyrings/debian-archive-keyring.gpg'
138273
fi
139274
}
140275
# }}}
@@ -146,19 +281,15 @@ grmlrepos() {
146281
fi
147282

148283
# user might have provided their own apt sources configuration
149-
if [ -r /etc/apt/sources.list.d/grml.list ] ; then
150-
echo "File /etc/apt/sources.list.d/grml.list exists already, not modifying."
284+
if [ -r /etc/apt/sources.list.d/grml.sources ] ; then
285+
echo "File /etc/apt/sources.list.d/grml.sources exists already, not modifying."
151286
else
152-
echo "Setting up /etc/apt/sources.list.d/grml.list."
153-
cat > /etc/apt/sources.list.d/grml.list << EOF
154-
# grml: stable repository:
155-
deb [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-stable main
156-
deb-src [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-stable main
157-
158-
# grml: testing/development repository:
159-
deb [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-testing main
160-
deb-src [signed-by=/usr/share/keyrings/grml-archive-keyring.gpg] http://deb.grml.org/ grml-testing main
161-
EOF
287+
echo "Setting up /etc/apt/sources.list.d/grml.sources."
288+
echo '# grml: stable repository:' >> /etc/apt/sources.list.d/grml.sources
289+
writesource '/etc/apt/sources.list.d/grml.sources' 'deb deb-src' 'https://deb.grml.org' 'grml-stable' 'main' '/usr/share/keyrings/grml-archive-keyring.gpg'
290+
echo '' >> /etc/apt/sources.list.d/grml.sources
291+
echo '# grml: testing/development repository:' >> /etc/apt/sources.list.d/grml.sources
292+
writesource '/etc/apt/sources.list.d/grml.sources' 'deb deb-src' 'https://deb.grml.org' 'grml-testing' 'main' '/usr/share/keyrings/grml-archive-keyring.gpg'
162293
fi
163294

164295
# make sure we install packages from Grml's pool only if not available from Debian
@@ -188,11 +319,8 @@ EOF
188319
# feature to provide Debian backports repos {{{
189320
backportrepos() {
190321
if [ -n "$BACKPORTREPOS" ] ; then
191-
cat >> /etc/apt/sources.list.d/backports.list << EOF
192-
# debian backports: ${RELEASE}-backports repository:
193-
deb ${MIRROR} ${RELEASE}-backports main
194-
deb-src ${MIRROR} ${RELEASE}-backports main
195-
EOF
322+
echo "# debian backports: ${RELEASE}-backports repository:" >> /etc/apt/sources.list.d/backports.sources
323+
writesource '/etc/apt/sources.list.d/backports.sources' 'deb deb-src' "$MIRROR" "${RELEASE}-backports" 'main' '/usr/share/keyrings/debian-archive-keyring.gpg'
196324
fi
197325
}
198326
# }}}

config

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,19 @@
4141
# BOOT_APPEND='pci=nomsi'
4242

4343
# Set mirror where packages will be downloaded from.
44-
# Default: use /etc/debootstrap/etc/apt/sources.list if it exists, else
45-
# 'http://deb.debian.org/debian'
44+
# Default: use /etc/debootstrap/etc/apt/sources.list.d/debian.sources if it
45+
# exists, else use /etc/debootstrap/etc/apt/sources.list if it exists, else
46+
# use 'http://deb.debian.org/debian'
4647
# Usage example:
4748
# MIRROR='ftp://ftp.de.debian.org/debian'
4849

49-
# If /etc/apt/sources.list should NOT be build on the fly, this
50-
# options allows providing a separate apt sources.list file via
51-
# /etc/debootstrap/etc/apt/sources.list
50+
# If /etc/apt/sources.list.d/debian.sources should NOT be built on the fly,
51+
# this option allows providing a separate apt sources.list file via
52+
# /etc/debootstrap/etc/apt/sources.list, or providing a deb822-format sources
53+
# file via /etc/debootstrap/etc/apt/sources.list.d/debian.sources.
5254
# KEEP_SRC_LIST='yes'
5355

54-
# To enable the Grml repository via /etc/apt/sources.list.d/grml.list
56+
# To enable the Grml repository via /etc/apt/sources.list.d/grml.sources
5557
# set this variable to 'yes'.
5658
# Default: 'no'
5759
# GRMLREPOS='yes'
@@ -62,7 +64,7 @@
6264
# GRMLPACKAGES='grml-etc-core'
6365

6466
# To enable Debian's backports repository via
65-
# /etc/apt/sources.list.d/backports.list set this variable to 'yes'.
67+
# /etc/apt/sources.list.d/backports.sources set this variable to 'yes'.
6668
# Default: 'no'
6769
# BACKPORTREPOS='yes'
6870

@@ -71,7 +73,7 @@
7173
# Default: 'trixie'
7274
# RELEASE='trixie'
7375

74-
# Define components that should be used within sources.list.
76+
# Define components that should be used within sources.list.d/debian.sources.
7577
# Default: 'main'
7678
# COMPONENTS='main contrib non-free'
7779

grml-debootstrap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Configuration options:
139139
--debconf <file> Pre-seed packages using specified pre-seed db file.
140140
--grmlrepos Enable Grml's Debian repository (deb.grml.org).
141141
--backportrepos Enable Debian's backports repository (backports.debian.org).
142-
--keep_src_list Do not overwrite user provided apt sources.list.
142+
--keep_src_list Do not override user provided apt sources.
143143
--contrib Enable 'contrib' in COMPONENTS (defaults to 'main' only).
144144
--non-free Enable non-free / non-free-firmware in COMPONENTS (defaults to 'main' only).
145145
--hostname <name> Hostname of Debian system.
@@ -461,7 +461,7 @@ while :; do
461461
shift; _opt_chroot_scripts="$1"
462462
_opt_chroot_scripts_set=T
463463
;;
464-
--keep_src_list) # Do not overwrite user provided apt sources.list
464+
--keep_src_list) # Do not overwrite user provided apt sources
465465
_opt_keep_src_list=T
466466
;;
467467
--hostname) # Hostname of Debian system

grml-debootstrap.8.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Options and environment variables
4040
*--backportrepos*::
4141

4242
Enable Debian's Backports repository via the
43-
/etc/apt/sources.list.d/backports.list configuration file. This provides the
44-
option to install Debian packages from Debian's backports repository.
43+
/etc/apt/sources.list.d/backports.sources configuration file. This provides
44+
the option to install Debian packages from Debian's backports repository.
4545

4646
*--bootappend* _appendline-for-the-kernel_::
4747

@@ -113,7 +113,7 @@ Options and environment variables
113113
*--grmlrepos*::
114114

115115
Enable Grml.org's Debian repository (http://deb.grml.org/) via the
116-
/etc/apt/sources.list.d/grml.list configuration file. This provides the
116+
/etc/apt/sources.list.d/grml.sources configuration file. This provides the
117117
option to install Debian packages from Grml's repository.
118118

119119
*--grub* _device_::
@@ -135,7 +135,8 @@ Options and environment variables
135135

136136
*--keep_src_list*::
137137

138-
Do not overwrite user provided /etc/apt/sources.list.
138+
Do not override user provided /etc/apt/sources.list.d/debian.sources or
139+
delete /etc/apt/sources.list.
139140

140141
*-m*, *--mirror* _URL_::
141142

packer/debian64_provision.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,12 @@ EOF
152152
sources_list_setup() {
153153
# This is ugly because it's 'testing' no matter what ISO we're using, but otherwise we're running into
154154
# W: Failed to fetch http://snapshot.debian.org/archive/debian/20141114/dists/testing/main/binary-amd64/Packages 404 Not Found [IP: 193.62.202.30 80]
155-
echo "* Setting up /etc/apt/sources.list.d/debian.list to avoid snapshot.debian.org usage causing possible failures"
156-
cat > /etc/apt/sources.list.d/debian.list << EOF
157-
deb http://ftp.debian.org/debian testing main
155+
echo "* Setting up /etc/apt/sources.list.d/debian.sources to avoid snapshot.debian.org usage causing possible failures"
156+
cat > /etc/apt/sources.list.d/debian.sources << EOF
157+
Types: deb
158+
URIs: http://ftp.debian.org/debian
159+
Suites: testing
160+
Components: main
158161
EOF
159162
}
160163

@@ -163,8 +166,11 @@ grml_debootstrap_setup() {
163166
if [ "$GRML_DEBOOTSTRAP_VERSION" = "latest" ] ; then
164167
echo "** GRML_DEBOOTSTRAP_VERSION is set to '$GRML_DEBOOTSTRAP_VERSION'"
165168
echo "** Setting up grml-debootstrap from CI repository from jenkins.grml.org"
166-
cat > /etc/apt/sources.list.d/grml-debootstrap.list << EOF
167-
deb http://jenkins.grml.org/debian grml-debootstrap main
169+
cat > /etc/apt/sources.list.d/grml-debootstrap.sources << EOF
170+
Types: deb
171+
URIs: http://jenkins.grml.org/debian
172+
Suites: grml-debootstrap
173+
Components: main
168174
EOF
169175
wget -O - http://jenkins.grml.org/debian/C525F56752D4A654.asc | apt-key add -
170176
apt-get update

0 commit comments

Comments
 (0)