@@ -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 {{{
96229chrootmirror () {
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
188319# feature to provide Debian backports repos {{{
189320backportrepos () {
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# }}}
0 commit comments