From baab5ef30705ed608efea5456d71ce2395c6ef7d Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 14 Sep 2023 18:59:06 +0200 Subject: [PATCH] v8.22 - DietPi-Build | Move from 7z to xz for image compression and do not embed readme and hashes --- .build/images/dietpi-build | 115 +++++++------------------------------ 1 file changed, 21 insertions(+), 94 deletions(-) diff --git a/.build/images/dietpi-build b/.build/images/dietpi-build index 406657d208..098c9554ec 100755 --- a/.build/images/dietpi-build +++ b/.build/images/dietpi-build @@ -210,11 +210,7 @@ fi # Virtual machine disk conversion [[ $VMTYPE && $VMTYPE != 'raw' ]] && apackages+=('qemu-utils') -# p7zip vs 7zip package -# shellcheck disable=SC2015 -(( $G_DISTRO < 7 )) && apackages+=('p7zip') c7zz='7zr' || apackages+=('7zip') c7zz='7zz' - -G_AG_CHECK_INSTALL_PREREQ parted debootstrap dbus systemd-container "${apackages[@]}" +G_AG_CHECK_INSTALL_PREREQ parted debootstrap dbus systemd-container xz-utils "${apackages[@]}" # Bootstrap archive keyring if missing if [[ ! -f $keyring ]] @@ -248,9 +244,8 @@ then 79) series=6;; *) :;; esac - G_EXEC curl -sSfO "https://dietpi.com/downloads/nanopi$series.7z" - G_EXEC "$c7zz" x "nanopi$series.7z" - G_EXEC rm "nanopi$series.7z" + G_EXEC curl -sSfO "https://dietpi.com/downloads/nanopi$series.img.xz" + G_EXEC xz -d "nanopi$series.img.xz" G_EXEC truncate -s "$(( 140 + $root_size ))M" "nanopi$series.img" G_EXEC_OUTPUT=1 G_EXEC sgdisk -e "nanopi$series.img" G_EXEC_OUTPUT=1 G_EXEC eval "sfdisk -fN8 'nanopi$series.img' <<< ',+'" @@ -669,11 +664,9 @@ fi ########################################## # Virtual machines ########################################## -G_EXEC_DESC='Downloading current README.md to pack with image...' G_EXEC curl -sSf "https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/README.md" -o README.md - # NB: LZMA2 ultra compression requires much memory per thread. 1 GiB is not sufficient for >2 threads, hence use "-mmt2" to limit used CPU threads to "2" on 1 GiB devices with more than two cores. limit_threads=() -(( $(free -m | mawk '/Mem:/{print $2}') < 1750 && $(nproc) > 2 )) && limit_threads=('-mmt2') +(( $(free -m | mawk '/Mem:/{print $2}') < 1750 && $(nproc) > 2 )) && limit_threads=('-T2') # Since qemu-img does not support VMDK and VHDX resizing, we need to resize the raw .img. It is usually done as sparse file, hence the actual disk usage does not change. G_EXEC qemu-img resize "$OUTPUT_IMG_NAME.img" 8G @@ -728,25 +721,11 @@ ethernet0.virtualDev = "e1000" ethernet0.present = "TRUE" extendedConfigFile = "$image_name.vmxf" floppy0.present = "FALSE" -_EOF_ - G_DIETPI-NOTIFY 2 'Generating hashes to pack with VMware appliance, please wait...' - cat << _EOF_ > hash.txt -FILE: $image_name.vmdk -DATE: $(date) -MD5: $(md5sum "$image_name.vmdk" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.vmdk" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.vmdk" | mawk '{print $1}') - -FILE: $image_name.vmx -DATE: $(date) -MD5: $(md5sum "$image_name.vmx" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.vmx" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.vmx" | mawk '{print $1}') _EOF_ [[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1 - G_EXEC_DESC='Creating VMware 7-Zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$image_name.7z" "$image_name.vmdk" "$image_name.vmx" hash.txt README.md + G_EXEC_DESC='Creating VMware tar.xz archive' XZ_OPT="-e9 ${limit_threads[*]}" G_EXEC tar -cJf "$image_name.tar.xz" "$image_name.vmdk" "$image_name.vmx" G_EXEC rm "$image_name.vmdk" "$image_name.vmx" - [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.7z" && G_EXEC rm "$image_name.7z" + [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.tar.xz" && G_EXEC rm "$image_name.tar.xz" fi ####### ESXi ############################# @@ -870,18 +849,9 @@ _EOF_ [[ $VMTYPE == 'all' ]] || G_EXEC rm "$image_name.vmdk" G_EXEC rm "$image_name."{ovf,mf} - G_DIETPI-NOTIFY 2 'Generating hashes to pack with ESXi appliance, please wait...' - cat << _EOF_ > hash.txt -FILE: $image_name.ova -DATE: $(date) -MD5: $(md5sum "$image_name.ova" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.ova" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.ova" | mawk '{print $1}') -_EOF_ [[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1 - G_EXEC_DESC='Creating VirtualBox 7-Zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$image_name.7z" "$image_name.ova" hash.txt README.md - G_EXEC rm "$image_name.ova" - [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.7z" && G_EXEC rm "$image_name.7z" + G_EXEC_DESC='Creating ESXi xz archive' G_EXEC xz -9e "${limit_threads[@]}" "$image_name.ova" + [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.ova.xz" && G_EXEC rm "$image_name.ova.xz" fi ####### VirtualBox ####################### @@ -1028,18 +998,9 @@ _EOF_ G_EXEC tar -cf "$image_name.ova" "$image_name."{ovf,vmdk,mf} G_EXEC rm "$image_name."{ovf,vmdk,mf} - G_DIETPI-NOTIFY 2 'Generating hashes to pack with VMware appliance, please wait...' - cat << _EOF_ > hash.txt -FILE: $image_name.ova -DATE: $(date) -MD5: $(md5sum "$image_name.ova" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.ova" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.ova" | mawk '{print $1}') -_EOF_ [[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1 - G_EXEC_DESC='Creating VirtualBox 7-Zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$image_name.7z" "$image_name.ova" hash.txt README.md - G_EXEC rm "$image_name.ova" - [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.7z" && G_EXEC rm "$image_name.7z" + G_EXEC_DESC='Creating VirtualBox xz archive' G_EXEC xz -9e "${limit_threads[@]}" "$image_name.ova" + [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.ova.xz" && G_EXEC rm "$image_name.ova.xz" fi ####### Hyper-V ########################## @@ -1049,18 +1010,9 @@ then # Convert raw image to VHDX G_EXEC qemu-img convert -O vhdx "$OUTPUT_IMG_NAME.img" "$image_name.vhdx" - G_DIETPI-NOTIFY 2 'Generating hashes to pack with Hyper-V image, please wait...' - cat << _EOF_ > hash.txt -FILE: $image_name.vhdx -DATE: $(date) -MD5: $(md5sum "$image_name.vhdx" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.vhdx" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.vhdx" | mawk '{print $1}') -_EOF_ [[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1 - G_EXEC_DESC='Creating Hyper-V 7-Zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$image_name.7z" "$image_name.vhdx" hash.txt README.md - G_EXEC rm "$image_name.vhdx" - [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.7z" && G_EXEC rm "$image_name.7z" + G_EXEC_DESC='Creating Hyper-V xz archive' G_EXEC xz -9e "${limit_threads[@]}" "$image_name.vhdx" + [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.vhdx.xz" && G_EXEC rm "$image_name.vhdx.xz" fi ####### Proxmox ############################ @@ -1070,18 +1022,13 @@ then # Convert raw image to QCOW2 G_EXEC qemu-img convert -c -O qcow2 "$OUTPUT_IMG_NAME.img" "$image_name.qcow2" - G_DIETPI-NOTIFY 2 'Generating hashes to pack with Proxmox image, please wait...' - cat << _EOF_ > hash.txt -FILE: $image_name.qcow2 -DATE: $(date) -MD5: $(md5sum "$image_name.qcow2" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.qcow2" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.qcow2" | mawk '{print $1}') -_EOF_ + # Keep QCOW2 in compression when UTM appliance shall be generated from it as well. + keep=() + [[ $VMTYPE == 'all' ]] && keep=('-k') + [[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1 - G_EXEC_DESC='Creating Proxmox 7-Zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$image_name.7z" "$image_name.qcow2" hash.txt README.md - [[ $VMTYPE == 'all' ]] || G_EXEC rm "$image_name.qcow2" - [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.7z" && G_EXEC rm "$image_name.7z" + G_EXEC_DESC='Creating Proxmox xz archive' G_EXEC xz -9e "${limit_threads[@]}" "${keep[@]}" "$image_name.qcow2" + [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.qcow2.xz" && G_EXEC rm "$image_name.qcow2.xz" fi ####### UTM ############################## @@ -1246,35 +1193,15 @@ _EOF_ -_EOF_ - G_DIETPI-NOTIFY 2 'Generating hashes to pack with UTM appliance, please wait...' - cat << _EOF_ > hash.txt -FILE: $image_name.utm/Images/data.qcow2 -DATE: $(date) -MD5: $(md5sum "$image_name.utm/Images/data.qcow2" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.utm/Images/data.qcow2" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.utm/Images/data.qcow2" | mawk '{print $1}') - -FILE: $image_name.utm/config.plist -DATE: $(date) -MD5: $(md5sum "$image_name.utm/config.plist" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.utm/config.plist" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.utm/config.plist" | mawk '{print $1}') - -FILE: $image_name.utm/view.plist -DATE: $(date) -MD5: $(md5sum "$image_name.utm/view.plist" | mawk '{print $1}') -SHA1: $(sha1sum "$image_name.utm/view.plist" | mawk '{print $1}') -SHA256: $(sha256sum "$image_name.utm/view.plist" | mawk '{print $1}') _EOF_ [[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1 - G_EXEC_DESC='Creating UTM 7-Zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$image_name.7z" "$image_name.utm" hash.txt README.md + G_EXEC_DESC='Creating UTM tar.xz archive' XZ_OPT="-e9 ${limit_threads[*]}" G_EXEC tar -cJf "$image_name.tar.xz" "$image_name.utm" G_EXEC rm -R "$image_name.utm" - [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.7z" && G_EXEC rm "$image_name.7z" + [[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$image_name.tar.xz" && G_EXEC rm "$image_name.tar.xz" fi # Cleanup -G_EXEC rm hash.txt README.md "$OUTPUT_IMG_NAME.img" +G_EXEC rm "$OUTPUT_IMG_NAME.img" exit 0 }