Skip to content

Commit

Permalink
dietpi-build: make UEFI and ISO options independent
Browse files Browse the repository at this point in the history
- Merge "-i" and "-v" options into "-v"/"--variant", which can be defined for all builds but has an effect for x86_64 only so far. The previous "-i" flag can be achieved with "-v iso" now, and ISO images are build with "-v all" as well, for VM as well as PC images. "-v raw" is not invalid, as it can be achieved by just skipping the option, and raw images are implied with "-v all" as well.
- Add long forms for all CLI options.
- Print output image name when running DietPi-Imager
  • Loading branch information
MichaIng committed Jan 31, 2025
1 parent 92a94a3 commit 9f111b0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 59 deletions.
107 changes: 52 additions & 55 deletions .build/images/dietpi-build
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ HW_ARCH=
DISTRO=7 # 6=Bullseye, 7=Bookworm, 8=Trixie
PTTYPE='msdos'
FSTYPE='ext4'
ITYPE=
VMTYPE=
VARIANT=
GITBRANCH='master'
GITOWNER='MichaIng'
EDITION=
Expand All @@ -63,17 +62,16 @@ TEST_UBOOT=0
while (( $# ))
do
case $1 in
'-m') shift; HW_MODEL=$1;;
'-a') shift; HW_ARCH=$1;;
'-d') shift; DISTRO=$1;;
'-p') shift; PTTYPE=$1;;
'-f') shift; FSTYPE=$1;;
'-i') ITYPE='Installer';;
'-v') shift; VMTYPE=$1;;
'-b') shift; GITBRANCH=$1;;
'-o') shift; GITOWNER=$1;;
'-e') shift; EDITION=$1;;
'-s') shift; SUFFIX=$1;;
'-m'|'--model') shift; HW_MODEL=$1;;
'-a'|'--arch') shift; HW_ARCH=$1;;
'-d'|'--distro') shift; DISTRO=$1;;
'-p'|'--parttype') shift; PTTYPE=$1;;
'-f'|'--fstype') shift; FSTYPE=$1;;
'-v'|'--variant') shift; VARIANT=$1;;
'-b'|'--branch') shift; GITBRANCH=$1;;
'-o'|'--owner') shift; GITOWNER=$1;;
'-e'|'--edition') shift; EDITION=$1;;
'-s'|'--suffix') shift; SUFFIX=$1;;
'--skip-archive') SKIP_ARCHIVE=1;;
'--upload-script') shift; UPLOAD_SCRIPT=$1;;
'--no-dos-part') ADD_DOS_PART=0;;
Expand Down Expand Up @@ -103,8 +101,8 @@ case $HW_MODEL in
12) iname='OdroidC2' HW_ARCH=3 partition_start=4 root_size=1148;;
15) iname='OdroidN2' HW_ARCH=3 partition_start=4 root_size=1148;;
16) iname='OdroidC4' HW_ARCH=3 partition_start=4 root_size=1148;;
20) iname='VM' HW_ARCH=${HW_ARCH:-10} VMTYPE=${VMTYPE:-raw};;
21) iname='NativePC-BIOS' HW_ARCH=10 root_size=1663;;
20) iname='VM' HW_ARCH=${HW_ARCH:-10};;
21) iname='NativePC' HW_ARCH=10 root_size=1663;;
40) iname='PINEA64' HW_ARCH=3 partition_start=4 root_size=1020;;
42) iname='ROCKPro64' HW_ARCH=3 partition_start=16 root_size=1100;;
43) iname='ROCK64' HW_ARCH=3 partition_start=16 root_size=1100;;
Expand Down Expand Up @@ -167,12 +165,7 @@ case $HW_MODEL in
*) Error_Exit "Invalid hardware model \"$HW_MODEL\" passed. Aborting ...";;
esac

if [[ $VMTYPE ]]
then
[[ $HW_MODEL == 20 ]] || Error_Exit "Unsupported option \"-v\" (virtual machine type) for hardware model \"$HW_MODEL\" passed, aborting ..."
[[ $VMTYPE =~ ^(raw|vbox|vmx|esxi|hyperv|utm|proxmox|all)$ ]] || Error_Exit "Invalid virtual machine type \"$VMTYPE\" passed, aborting ..."
[[ $ITYPE == 'Installer' ]] && Error_Exit 'The VM type option "-v" cannot be combined with "-i", since installer images result in an ISO, instead of a virtual disk image or appliance. Aborting ...'
fi
[[ $VARIANT =~ ^(|iso|vbox|vmx|esxi|hyperv|utm|proxmox|all)$ ]] || Error_Exit "Invalid variant \"$VARIANT\" passed, aborting ..."

[[ $EDITION =~ ^(|Amiberry|AlloGUI|all)$ ]] || Error_Exit "Invalid edition \"$EDITION\" passed. Aborting ..."

Expand All @@ -196,13 +189,13 @@ case $DISTRO in
esac

case $PTTYPE in
'msdos') :;;
'gpt') [[ $HW_ARCH == 10 ]] && efi_size=64 iname="${iname%-BIOS}-UEFI";;
'msdos') [[ $HW_MODEL == 21 ]] && iname+='-BIOS';;
'gpt') [[ $HW_ARCH == 10 ]] && efi_size=64 iname+='-UEFI';;
*) Error_Exit "Invalid partition table type \"$PTTYPE\" passed. Aborting ...";;
esac

# Do not add trailing FAT partitions for VM, container and (Clonezilla) installer images, and if there is a boot FAT partition already
[[ $HW_MODEL == 20 || $HW_MODEL == 75 || $ITYPE == 'Installer' || ( $boot_size -gt 0 && $boot_fstype == 'fat'* ) ]] && ADD_DOS_PART=0
# Do not add trailing FAT partition for VM, container and ISO installer images, and if there is a boot FAT partition already
[[ $HW_MODEL == 20 || $HW_MODEL == 75 || $VARIANT == 'iso' || ( $boot_size -gt 0 && $boot_fstype == 'fat'* ) ]] && ADD_DOS_PART=0

fsname='' apackages=() afs_opts=() afsck=() aresize=()
case $FSTYPE in
Expand All @@ -217,14 +210,13 @@ G_CHECK_URL "https://github.com/$GITOWNER/DietPi/tree/$GITBRANCH" || Error_Exit
# Image name
OUTPUT_IMG_NAME="DietPi_$iname-$iarch-${distro^}"
[[ $fsname ]] && OUTPUT_IMG_NAME+="_$fsname"
[[ $ITYPE ]] && OUTPUT_IMG_NAME+="_$ITYPE"
[[ $SUFFIX ]] && OUTPUT_IMG_NAME+="_$SUFFIX"
# - x86_64 installer images
if [[ $ITYPE == 'Installer' ]]
if [[ $VARIANT == 'iso' ]]
then
[[ $HW_ARCH == 10 ]] || Error_Exit "Unsupported option \"-i\" (installer image) for architecture \"$HW_ARCH\" passed. Aborting ..."
[[ $HW_ARCH == 10 ]] || Error_Exit "Unsupported variant \"$VARIANT\" (installer image) for architecture \"$HW_ARCH\" passed. Aborting ..."
CLONING_TOOL='Clonezilla'
OUTPUT_IMG_NAME+='_Installer'
fi
[[ $SUFFIX ]] && OUTPUT_IMG_NAME+="_$SUFFIX"

##########################################
# Dependencies
Expand All @@ -240,7 +232,7 @@ emulation=0
(( $emulation )) && { apackages+=('qemu-user-static'); (( $G_DISTRO < 7 )) && apackages+=('binfmt-support'); }

# Virtual machine disk conversion
[[ $VMTYPE && $VMTYPE != 'raw' ]] && apackages+=('qemu-utils')
[[ $HW_MODEL == 20 && ! $VARIANT =~ ^(|iso)$ ]] && apackages+=('qemu-utils')

G_AG_CHECK_INSTALL_PREREQ --no-install-recommends parted mmdebstrap dbus systemd-container xz-utils "${apackages[@]}"

Expand Down Expand Up @@ -492,21 +484,34 @@ G_EXEC losetup -d "$FP_LOOP"
# DietPi-Imager
##########################################
# Do not pack and upload raw VM image if not explicitly requested
[[ $VMTYPE && ! $VMTYPE =~ ^(raw|all)$ ]] && SKIP_ARCHIVE=1 UPLOAD_SCRIPT=''
[[ $VARIANT =~ ^(|iso|all)$ ]] || SKIP_ARCHIVE=1 UPLOAD_SCRIPT=''
export FP_ROOT_DEV CLONING_TOOL OUTPUT_IMG_NAME MOUNT_IT='Off' SKIP_FIRSTBOOT_RESIZE=1
IMAGER_ARGS=("$OUTPUT_IMG_NAME.img")
(( $SKIP_ARCHIVE )) && IMAGER_ARGS+=('--skip-archive')
[[ $UPLOAD_SCRIPT ]] && IMAGER_ARGS+=('--upload-script' "$UPLOAD_SCRIPT")
(( $ADD_DOS_PART )) && IMAGER_ARGS+=('--add-dos-part')
[[ $HW_MODEL == [1245] ]] && IMAGER_ARGS+=('--configs-to-boot')
[[ $SIGN_PASS ]] && IMAGER_ARGS+=('--sign' "$SIGN_PASS")

####### IMG/ISO ##########################
if [[ ! $EDITION || $EDITION == 'all' ]]
then
G_DIETPI-NOTIFY 2 "Running DietPi-Imager for $G_GITOWNER/$G_GITBRANCH"
[[ $VARIANT == 'iso' ]] && ext='iso' || ext='img'
G_DIETPI-NOTIFY 2 "Running DietPi-Imager from $G_GITOWNER/$G_GITBRANCH to generate $OUTPUT_IMG_NAME.$ext"
bash -c "$(curl -sSf "https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/.build/images/dietpi-imager")" 'DietPi-Imager' "${IMAGER_ARGS[@]}" || exit 1
fi

# Amiberry edition: Install automatically on first boot, enable autostart option and onboard audio on RPi
####### ALL/ISO ##########################
if [[ $HW_ARCH == 10 && $VARIANT == 'all' ]]
then
CLONING_TOOL='Clonezilla' OUTPUT_IMG_NAME="${OUTPUT_IMG_NAME}_Installer"
G_DIETPI-NOTIFY 2 "Running DietPi-Imager from $G_GITOWNER/$G_GITBRANCH to generate $OUTPUT_IMG_NAME.iso"
bash -c "$(curl -sSf "https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/.build/images/dietpi-imager")" 'DietPi-Imager' "${IMAGER_ARGS[@]}" || exit 1
CLONING_TOOL='dd' OUTPUT_IMG_NAME=${OUTPUT_IMG_NAME%_Installer}
fi

####### Amiberry #########################
# - Install automatically on first boot, enable autostart option and onboard audio on RPi
if [[ $EDITION == 'Amiberry' || ( $EDITION == 'all' && $HW_MODEL == 0 ) ]]
then
G_EXEC mv "$OUTPUT_IMG_NAME.img" "${OUTPUT_IMG_NAME}_Amiberry.img"
Expand Down Expand Up @@ -556,11 +561,12 @@ then
G_EXEC rmdir rootfs
G_EXEC losetup -d "$FP_LOOP"

G_DIETPI-NOTIFY 2 "Running DietPi-Imager for $G_GITOWNER/$G_GITBRANCH"
G_DIETPI-NOTIFY 2 "Running DietPi-Imager from $G_GITOWNER/$G_GITBRANCH to generate $OUTPUT_IMG_NAME.img"
bash -c "$(curl -sSf "https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/.build/images/dietpi-imager")" 'DietPi-Imager' "${IMAGER_ARGS[@]}" || exit 1
fi

# AlloGUI edition: Pre-install Allo GUI with all managed audiophile software
####### AlloGUI ##########################
# - Pre-install Allo GUI with all managed audiophile software
# - Temporarily skip Trixie AlloGUI builds: The netdata package is currently not available (only on Raspbian, not Debian) and systemd-logind fails to start within the container as of a new change/bug, to investigate.
if [[ $EDITION == 'AlloGUI' || ( $EDITION == 'all' && $HW_MODEL =~ ^(0|70)$ && $DISTRO != 8 ) ]]
then
Expand Down Expand Up @@ -709,30 +715,21 @@ _EOF_
G_EXEC rmdir rootfs
G_EXEC losetup -d "$FP_LOOP"

G_DIETPI-NOTIFY 2 "Running DietPi-Imager for $G_GITOWNER/$G_GITBRANCH"
G_DIETPI-NOTIFY 2 "Running DietPi-Imager from $G_GITOWNER/$G_GITBRANCH to generate $OUTPUT_IMG_NAME.img"
bash -c "$(curl -sSf "https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/.build/images/dietpi-imager")" 'DietPi-Imager' "${IMAGER_ARGS[@]}" || exit 1
fi

[[ $VMTYPE && $VMTYPE != 'raw' ]] || exit 0
[[ $HW_MODEL == 20 && ! $VARIANT =~ ^(|iso)$ ]] || exit 0

##########################################
# Virtual machines
##########################################

####### ISO ##############################
if [[ $VMTYPE == all ]]
then
CLONING_TOOL='Clonezilla' OUTPUT_IMG_NAME="${OUTPUT_IMG_NAME}_Installer"
G_DIETPI-NOTIFY 2 "Running DietPi-Imager for $G_GITOWNER/$G_GITBRANCH"
bash -c "$(curl -sSf "https://raw.githubusercontent.com/$G_GITOWNER/DietPi/$G_GITBRANCH/.build/images/dietpi-imager")" 'DietPi-Imager' "${IMAGER_ARGS[@]}" || exit 1
CLONING_TOOL='dd' OUTPUT_IMG_NAME=${OUTPUT_IMG_NAME%_Installer}
fi

# 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

####### VMX/VMware/Parallels #############
if [[ $VMTYPE =~ ^(vmx|all)$ ]]
if [[ $VARIANT =~ ^(vmx|all)$ ]]
then
image_name=${OUTPUT_IMG_NAME/_VM-/_VMX-}
# Convert raw image to VMDK
Expand Down Expand Up @@ -791,7 +788,7 @@ _EOF_
fi

####### ESXi #############################
if [[ $VMTYPE =~ ^(esxi|all)$ ]]
if [[ $VARIANT =~ ^(esxi|all)$ ]]
then
image_name=${OUTPUT_IMG_NAME/_VM-/_ESXi-}
# Convert raw image to VMDK
Expand Down Expand Up @@ -908,7 +905,7 @@ SHA1($image_name.vmdk)= $(sha1sum "$image_name.vmdk" | mawk '{print $1}')
_EOF_
# Pack everything as OVA appliance for ESXi import
G_EXEC tar -cf "$image_name.ova" "$image_name."{ovf,vmdk,mf}
[[ $VMTYPE == 'all' ]] || G_EXEC rm "$image_name.vmdk"
[[ $VARIANT == 'all' ]] || G_EXEC rm "$image_name.vmdk"
G_EXEC rm "$image_name."{ovf,mf}

G_EXEC_DESC='Creating ESXi xz archive' G_EXEC xz -9e -T0 -M75% "$image_name.ova"
Expand All @@ -919,11 +916,11 @@ _EOF_
fi

####### VirtualBox #######################
if [[ $VMTYPE =~ ^(vbox|all)$ ]]
if [[ $VARIANT =~ ^(vbox|all)$ ]]
then
image_name=${OUTPUT_IMG_NAME/_VM-/_VirtualBox-}
# Reuse or convert raw image to VMDK
if [[ $VMTYPE == 'all' ]]
if [[ $VARIANT == 'all' ]]
then
G_EXEC mv "${OUTPUT_IMG_NAME/_VM-/_ESXi-}.vmdk" "$image_name.vmdk"
else
Expand Down Expand Up @@ -1070,7 +1067,7 @@ _EOF_
fi

####### Hyper-V ##########################
if [[ $VMTYPE =~ ^(hyperv|all)$ ]]
if [[ $VARIANT =~ ^(hyperv|all)$ ]]
then
image_name=${OUTPUT_IMG_NAME/_VM-/_Hyper-V-}
# Convert raw image to VHDX
Expand All @@ -1084,7 +1081,7 @@ then
fi

####### UTM ##############################
if [[ $VMTYPE =~ ^(utm|all)$ ]]
if [[ $VARIANT =~ ^(utm|all)$ ]]
then
image_name=${OUTPUT_IMG_NAME/_VM-/_UTM-}
# Create directory which is interpreted as VM appliance file on macOS
Expand Down Expand Up @@ -1250,7 +1247,7 @@ _EOF_
fi

####### Proxmox ############################
if [[ $VMTYPE =~ ^(proxmox|all)$ ]]
if [[ $VARIANT =~ ^(proxmox|all)$ ]]
then
# Convert raw image to QCOW2
image_name=${OUTPUT_IMG_NAME/_VM-/_Proxmox-}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/dietpi-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ jobs:
'"-m 15 -d 6", "-m 15 -d 7", "-m 15 -d 8", '\
'"-m 16 -d 6", "-m 16 -d 7", "-m 16 -d 8", '\
'"-m 20 -d 6 -v all", "-m 20 -d 7 -v all", "-m 20 -d 8 -v all", '\
'"-m 20 -d 6 -g gpt -i", "-m 20 -d 7 -g gpt -i", "-m 20 -d 8 -g gpt -i", '\
'"-m 21 -d 6", "-m 21 -d 7", "-m 21 -d 8", '\
'"-m 21 -d 6 -i", "-m 21 -d 7 -i", "-m 21 -d 8 -i", '\
'"-m 21 -d 6 -p gpt -i", "-m 21 -d 7 -p gpt -i", "-m 21 -d 8 -p gpt -i", '\
'"-m 20 -d 6 -v all -g gpt", "-m 20 -d 7 -g gpt -v all", "-m 20 -d 8 -g gpt -v all", '\
'"-m 21 -d 6 -v all", "-m 21 -d 7 -v all", "-m 21 -d 8 -v all", '\
'"-m 21 -d 6 -v all -g gpt", "-m 21 -d 7 -g gpt -v all", "-m 21 -d 8 -g gpt -v all", '\
'"-m 40 -d 6", "-m 40 -d 7", "-m 40 -d 8", '\
'"-m 42 -d 6", "-m 42 -d 7", "-m 42 -d 8", '\
'"-m 43 -d 6", "-m 43 -d 7", "-m 43 -d 8", '\
Expand Down

0 comments on commit 9f111b0

Please sign in to comment.