@@ -171,12 +171,14 @@ main() {
171171 sharutils \
172172 gnupg
173173
174- # amd64 has conflicting versions of the packages installed, so
174+ # conflicting versions of some packages will be installed already for the host platform,
175175 # we need to remove the system installs later. since apt relies
176176 # on these packages, we need to download them and reinstall
177177 # using dpkg later, since we cannot redownload via apt.
178+ local dpkg_arch
179+ dpkg_arch=$( dpkg --print-architecture)
178180 local libgcc_packages=(" ${libgcc} :${arch} " " libstdc++6:${arch} " )
179- if [[ " ${arch} " == " amd64 " ]]; then
181+ if [[ " ${arch} " == " ${dpkg_arch} " ]]; then
180182 local libgcc_root=/qemu/libgcc
181183 mkdir -p " ${libgcc_root} "
182184 pushd " ${libgcc_root} "
@@ -186,6 +188,7 @@ main() {
186188
187189 # Download packages
188190 mv /etc/apt/sources.list /etc/apt/sources.list.bak
191+ mv /etc/apt/sources.list.d /etc/apt/sources.list.d.bak
189192 echo -e " ${debsource} " > /etc/apt/sources.list
190193
191194 # Old ubuntu does not support --add-architecture, so we directly change multiarch file
@@ -240,10 +243,10 @@ main() {
240243 ncurses-base" ${ncurses} " \
241244 " zlib1g:${arch} "
242245
243- if [[ " ${arch} " != " amd64 " ]]; then
246+ if [[ " ${arch} " != " ${dpkg_arch} " ]]; then
244247 apt-get -d --no-install-recommends download " ${libgcc_packages[@]} "
245248 else
246- # amd64 has conflicting versions of the packages installed
249+ # host arch has conflicting versions of the packages installed
247250 # this prevents us from downloading them, so we need to
248251 # simply grab the last version from the debian sources.
249252 # we're search for a paragraph with:
380383 find . | cpio --create --format=' newc' --quiet | gzip > ../initrd.gz
381384 cd -
382385
383- if [[ " ${arch} " == " amd64 " ]]; then
386+ if [[ " ${arch} " == " ${dpkg_arch} " ]]; then
384387 # need to reinstall these packages, since basic utilities rely on them.
385388 pushd " ${libgcc_root} "
386389 dpkg -i --force-depends " ${libgcc_root} " /* .deb
@@ -391,15 +394,16 @@ EOF
391394 # Clean up
392395 rm -rf " /qemu/${root} " " /qemu/${arch} "
393396 mv -f /etc/apt/sources.list.bak /etc/apt/sources.list
397+ mv -f /etc/apt/sources.list.d.bak /etc/apt/sources.list.d
394398 if [ -f /etc/dpkg/dpkg.cfg.d/multiarch.bak ]; then
395399 mv /etc/dpkg/dpkg.cfg.d/multiarch.bak /etc/dpkg/dpkg.cfg.d/multiarch
396400 fi
397- # can fail if arch is used (amd64 and/or i386)
401+ # can fail if arch is used (image arch, such as amd64 and/or i386)
398402 dpkg --remove-architecture " ${arch} " || true
399403 apt-get update
400404
401405 # need to reinstall the removed libgcc packages, which are required for apt
402- if [[ " ${arch} " == " amd64 " ]]; then
406+ if [[ " ${arch} " == " ${dpkg_arch} " ]]; then
403407 apt-get install --no-install-recommends --assume-yes " ${packages[@]} "
404408 fi
405409
0 commit comments