hibyos_nativepatcher: make tolerant of spaces in paths

Change-Id: Ibc0f2e6e1a00c526b4617e4b4ebfcfe132cbfa25
This commit is contained in:
Dana Conrad 2025-06-27 09:36:09 -05:00 committed by Solomon Peachy
parent 4d9314692f
commit f2ea677b4d

View file

@ -10,14 +10,14 @@ usage="hibyos_nativepatcher.sh
hibyos_nativepatcher.sh <mkrbinstall/mkstockuboot> [arguments depend on mode, see below] hibyos_nativepatcher.sh <mkrbinstall/mkstockuboot> [arguments depend on mode, see below]
hibyos_nativepatcher.sh mkrbinstall <OFVERNAME (erosq or eros_h2)> hibyos_nativepatcher.sh mkrbinstall <OFVERNAME (erosq or eros_h2)>
<path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2 or hw3)> <path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2, hw3, hw4)>
Output file will be path/to/output/erosqnative_RBVER-HWVER-OFVERNAME.upt. Output file will be path/to/output/erosqnative_RBVER-HWVER-OFVERNAME.upt.
Only the Hifiwalker H2 v1.3 uses "eros_h2", everything else uses "erosq". Only the Hifiwalker H2 v1.3 uses "eros_h2", everything else uses "erosq".
hibyos_nativepatcher.sh mkstockuboot <path/to/OFupdatefile.upt> hibyos_nativepatcher.sh mkstockuboot <path/to/OFupdatefile.upt>
Output file will be path/to/OFupdatefile-rbuninstall.upt.
Output file will be path/to/OFupdatefile-rbuninstall.upt."
NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS!"
# check OS type and for any needed tools # check OS type and for any needed tools
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
@ -58,81 +58,81 @@ if [[ "$1" == "mkrbinstall" ]]; then
fi fi
# validate arguments # validate arguments
outputdir=$(realpath --relative-base=$(pwd) $3) outputdir=$(realpath "$3")
if !(ls $outputdir >& /dev/null); then if !(ls "$outputdir" >& /dev/null); then
echo "directory $outputdir doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh." echo "directory $outputdir doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh."
exit 1 exit 1
fi fi
# note, bootloaderfile might still be a valid path, but not a valid bootloader file... check to make sure tar can extract it okay. # note, bootloaderfile might still be a valid path, but not a valid bootloader file... check to make sure tar can extract it okay.
bootloaderfile=$(realpath --relative-base=$(pwd) $4) bootloaderfile=$(realpath "$4")
if !(ls $bootloaderfile >& /dev/null); then if !(ls "$bootloaderfile" >& /dev/null); then
echo "bootloader file $bootloaderfile doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh." echo "bootloader file $bootloaderfile doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh."
exit 1 exit 1
fi fi
# make working directory... # make working directory...
mkdir $outputdir/working_dir mkdir "$outputdir"/working_dir
workingdir=$(realpath $outputdir/working_dir) workingdir=$(realpath "$outputdir"/working_dir)
mkdir $workingdir/bootloader mkdir "$workingdir"/bootloader
# extract bootloader file # extract bootloader file
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
# macos # macos
tar -xvf $bootloaderfile --cd $workingdir/bootloader tar -xvf "$bootloaderfile" --cd "$workingdir"/bootloader
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux-gnu # linux-gnu
tar -xvf $bootloaderfile -C $workingdir/bootloader tar -xvf "$bootloaderfile" -C "$workingdir"/bootloader
fi fi
# make sure we got what we wanted # make sure we got what we wanted
if !(ls $workingdir/bootloader/bootloader.ucl >& /dev/null); then if !(ls "$workingdir"/bootloader/bootloader.ucl >& /dev/null); then
echo "can't find bootloader.ucl! help!" echo "can't find bootloader.ucl! help!"
rm -rf $workingdir rm -rf "$workingdir"
exit 1 exit 1
elif !(ls $workingdir/bootloader/spl.erosq >& /dev/null); then elif !(ls "$workingdir"/bootloader/spl.erosq >& /dev/null); then
echo "can't find spl.erosq! help!" echo "can't find spl.erosq! help!"
rm -rf $workingdir rm -rf "$workingdir"
exit 1 exit 1
fi fi
bootver=$(cat $workingdir/bootloader/bootloader-info.txt) bootver=$(cat "$workingdir"/bootloader/bootloader-info.txt)
if [ -z "$bootver" ]; then if [ -z "$bootver" ]; then
echo "COULDN'T FIND BOOTLOADER-INFO!" echo "COULDN'T FIND BOOTLOADER-INFO!"
rm -rf $workingdir rm -rf "$workingdir"
exit 1 exit 1
fi fi
# if uboot.bin already exists, something is weird. # if uboot.bin already exists, something is weird.
if (ls $workingdir/image_contents/uboot.bin >& /dev/null); then if (ls "$workingdir"/image_contents/uboot.bin >& /dev/null); then
echo "$workingdir/image_contents/uboot.bin already exists, something went weird." echo "$workingdir/image_contents/uboot.bin already exists, something went weird."
rm -rf $workingdir rm -rf "$workingdir"
exit 1 exit 1
fi fi
# everything exists, make the bin # everything exists, make the bin
mkdir $workingdir/image_contents/ mkdir "$workingdir"/image_contents/
touch $workingdir/image_contents/uboot.bin touch "$workingdir"/image_contents/uboot.bin
echo "PATCHING!" echo "PATCHING!"
dd if=$workingdir/bootloader/spl.erosq of=$workingdir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc dd if="$workingdir"/bootloader/spl.erosq of="$workingdir"/image_contents/uboot.bin obs=1 seek=0 conv=notrunc
dd if=$workingdir/bootloader/bootloader.ucl of=$workingdir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc dd if="$workingdir"/bootloader/bootloader.ucl of="$workingdir"/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc
# create update.txt # create update.txt
md5=($(md5sum $workingdir/image_contents/uboot.bin)) md5=($(md5sum "$workingdir"/image_contents/uboot.bin))
if [ -z "$md5" ]; then if [ -z "$md5" ]; then
echo "COULDN'T MD5SUM UBOOT.BIN!" echo "COULDN'T MD5SUM UBOOT.BIN!"
rm -rf $workingdir rm -rf "$workingdir"
exit 1 exit 1
fi fi
echo "Create update manifest with md5sum $md5" echo "Create update manifest with md5sum $md5"
echo "" > $workingdir/image_contents/update.txt echo "" > "$workingdir"/image_contents/update.txt
$SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt "$SCRIPT_DIR"/patch_manifest.pl "$md5" "$workingdir"/image_contents/update.txt
# create version.txt # create version.txt
echo "version={ echo "version={
name=$2 name=$2
ver=2024-09-10T14:42:18+08:00 ver=2024-09-10T14:42:18+08:00
}" > $workingdir/image_contents/version.txt }" > "$workingdir"/image_contents/version.txt
outputfilename="erosqnative_$bootver-$5-$2" outputfilename="erosqnative_$bootver-$5-$2"
@ -150,47 +150,47 @@ elif [[ "$1" == "mkstockuboot" ]]; then
exit 1 exit 1
fi fi
updatefile=$(realpath --relative-base=$(pwd) $2) updatefile=$(realpath "$2")
updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") updatefile_path=$(dirname "$updatefile")
updatefile_name=$(basename $updatefile) updatefile_name=$(basename "$updatefile")
updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print")
outputdir=$updatefile_path outputdir="$updatefile_path"
outputfilename="$updatefile_name_noext-rbuninstall" outputfilename="$updatefile_name_noext"-rbuninstall
mkdir $updatefile_path/working_dir mkdir "$updatefile_path"/working_dir
workingdir=$(realpath $updatefile_path/working_dir) workingdir=$(realpath "$updatefile_path"/working_dir)
# copy update.upt to update.iso # copy update.upt to update.iso
cp $updatefile $workingdir/$updatefile_name_noext-cpy.iso cp "$updatefile" "$workingdir"/"$updatefile_name_noext"-cpy.iso
mkdir $workingdir/image_contents mkdir "$workingdir"/image_contents
# extract iso # extract iso
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
# macos # macos
hdiutil attach $workingdir/$updatefile_name_noext-cpy.iso -mountpoint $workingdir/contentsiso hdiutil attach "$workingdir"/"$updatefile_name_noext"-cpy.iso -mountpoint "$workingdir"/contentsiso
# copy out iso contents # copy out iso contents
cp $workingdir/contentsiso/* $workingdir/image_contents cp "$workingdir"/contentsiso/* "$workingdir"/image_contents
# unmount iso # unmount iso
hdiutil detach $workingdir/contentsiso hdiutil detach "$workingdir"/contentsiso
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux-gnu # linux-gnu
7z -o$workingdir/image_contents x $workingdir/$updatefile_name_noext-cpy.iso 7z -o"$workingdir"/image_contents x "$workingdir"/"$updatefile_name_noext"-cpy.iso
fi fi
chmod 777 $workingdir/image_contents/* chmod 777 "$workingdir"/image_contents/*
# modify update.txt # modify update.txt
md5=($(md5sum $workingdir/image_contents/uboot.bin)) md5=($(md5sum "$workingdir"/image_contents/uboot.bin))
if [ -z "$md5" ]; then if [ -z "$md5" ]; then
echo "COULDN'T MD5SUM UBOOT.BIN!" echo "COULDN'T MD5SUM UBOOT.BIN!"
rm -rf $working_dir rm -rf "$working_dir"
exit 1 exit 1
fi fi
echo "add to update manifest with md5sum $md5" echo "add to update manifest with md5sum $md5"
$SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt "$SCRIPT_DIR"/patch_manifest.pl "$md5" "$workingdir"/image_contents/update.txt
###################################################################### ######################################################################
# PRINT USAGE # PRINT USAGE
@ -206,16 +206,16 @@ fi
# make the image # make the image
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
# macos # macos
hdiutil makehybrid -iso -joliet -o $outputdir/output.iso $workingdir/image_contents/ hdiutil makehybrid -iso -joliet -o "$outputdir"/output.iso "$workingdir"/image_contents/
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux-gnu # linux-gnu
genisoimage -o $outputdir/output.iso $workingdir/image_contents/ genisoimage -o "$outputdir"/output.iso "$workingdir"/image_contents/
fi fi
# rename # rename
mv $outputdir/output.iso $outputdir/$outputfilename.upt mv "$outputdir"/output.iso "$outputdir"/"$outputfilename".upt
# cleaning up # cleaning up
rm -rf $workingdir rm -rf "$workingdir"
exit 0 exit 0