Skip to content

Commit

Permalink
v8.22
Browse files Browse the repository at this point in the history
- DietPi-Imager | Move from 7z to xz for image compression and do not embed readme and hashes
  • Loading branch information
MichaIng committed Aug 31, 2023
1 parent bdde5bd commit dbbc413
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions .build/images/dietpi-imager
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# or use an existing .img file
# or use Clonezilla to generate a bootable installer ISO from drive for x86_64 systems
# - Minimises root partition and filesystem
# - Hashes and 7z's the final image ready for release
# - Compresses the final image ready for release
#////////////////////////////////////

# Import DietPi-Globals ---------------------------------------------------------------
Expand Down Expand Up @@ -277,9 +277,7 @@
Main(){

# Dependencies
local p7zip='7zip' c7zz='7zz'
(( $G_DISTRO < 7 )) && p7zip='p7zip' c7zz='7zr'
G_AG_CHECK_INSTALL_PREREQ parted fdisk zerofree "$p7zip"
G_AG_CHECK_INSTALL_PREREQ parted fdisk zerofree xz-utils

# Skip menu if all inputs are provided via environment variables
if [[ ( $SOURCE_TYPE$FP_SOURCE == 'Drive'?* || $SOURCE_TYPE$FP_SOURCE_IMG == 'Image'?* ) && $FP_ROOT_DEV && $CLONING_TOOL =~ ^(dd|Clonezilla)$ && $OUTPUT_IMG_NAME ]]
Expand Down Expand Up @@ -513,13 +511,13 @@
# Rename if source image != output image yet
[[ $(readlink -f "$PWD/$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT") != "$(readlink -f "$FP_SOURCE_IMG")" ]] && G_EXEC mv "$FP_SOURCE_IMG" "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT"

# Check for sufficient free disk space to store the 7z archive with 100 MiB buffer
# Check for sufficient free disk space to store the xz archive with 100 MiB buffer
G_CHECK_FREESPACE . $(( $IMAGE_SIZE * 15/100 / 1024**2 + 100 )) || exit 1

# Drive source and dd target
elif [[ $CLONING_TOOL == 'dd' ]]
then
# Check for sufficient free disk space to store the image and the 7z archive with 100 MiB buffer
# Check for sufficient free disk space to store the image and the xz archive with 100 MiB buffer
G_CHECK_FREESPACE . $(( $IMAGE_SIZE * 115/100 / 1024**2 + 100 )) || exit 1

G_DIETPI-NOTIFY 2 "Creating final image with actually used size: $(( $IMAGE_SIZE / 1024**2 + 1 )) MiB"
Expand Down Expand Up @@ -661,34 +659,21 @@ _EOF_
# Exit now when archive shall be skipped
(( $SKIP_ARCHIVE )) && exit 0

# Generate hashes: MD5, SHA1, SHA256
G_DIETPI-NOTIFY 2 'Generating hashes to pack with image, please wait...'
cat << _EOF_ > hash.txt
FILE: $OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT
DATE: $(date)
MD5: $(md5sum "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT" | mawk '{print $1}')
SHA1: $(sha1sum "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT" | mawk '{print $1}')
SHA256: $(sha256sum "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT" | mawk '{print $1}')
_EOF_
# Download current README
G_EXEC_DESC='Downloading current README.md to pack with image...' G_EXEC curl -sSf "$DIETPI_REPO/README.md" -o README.md

# Generate 7z archive
# Generate xz archive
# 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.
local limit_threads=()
(( $(free -m | mawk '/Mem:/{print $2}') < 1750 && $(nproc) > 2 )) && limit_threads=('-mmt2')
[[ -f $OUTPUT_IMG_NAME.7z ]] && G_EXEC rm "$OUTPUT_IMG_NAME.7z"
(( $(free -m | mawk '/Mem:/{print $2}') < 1750 && $(nproc) > 2 )) && limit_threads=('-T2')
[[ -f $OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT.xz ]] && G_EXEC rm "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT.xz"
[[ ( -t 0 || -t 1 ) && $TERM != 'dumb' ]] && G_EXEC_OUTPUT=1
# Add "-bsp1 -bso1 -bse2" to print output to regular STDOUT and STDERR, else the pipe to "tee" makes it omit at least the progress output.
G_EXEC_DESC='Creating final 7zip archive' G_EXEC "$c7zz" a -mx=9 "${limit_threads[@]}" "$OUTPUT_IMG_NAME.7z" "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT" hash.txt README.md
G_EXEC_DESC='Creating final xz archive' G_EXEC xz -9e "${limit_threads[@]}" "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT"

G_EXEC_NOHALT=1 G_EXEC rm hash.txt README.md
G_DIETPI-NOTIFY 0 "DietPi-Imager has successfully finished.
Final image file: $PWD/$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT
Final 7z archive: $PWD/$OUTPUT_IMG_NAME.7z"
Final xz archive: $PWD/$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT.xz"

# Upload archive automatically if there is an upload.sh in the same directory
[[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$OUTPUT_IMG_NAME.7z" && G_EXEC rm -R "$OUTPUT_IMG_NAME.7z"
[[ -x 'upload.sh' ]] && G_EXEC_OUTPUT=1 G_EXEC ./upload.sh "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT.xz" && G_EXEC rm -R "$OUTPUT_IMG_NAME.$OUTPUT_IMG_EXT.xz"

}

Expand Down

0 comments on commit dbbc413

Please sign in to comment.