@@ -165,12 +165,14 @@ main() {
165165 sharutils \
166166 gnupg
167167
168- # amd64 has conflicting versions of the packages installed, so
168+ # image arch has conflicting versions of the packages installed, so
169169 # we need to remove the system installs later. since apt relies
170170 # on these packages, we need to download them and reinstall
171171 # using dpkg later, since we cannot redownload via apt.
172+ local image_arch
173+ image_arch=$( dpkg --print-architecture)
172174 local libgcc_packages=(" ${libgcc} :${arch} " " libstdc++6:${arch} " )
173- if [[ " ${arch} " == " amd64 " ]]; then
175+ if [[ " ${arch} " == " ${image_arch} " ]]; then
174176 local libgcc_root=/qemu/libgcc
175177 mkdir -p " ${libgcc_root} "
176178 pushd " ${libgcc_root} "
@@ -180,6 +182,7 @@ main() {
180182
181183 # Download packages
182184 mv /etc/apt/sources.list /etc/apt/sources.list.bak
185+ mv /etc/apt/sources.list.d /etc/apt/sources.list.d.bak
183186 echo -e " ${debsource} " > /etc/apt/sources.list
184187
185188 # Old ubuntu does not support --add-architecture, so we directly change multiarch file
@@ -234,10 +237,10 @@ main() {
234237 ncurses-base" ${ncurses} " \
235238 " zlib1g:${arch} "
236239
237- if [[ " ${arch} " != " amd64 " ]]; then
240+ if [[ " ${arch} " != " ${image_arch} " ]]; then
238241 apt-get -d --no-install-recommends download " ${libgcc_packages[@]} "
239242 else
240- # amd64 has conflicting versions of the packages installed
243+ # host arch has conflicting versions of the packages installed
241244 # this prevents us from downloading them, so we need to
242245 # simply grab the last version from the debian sources.
243246 # we're search for a paragraph with:
374377 find . | cpio --create --format=' newc' --quiet | gzip > ../initrd.gz
375378 cd -
376379
377- if [[ " ${arch} " == " amd64 " ]]; then
380+ if [[ " ${arch} " == " ${image_arch} " ]]; then
378381 # need to reinstall these packages, since basic utilities rely on them.
379382 pushd " ${libgcc_root} "
380383 dpkg -i --force-depends " ${libgcc_root} " /* .deb
@@ -385,15 +388,16 @@ EOF
385388 # Clean up
386389 rm -rf " /qemu/${root} " " /qemu/${arch} "
387390 mv -f /etc/apt/sources.list.bak /etc/apt/sources.list
391+ mv -f /etc/apt/sources.list.d.bak /etc/apt/sources.list.d
388392 if [ -f /etc/dpkg/dpkg.cfg.d/multiarch.bak ]; then
389393 mv /etc/dpkg/dpkg.cfg.d/multiarch.bak /etc/dpkg/dpkg.cfg.d/multiarch
390394 fi
391- # can fail if arch is used (amd64 and/or i386)
395+ # can fail if arch is used (image arch, such as amd64 and/or i386)
392396 dpkg --remove-architecture " ${arch} " || true
393397 apt-get update
394398
395399 # need to reinstall the removed libgcc packages, which are required for apt
396- if [[ " ${arch} " == " amd64 " ]]; then
400+ if [[ " ${arch} " == " ${image_arch} " ]]; then
397401 apt-get install --no-install-recommends --assume-yes " ${packages[@]} "
398402 fi
399403
0 commit comments