From 439a7b8a91af61fe3f44e93e3d056e8d0ca8a943 Mon Sep 17 00:00:00 2001 From: Mathew R Gordon <72643694+mgord9518@users.noreply.github.com> Date: Wed, 12 Jun 2024 23:39:38 -0600 Subject: [PATCH] Fix with squashfuse-zig, other small changes --- make_runtime.sh | 55 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/make_runtime.sh b/make_runtime.sh index 8266395..d01cd9a 100755 --- a/make_runtime.sh +++ b/make_runtime.sh @@ -9,6 +9,7 @@ [ -z $ARCH ] && ARCH='x86_64-aarch64' [ -z $COMP ] && COMP='lz4' [ -z $img_type ] && img_type='squashfs' +[ -z $TMPDIR ] && TMPDIR='/tmp' [ $STATIC_SQUASHFUSE ] && static_prefix='.static' @@ -24,19 +25,23 @@ else compress_flags="-9" fi -for arch in 'x86_64' 'aarch64' 'i386' 'armhf'; do +for arch in 'x86' 'x86_64' 'arm' 'aarch64'; do # Download required squashfuse squashfusearies per architecture if they don't already # exist - if [ $(grep "$arch" <<< "$ARCH") ]; then - if [ ! -f "squashfuse/squashfuse.$arch"* ]; then - wget "$squashfuse_source/squashfuse_${COMP}${static_prefix}.$arch" \ - -O "squashfuse/squashfuse.$arch" + if [ $(grep "$arch" <<< "-$ARCH-") ]; then + file="squashfuse/squashfuse.$arch" + if [ ! -f "$file" ] && [ ! -f "$file.gz" ]; then + echo "Downloading $arch" + + wget "$squashfuse_source/squashfuse-linux-$arch.tar.xz" -O - \ + | tar -xJ -C "squashfuse/" if [ $? -ne 0 ]; then - rm "squashfuse/squashfuse.$arch" + rm "squashfuse/squashfuse" exit $? fi + mv "squashfuse/squashfuse" "squashfuse/squashfuse.$arch" fi if [ $COMPRESS_SQUASHFUSE ]; then @@ -49,54 +54,60 @@ for arch in 'x86_64' 'aarch64' 'i386' 'armhf'; do fi done +temp_runtime="$TMPDIR/shImg.temp.runtime" + # Collapse the script to make it smaller, not really sure whether I should keep # it or not as it also obfuscates the code and the size difference makes little # difference as the squashfuse binaries make up an overwhelming majority of the # size of the runtime echo '#!/bin/sh #.shImg.# -#see for src' > runtime +#see for src' > "$temp_runtime" -cat runtime.sh | tr -d '\t' | sed 's/#.*//' | grep . >> runtime + +cat runtime.sh | tr -d '\t' | sed 's/#.*//' | grep . >> "$temp_runtime" arch=$(echo "$ARCH" | tr '-' ';') # Honestly, I can't think of any reason NOT to compress the squashfuse binaries # but leaving it as optional anyway -[ $COMPRESS_SQUASHFUSE ] && sed -i 's/head -c $length >/head -c $length | gzip -d >/' runtime -sed -i "s/=_IMAGE_COMPRESSION_/=$COMP/" runtime -sed -i "s/=_IMAGE_TYPE_/=$img_type/" runtime -sed -i "s/=_ARCH_/='$arch'/" runtime +[ $COMPRESS_SQUASHFUSE ] && sed -i 's/head -c $length >/head -c $length | gzip -d >/' "$temp_runtime" +sed -i "s/=_IMAGE_COMPRESSION_/=$COMP/" "$temp_runtime" +sed -i "s/=_IMAGE_TYPE_/=$img_type/" "$temp_runtime" +sed -i "s/=_ARCH_/='$arch'/" "$temp_runtime" # Add one because this number is used by tail, which reads offsets off by 1 -offset=$(($(cat runtime | wc -c) + 1)) +offset=$(($(cat "$temp_runtime" | wc -c) + 1)) length=0 # TODO: remove need for zero-padding for bin in $bin_list; do offset=$(printf "%07d" $((10#$offset + 10#$length))) - length=$(printf "%07d" $(wc -c ${bin}* | cut -d ' ' -f 1)) + length=$(printf "%07d" $(wc -c ${bin} | cut -d ' ' -f 1)) arch=$(cut -d'.' -f2 <<< "$bin") - sed -i "s/${arch}_offset=0000000/${arch}_offset=$offset/" runtime - sed -i "s/${arch}_length=0000000/${arch}_length=$length/" runtime + [ "$arch" = 'x86' ] && arch='i386' + [ "$arch" = 'arm' ] && arch='armhf' + + sed -i "s/${arch}_offset=0000000/${arch}_offset=$offset/" "$temp_runtime" + sed -i "s/${arch}_length=0000000/${arch}_length=$length/" "$temp_runtime" done -runtime_size=$(cat runtime $bin_list | wc -c | tr -dc '0-9') +runtime_size=$(cat "$temp_runtime" $bin_list | wc -c | tr -dc '0-9') # Had to expand to 7 digits because of DwarFS's large size image_offset=$(printf "%014d" "$runtime_size") -sed -i "s/=_IMAGE_OFFSET_/=$image_offset/" runtime +sed -i "s/=_IMAGE_OFFSET_/=$image_offset/" "$temp_runtime" -cat runtime $bin_list > runtime2 +cat "$temp_runtime" $bin_list > "$temp_runtime.2" if [ ! $img_type = dwarfs ]; then - mv runtime2 "runtime-$COMP$STATIC-$ARCH" + mv "$temp_runtime.2" "runtime-$COMP$STATIC-$ARCH" else - mv runtime2 "runtime_dwarfs-static-$ARCH" + mv "$temp_runtime.2" "runtime_dwarfs-static-$ARCH" rm squashfuse/squashfuse.x86_64.gz fi -rm runtime +rm "$temp_runtime"