A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd

hibyos_nativepatcher: make tolerant of spaces in paths

Change-Id: Ibc0f2e6e1a00c526b4617e4b4ebfcfe132cbfa25

authored by

Dana Conrad and committed by
Solomon Peachy
f2ea677b 4d931469

+51 -51
+51 -51
tools/hibyos_nativepatcher/hibyos_nativepatcher.sh
··· 10 10 hibyos_nativepatcher.sh <mkrbinstall/mkstockuboot> [arguments depend on mode, see below] 11 11 12 12 hibyos_nativepatcher.sh mkrbinstall <OFVERNAME (erosq or eros_h2)> 13 - <path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2 or hw3)> 13 + <path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2, hw3, hw4)> 14 + 14 15 Output file will be path/to/output/erosqnative_RBVER-HWVER-OFVERNAME.upt. 15 16 Only the Hifiwalker H2 v1.3 uses "eros_h2", everything else uses "erosq". 16 17 17 18 hibyos_nativepatcher.sh mkstockuboot <path/to/OFupdatefile.upt> 18 - Output file will be path/to/OFupdatefile-rbuninstall.upt. 19 - 20 - NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS!" 19 + 20 + Output file will be path/to/OFupdatefile-rbuninstall.upt." 21 21 22 22 # check OS type and for any needed tools 23 23 if [[ "$OSTYPE" == "darwin"* ]]; then ··· 58 58 fi 59 59 60 60 # validate arguments 61 - outputdir=$(realpath --relative-base=$(pwd) $3) 62 - if !(ls $outputdir >& /dev/null); then 61 + outputdir=$(realpath "$3") 62 + if !(ls "$outputdir" >& /dev/null); then 63 63 echo "directory $outputdir doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh." 64 64 exit 1 65 65 fi 66 66 67 67 # note, bootloaderfile might still be a valid path, but not a valid bootloader file... check to make sure tar can extract it okay. 68 - bootloaderfile=$(realpath --relative-base=$(pwd) $4) 69 - if !(ls $bootloaderfile >& /dev/null); then 68 + bootloaderfile=$(realpath "$4") 69 + if !(ls "$bootloaderfile" >& /dev/null); then 70 70 echo "bootloader file $bootloaderfile doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh." 71 71 exit 1 72 72 fi 73 73 74 74 # make working directory... 75 - mkdir $outputdir/working_dir 76 - workingdir=$(realpath $outputdir/working_dir) 77 - mkdir $workingdir/bootloader 75 + mkdir "$outputdir"/working_dir 76 + workingdir=$(realpath "$outputdir"/working_dir) 77 + mkdir "$workingdir"/bootloader 78 78 79 79 # extract bootloader file 80 80 if [[ "$OSTYPE" == "darwin"* ]]; then 81 81 # macos 82 - tar -xvf $bootloaderfile --cd $workingdir/bootloader 82 + tar -xvf "$bootloaderfile" --cd "$workingdir"/bootloader 83 83 elif [[ "$OSTYPE" == "linux-gnu"* ]]; then 84 84 # linux-gnu 85 - tar -xvf $bootloaderfile -C $workingdir/bootloader 85 + tar -xvf "$bootloaderfile" -C "$workingdir"/bootloader 86 86 fi 87 87 88 88 # make sure we got what we wanted 89 - if !(ls $workingdir/bootloader/bootloader.ucl >& /dev/null); then 89 + if !(ls "$workingdir"/bootloader/bootloader.ucl >& /dev/null); then 90 90 echo "can't find bootloader.ucl! help!" 91 - rm -rf $workingdir 91 + rm -rf "$workingdir" 92 92 exit 1 93 - elif !(ls $workingdir/bootloader/spl.erosq >& /dev/null); then 93 + elif !(ls "$workingdir"/bootloader/spl.erosq >& /dev/null); then 94 94 echo "can't find spl.erosq! help!" 95 - rm -rf $workingdir 95 + rm -rf "$workingdir" 96 96 exit 1 97 97 fi 98 98 99 - bootver=$(cat $workingdir/bootloader/bootloader-info.txt) 99 + bootver=$(cat "$workingdir"/bootloader/bootloader-info.txt) 100 100 if [ -z "$bootver" ]; then 101 101 echo "COULDN'T FIND BOOTLOADER-INFO!" 102 - rm -rf $workingdir 102 + rm -rf "$workingdir" 103 103 exit 1 104 104 fi 105 105 106 106 # if uboot.bin already exists, something is weird. 107 - if (ls $workingdir/image_contents/uboot.bin >& /dev/null); then 107 + if (ls "$workingdir"/image_contents/uboot.bin >& /dev/null); then 108 108 echo "$workingdir/image_contents/uboot.bin already exists, something went weird." 109 - rm -rf $workingdir 109 + rm -rf "$workingdir" 110 110 exit 1 111 111 fi 112 112 113 113 # everything exists, make the bin 114 - mkdir $workingdir/image_contents/ 115 - touch $workingdir/image_contents/uboot.bin 114 + mkdir "$workingdir"/image_contents/ 115 + touch "$workingdir"/image_contents/uboot.bin 116 116 echo "PATCHING!" 117 - dd if=$workingdir/bootloader/spl.erosq of=$workingdir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc 118 - dd if=$workingdir/bootloader/bootloader.ucl of=$workingdir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc 117 + dd if="$workingdir"/bootloader/spl.erosq of="$workingdir"/image_contents/uboot.bin obs=1 seek=0 conv=notrunc 118 + dd if="$workingdir"/bootloader/bootloader.ucl of="$workingdir"/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc 119 119 120 120 # create update.txt 121 - md5=($(md5sum $workingdir/image_contents/uboot.bin)) 121 + md5=($(md5sum "$workingdir"/image_contents/uboot.bin)) 122 122 if [ -z "$md5" ]; then 123 123 echo "COULDN'T MD5SUM UBOOT.BIN!" 124 - rm -rf $workingdir 124 + rm -rf "$workingdir" 125 125 exit 1 126 126 fi 127 127 echo "Create update manifest with md5sum $md5" 128 - echo "" > $workingdir/image_contents/update.txt 129 - $SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt 128 + echo "" > "$workingdir"/image_contents/update.txt 129 + "$SCRIPT_DIR"/patch_manifest.pl "$md5" "$workingdir"/image_contents/update.txt 130 130 131 131 # create version.txt 132 132 echo "version={ 133 133 name=$2 134 134 ver=2024-09-10T14:42:18+08:00 135 - }" > $workingdir/image_contents/version.txt 135 + }" > "$workingdir"/image_contents/version.txt 136 136 137 137 outputfilename="erosqnative_$bootver-$5-$2" 138 138 ··· 150 150 exit 1 151 151 fi 152 152 153 - updatefile=$(realpath --relative-base=$(pwd) $2) 154 - updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") 155 - updatefile_name=$(basename $updatefile) 153 + updatefile=$(realpath "$2") 154 + updatefile_path=$(dirname "$updatefile") 155 + updatefile_name=$(basename "$updatefile") 156 156 updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") 157 - outputdir=$updatefile_path 158 - outputfilename="$updatefile_name_noext-rbuninstall" 157 + outputdir="$updatefile_path" 158 + outputfilename="$updatefile_name_noext"-rbuninstall 159 159 160 - mkdir $updatefile_path/working_dir 161 - workingdir=$(realpath $updatefile_path/working_dir) 160 + mkdir "$updatefile_path"/working_dir 161 + workingdir=$(realpath "$updatefile_path"/working_dir) 162 162 163 163 # copy update.upt to update.iso 164 - cp $updatefile $workingdir/$updatefile_name_noext-cpy.iso 164 + cp "$updatefile" "$workingdir"/"$updatefile_name_noext"-cpy.iso 165 165 166 - mkdir $workingdir/image_contents 166 + mkdir "$workingdir"/image_contents 167 167 168 168 # extract iso 169 169 if [[ "$OSTYPE" == "darwin"* ]]; then 170 170 # macos 171 - hdiutil attach $workingdir/$updatefile_name_noext-cpy.iso -mountpoint $workingdir/contentsiso 171 + hdiutil attach "$workingdir"/"$updatefile_name_noext"-cpy.iso -mountpoint "$workingdir"/contentsiso 172 172 173 173 # copy out iso contents 174 - cp $workingdir/contentsiso/* $workingdir/image_contents 174 + cp "$workingdir"/contentsiso/* "$workingdir"/image_contents 175 175 176 176 # unmount iso 177 - hdiutil detach $workingdir/contentsiso 177 + hdiutil detach "$workingdir"/contentsiso 178 178 elif [[ "$OSTYPE" == "linux-gnu"* ]]; then 179 179 # linux-gnu 180 - 7z -o$workingdir/image_contents x $workingdir/$updatefile_name_noext-cpy.iso 180 + 7z -o"$workingdir"/image_contents x "$workingdir"/"$updatefile_name_noext"-cpy.iso 181 181 fi 182 182 183 - chmod 777 $workingdir/image_contents/* 183 + chmod 777 "$workingdir"/image_contents/* 184 184 185 185 # modify update.txt 186 - md5=($(md5sum $workingdir/image_contents/uboot.bin)) 186 + md5=($(md5sum "$workingdir"/image_contents/uboot.bin)) 187 187 if [ -z "$md5" ]; then 188 188 echo "COULDN'T MD5SUM UBOOT.BIN!" 189 - rm -rf $working_dir 189 + rm -rf "$working_dir" 190 190 exit 1 191 191 fi 192 192 echo "add to update manifest with md5sum $md5" 193 - $SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt 193 + "$SCRIPT_DIR"/patch_manifest.pl "$md5" "$workingdir"/image_contents/update.txt 194 194 195 195 ###################################################################### 196 196 # PRINT USAGE ··· 206 206 # make the image 207 207 if [[ "$OSTYPE" == "darwin"* ]]; then 208 208 # macos 209 - hdiutil makehybrid -iso -joliet -o $outputdir/output.iso $workingdir/image_contents/ 209 + hdiutil makehybrid -iso -joliet -o "$outputdir"/output.iso "$workingdir"/image_contents/ 210 210 elif [[ "$OSTYPE" == "linux-gnu"* ]]; then 211 211 # linux-gnu 212 - genisoimage -o $outputdir/output.iso $workingdir/image_contents/ 212 + genisoimage -o "$outputdir"/output.iso "$workingdir"/image_contents/ 213 213 fi 214 214 215 215 # rename 216 - mv $outputdir/output.iso $outputdir/$outputfilename.upt 216 + mv "$outputdir"/output.iso "$outputdir"/"$outputfilename".upt 217 217 218 218 # cleaning up 219 - rm -rf $workingdir 219 + rm -rf "$workingdir" 220 220 221 221 exit 0