Skip to content

Commit 1aa7823

Browse files
committed
image / create_chroot - support OS images that are compressed with xz
Image files for Raspberry Pi OS buster (oldstable) and bulleye are now single files compressed with .xz instead of the zip files used previously. Add support for decompressing xz as well as an additional check to make sure the image was extracted ok before continuing. Added return codes to the function.
1 parent f28351d commit 1aa7823

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

scriptmodules/admin/image.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rp_module_section=""
1515
rp_module_flags=""
1616

1717
function depends_image() {
18-
local depends=(kpartx unzip binfmt-support rsync parted squashfs-tools dosfstools e2fsprogs)
18+
local depends=(kpartx unzip binfmt-support rsync parted squashfs-tools dosfstools e2fsprogs xz-utils)
1919
isPlatform "x86" && depends+=(qemu-user-static)
2020
getDepends "${depends[@]}"
2121
}
@@ -34,12 +34,15 @@ function create_chroot_image() {
3434

3535
local url
3636
local image
37+
local fmt=".img.xz"
3738
case "$dist" in
3839
jessie)
3940
url="https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-07-05/2017-07-05-raspbian-jessie-lite.zip"
41+
fmt=".zip"
4042
;;
4143
stretch)
4244
url="https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-04-09/2019-04-08-raspbian-stretch-lite.zip"
45+
fmt=".zip"
4346
;;
4447
buster)
4548
url="https://downloads.raspberrypi.org/raspios_oldstable_lite_armhf_latest"
@@ -56,12 +59,24 @@ function create_chroot_image() {
5659
local base="raspbian-${dist}-lite"
5760
local image="$base.img"
5861
if [[ ! -f "$image" ]]; then
59-
download "$url" "$base.zip"
60-
unzip -o "$base.zip"
61-
mv "$(unzip -Z -1 "$base.zip")" "$image"
62-
rm "$base.zip"
62+
local dest="$base$fmt"
63+
case "$fmt" in
64+
.zip)
65+
download "$url" "$dest"
66+
unzip -o "$dest"
67+
mv "$(unzip -Z -1 "$dest")" "$image"
68+
rm "$dest"
69+
;;
70+
.img.xz)
71+
download "$url" "$dest"
72+
xz -d -v "$dest"
73+
;;
74+
esac
6375
fi
6476

77+
# abort if there is no extracted image present
78+
[[ ! -f "$image" ]] && return 1
79+
6580
# mount image
6681
local partitions=($(kpartx -s -a -v "$image" | awk '{ print "/dev/mapper/"$3 }'))
6782
local part_boot="${partitions[0]}"
@@ -82,6 +97,7 @@ function create_chroot_image() {
8297
kpartx -d "$image"
8398

8499
popd
100+
return 0
85101
}
86102

87103
function install_rp_image() {

0 commit comments

Comments
 (0)