diff options
Diffstat (limited to 'tools/hibyos_nativepatcher/hibyos_nativepatcher.sh')
-rwxr-xr-x | tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh new file mode 100755 index 0000000000..e0a76da5c2 --- /dev/null +++ b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | |||
@@ -0,0 +1,117 @@ | |||
1 | #!/bin/bash | ||
2 | # USAGE: ./hibyos_nativepatcher.sh <path/to/updatefile.upt> <path/to/bootloader.erosq> | ||
3 | # NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS | ||
4 | |||
5 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
6 | echo "$OSTYPE DETECTED" | ||
7 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
8 | echo "$OSTYPE DETECTED" | ||
9 | if !(which 7z > /dev/null); then | ||
10 | echo "PLEASE INSTALL 7z (usually part of p7zip-full package)" | ||
11 | exit 1 | ||
12 | fi | ||
13 | if !(which genisoimage > /dev/null); then | ||
14 | echo "PLEASE INSTALL genisoimage" | ||
15 | exit 1 | ||
16 | fi | ||
17 | else | ||
18 | echo "SCRIPT NOT IMPLEMENTED ON $OSTYPE YET!" | ||
19 | exit 1 | ||
20 | fi | ||
21 | |||
22 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
23 | if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then | ||
24 | echo "couldn't find patch_manifest.pl!" | ||
25 | exit 1 | ||
26 | fi | ||
27 | |||
28 | updatefile=$(realpath --relative-base=$(pwd) $1) | ||
29 | updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") | ||
30 | updatefile_name=$(basename $updatefile) | ||
31 | updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") | ||
32 | bootfile=$(realpath --relative-base=$(pwd) $2) | ||
33 | echo "This will patch $updatefile with $bootfile..." | ||
34 | |||
35 | echo "MAKE WORKING DIR..." | ||
36 | mkdir $updatefile_path/working_dir | ||
37 | working_dir=$(realpath $updatefile_path/working_dir) | ||
38 | |||
39 | # copy update.upt to update.iso | ||
40 | cp $updatefile $working_dir/$updatefile_name_noext\_cpy.iso | ||
41 | |||
42 | mkdir $working_dir/image_contents | ||
43 | |||
44 | # attach/mount iso | ||
45 | echo "mount/extract/unmount original iso..." | ||
46 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
47 | # macos | ||
48 | hdiutil attach $working_dir/$updatefile_name_noext\_cpy.iso -mountpoint $working_dir/contentsiso | ||
49 | |||
50 | # copy out iso contents | ||
51 | cp $working_dir/contentsiso/* $working_dir/image_contents | ||
52 | |||
53 | # unmount iso | ||
54 | hdiutil detach $working_dir/contentsiso | ||
55 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
56 | # linux-gnu | ||
57 | 7z -o$working_dir/image_contents x $working_dir/$updatefile_name_noext\_cpy.iso | ||
58 | fi | ||
59 | |||
60 | chmod 777 $working_dir/image_contents/* | ||
61 | |||
62 | # extract spl, bootloader | ||
63 | echo "extract bootloader..." | ||
64 | mkdir $working_dir/bootloader | ||
65 | |||
66 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
67 | # macos | ||
68 | tar -xvf $bootfile --cd $working_dir/bootloader | ||
69 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
70 | # linux-gnu | ||
71 | tar -xvf $bootfile -C $working_dir/bootloader | ||
72 | fi | ||
73 | |||
74 | bootver=$(cat $working_dir/bootloader/bootloader-info.txt) | ||
75 | if [ -z "$bootver" ]; then | ||
76 | echo "COULDN'T FIND BOOTLOADER-INFO!" | ||
77 | echo "cleaning up..." | ||
78 | rm -rf $working_dir | ||
79 | exit 1 | ||
80 | fi | ||
81 | echo "FOUND VERSION $bootver" | ||
82 | |||
83 | # patch uboot.bin | ||
84 | echo "PATCH!" | ||
85 | dd if=$working_dir/bootloader/spl.erosq of=$working_dir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc | ||
86 | dd if=$working_dir/bootloader/bootloader.ucl of=$working_dir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc | ||
87 | |||
88 | # modify update.txt | ||
89 | md5=($(md5sum $working_dir/image_contents/uboot.bin)) | ||
90 | if [ -z "$md5" ]; then | ||
91 | echo "COULDN'T MD5SUM UBOOT.BIN!" | ||
92 | echo "cleaning up..." | ||
93 | rm -rf $working_dir | ||
94 | exit 1 | ||
95 | fi | ||
96 | echo "add to update manifest with md5sum $md5" | ||
97 | $SCRIPT_DIR/patch_manifest.pl $md5 $working_dir/image_contents/update.txt | ||
98 | |||
99 | # modify version.txt? | ||
100 | |||
101 | # create iso | ||
102 | echo "make new iso..." | ||
103 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
104 | # macos | ||
105 | hdiutil makehybrid -iso -joliet -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ | ||
106 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
107 | # linux-gnu | ||
108 | genisoimage -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ | ||
109 | fi | ||
110 | |||
111 | # rename to something.upt and put in original directory | ||
112 | echo "final output file $updatefile_name_noext\_patched_$bootver.upt" | ||
113 | mv $working_dir/$updatefile_name_noext\_patched_$bootver.iso $updatefile_path/$updatefile_name_noext\_patched_$bootver.upt | ||
114 | |||
115 | # clean up | ||
116 | echo "cleaning up..." | ||
117 | rm -rf $working_dir | ||