From 1c98f4b01183906a769eefdd847fcde4ec6b29b5 Mon Sep 17 00:00:00 2001 From: DSR! Date: Sun, 12 Nov 2023 16:40:47 -0300 Subject: [PATCH] Small improvements in several scripts --- build.md | 2 +- tools/builder.sh | 21 ++++++++ tools/dependencies-install.sh | 7 ++- tools/fs-patcher.sh | 99 ++++++++++++++++++----------------- 4 files changed, 78 insertions(+), 51 deletions(-) diff --git a/build.md b/build.md index cafce8a..c153193 100644 --- a/build.md +++ b/build.md @@ -6,7 +6,7 @@ Depending on what you decide to build the scrript will guide the user on what fi chmod +x tools/*.sh tools/dependencies-install.sh openwrt-deps-mips sudo tools/dependencies-install.sh ubuntu-deps -tools/builder.sh mips universal imagebuilder-19.07.7-ar71xx-generic gl-ar750s +tools/builder.sh mips universal imagebuilder/19.07.7-ar71xx-generic gl-ar750s ```
diff --git a/tools/builder.sh b/tools/builder.sh index 0e44b80..f50635c 100755 --- a/tools/builder.sh +++ b/tools/builder.sh @@ -31,6 +31,12 @@ PACKAGES_UNIVERSAL="iw at autossh base-files bash block-mount ca-certificates ch # add missing deps and custom busybox build declare -a FORCE_PACKAGES=("libubus20191227_2019-12-27-041c9d1c-1" "busybox_1.30.1-6") +# fw hash +FW_TETRA_HASH="081278abfc227078b642b80c6a965c26b11bf820" +FW_NANO_HASH="3e087e6e9256431f2022e8e70373569d57f7ec77" +FW_MK7_HASH="32ba9cc3fd7e1b4489a14c1b3c5b4af118dff810" + +# fix folders paths IMAGEBUILDER_FOLDER="$(realpath $IMAGEBUILDER_FOLDER)" TOOL_FOLDER="$(realpath $(dirname $0)/../tools)" BUILD_FOLDER="$(realpath $(dirname $0)/../build)" @@ -110,6 +116,11 @@ prepare_build () { #echo " [+] Downloading TETRA firmware..." #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-tetra.bin -O "$FW_FOLDER/basefw.bin" + FW_HASH=$(sha1sum "$FW_FOLDER/basefw.bin" | awk '{ print $1 }') + if [ "$FW_HASH" != "$FW_TETRA_HASH" ]; then + echo " [!] WARNING file basefw.bin hash does not match" + fi + echo " [+] Unpack firmware for get file system" binwalk "$FW_FOLDER/basefw.bin" -e binwalk "$FW_FOLDER/_basefw.bin.extracted/sysupgrade-pineapple-tetra/root" -e --preserve-symlinks @@ -118,6 +129,11 @@ prepare_build () { #echo " [+] Downloading NANO firmware..." #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-nano.bin -O "$FW_FOLDER/basefw.bin" + FW_HASH=$(sha1sum "$FW_FOLDER/basefw.bin" | awk '{ print $1 }') + if [ "$FW_HASH" != "$FW_NANO_HASH" ]; then + echo " [!] WARNING file basefw.bin hash does not match" + fi + echo " [+] Unpack firmware for get file system" binwalk "$FW_FOLDER/basefw.bin" -e --preserve-symlinks mv "$FW_FOLDER/_basefw.bin.extracted/squashfs-root/" "$BUILD_FOLDER/rootfs-base" @@ -137,6 +153,11 @@ prepare_build () { #echo " [+] Downloading old MK7 firmware..." #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/1.1.1-mk7.bin -O "$FW_FOLDER/basefw-mk7.bin" + FW_HASH=$(sha1sum "$FW_FOLDER/basefw-mk7.bin" | awk '{ print $1 }') + if [ "$FW_HASH" != "$FW_MK7_HASH" ]; then + echo " [!] WARNING file basefw-mk7.bin hash does not match" + fi + echo " [+] Unpack mipsel firmware for get file system" binwalk "$FW_FOLDER/basefw-mk7.bin" -e --preserve-symlinks mv "$FW_FOLDER/_basefw-mk7.bin.extracted/squashfs-root/" "$BUILD_FOLDER/rootfs-mk7-base" diff --git a/tools/dependencies-install.sh b/tools/dependencies-install.sh index 89ad056..e3e1fcc 100755 --- a/tools/dependencies-install.sh +++ b/tools/dependencies-install.sh @@ -13,7 +13,10 @@ declare -a OPENWRT_MIPSEL_TARGET_LIST=( install_openwrt_deps () { TARGET="$1" - FOLDER_NAME="imagebuilder-$OPENWRT_VERSION-$TARGET" + if [ ! -d "imagebuilder" ]; then + mkdir "imagebuilder" + fi + FOLDER_NAME="imagebuilder/$OPENWRT_VERSION-$TARGET" ORIGINAL_FOLDER_NAME="openwrt-imagebuilder-$OPENWRT_VERSION-$TARGET.Linux-x86_64" FILE="$FOLDER_NAME.tar.xz" @@ -33,7 +36,7 @@ install_openwrt_deps () { rm -rf "$FOLDER_NAME" tar xJf "$FILE" mv "$ORIGINAL_FOLDER_NAME" "$FOLDER_NAME" - rm "$FILE" + #rm "$FILE" # correct opkg feeds echo " [+] Correct opkg feeds" diff --git a/tools/fs-patcher.sh b/tools/fs-patcher.sh index 1b93a91..e66c1e1 100755 --- a/tools/fs-patcher.sh +++ b/tools/fs-patcher.sh @@ -149,31 +149,6 @@ common_patch () { # add new banner cp "$FILES_FOLDER/common/etc/banner" "$ROOT_FS/etc/banner" - - # patch elf files - if [[ "$ARCHITECTURE" == "mips" ]]; then - xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex" - sed -i 's/6361 7420 2f70 726f 632f 636d 646c 696e/6563 686f 2027 5049 4e45 4150 504c 452d/' "$ROOT_FS/usr/bin/pineap.hex" - sed -i 's/6520 7c20 6177 6b20 277b 2073 706c 6974/5445 5452 4127 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/bin/pineap.hex" - sed -i 's/2824 312c 782c 223d 2229 3b20 7072 696e/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/bin/pineap.hex" - sed -i 's/7420 785b 325d 207d 2700 0000 5749 4649/2020 2020 2020 2020 2000 0000 5749 4649/' "$ROOT_FS/usr/bin/pineap.hex" - sed -i 's/6420 7379 6e74 6178 2065 6e61 626c 6564/6420 5B57 5043 2056 4552 5349 4F4E 5D20/' "$ROOT_FS/usr/bin/pineap.hex" - xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap" - rm "$ROOT_FS/usr/bin/pineap.hex" - - xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/7065 6e64 0000 0000 6361 7420 2f70 726f/7065 6e64 0000 0000 6563 686f 2027 5049/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/632f 636d 646c 696e 6520 7c20 6177 6b20/4e45 4150 504c 452d 5445 5452 4127 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/277b 2073 706c 6974 2824 312c 782c 223d/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2229 3b20 7072 696e 7420 785b 325d 207d/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2700 0000 646d 6573 6720 7c20 6865 6164/2000 0000 646d 6573 6720 7c20 6865 6164/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2079 5b31 5d7d 2700 646d 6573 6720 7c20/2079 5b31 5d7d 2700 6563 686f 2027 4152/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/6865 6164 202d 6e34 207c 2061 776b 2027/3933 3434 2072 6576 2720 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/464e 5220 3d3d 2034 207b 2070 7269 6e74/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2824 352c 2024 3629 207d 2700 2564 2d25/2020 2020 2020 2020 2020 2000 2564 2d25/' "$ROOT_FS/usr/sbin/pineapd.hex" - xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd" - rm "$ROOT_FS/usr/sbin/pineapd.hex" - fi } mipsel_patch () { @@ -195,29 +170,6 @@ mipsel_patch () { # use old name for sniffer rm "$ROOT_FS/usr/sbin/http_sniffer" mv "$ROOT_FS/usr/sbin/sniffer" "$ROOT_FS/usr/sbin/http_sniffer" - - # patch elf files - xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex" - sed -i 's/6420 7379 6e74 6178 2065 6e61 626c 6564/6420 5B57 5043 2056 4552 5349 4F4E 5D20/' "$ROOT_FS/usr/bin/pineap.hex" - xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap" - rm "$ROOT_FS/usr/bin/pineap.hex" - - xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/3030 3a30 3000 0000 202d 2000 6865 6164/3030 3a30 3000 0000 202d 2000 6563 686f/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/202d 6e32 202f 7072 6f63 2f63 7075 696e/2027 4861 6b35 2057 6946 6920 5069 6e65/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/666f 207c 2074 6169 6c20 2d6e 2031 207c/6170 706c 6520 4d61 726b 2037 2720 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2061 776b 2027 7b70 7269 6e74 2824 332c/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2434 2c24 352c 2436 2c24 3729 7d27 0000/2020 2020 2020 2020 2020 2020 2020 0000/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/6865 6164 202d 6e31 3020 2f70 726f 632f/6563 686f 2027 5b30 7830 6666 632c 2030/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/6370 7569 6e66 6f20 7c20 7461 696c 202d/7830 6666 632c 2030 7830 6666 622c 2030/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/6e20 3120 7c20 6177 6b20 277b 2070 7269/7830 6666 625d 2720 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/6e74 2824 392c 2431 302c 2431 312c 2431/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/3229 3b20 7d27 0000 6865 6164 202d 6e35/2020 2020 2020 0000 6563 686f 2027 3338/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/202f 7072 6f63 2f63 7075 696e 666f 207c/352e 3834 2720 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2074 6169 6c20 2d6e 2031 207c 2061 776b/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" - sed -i 's/2027 7b70 7269 6e74 2824 3329 7d27 0000/2020 2020 2020 2020 2020 2020 2020 0000/' "$ROOT_FS/usr/sbin/pineapd.hex" - xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd" - rm "$ROOT_FS/usr/sbin/pineapd.hex" } nano_patch () { @@ -277,6 +229,56 @@ universal_patch () { sed -i 's/DEVICE/OMEGA/' "$ROOT_FS/etc/banner" } +elf_patch () { + echo "[*] Patch elf files" + + if [[ "$ARCHITECTURE" == "mips" ]]; then + xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex" + sed -i 's/6361 7420 2f70 726f 632f 636d 646c 696e/6563 686f 2027 5049 4e45 4150 504c 452d/' "$ROOT_FS/usr/bin/pineap.hex" + sed -i 's/6520 7c20 6177 6b20 277b 2073 706c 6974/5445 5452 4127 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/bin/pineap.hex" + sed -i 's/2824 312c 782c 223d 2229 3b20 7072 696e/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/bin/pineap.hex" + sed -i 's/7420 785b 325d 207d 2700 0000 5749 4649/2020 2020 2020 2020 2000 0000 5749 4649/' "$ROOT_FS/usr/bin/pineap.hex" + sed -i 's/6420 7379 6e74 6178 2065 6e61 626c 6564/6420 5B57 5043 2056 4552 5349 4F4E 5D20/' "$ROOT_FS/usr/bin/pineap.hex" + xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap" + rm "$ROOT_FS/usr/bin/pineap.hex" + + xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/7065 6e64 0000 0000 6361 7420 2f70 726f/7065 6e64 0000 0000 6563 686f 2027 5049/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/632f 636d 646c 696e 6520 7c20 6177 6b20/4e45 4150 504c 452d 5445 5452 4127 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/277b 2073 706c 6974 2824 312c 782c 223d/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2229 3b20 7072 696e 7420 785b 325d 207d/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2700 0000 646d 6573 6720 7c20 6865 6164/2000 0000 646d 6573 6720 7c20 6865 6164/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2079 5b31 5d7d 2700 646d 6573 6720 7c20/2079 5b31 5d7d 2700 6563 686f 2027 4152/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/6865 6164 202d 6e34 207c 2061 776b 2027/3933 3434 2072 6576 2720 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/464e 5220 3d3d 2034 207b 2070 7269 6e74/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2824 352c 2024 3629 207d 2700 2564 2d25/2020 2020 2020 2020 2020 2000 2564 2d25/' "$ROOT_FS/usr/sbin/pineapd.hex" + xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd" + rm "$ROOT_FS/usr/sbin/pineapd.hex" + else + xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex" + sed -i 's/6420 7379 6e74 6178 2065 6e61 626c 6564/6420 5B57 5043 2056 4552 5349 4F4E 5D20/' "$ROOT_FS/usr/bin/pineap.hex" + xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap" + rm "$ROOT_FS/usr/bin/pineap.hex" + + xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/3030 3a30 3000 0000 202d 2000 6865 6164/3030 3a30 3000 0000 202d 2000 6563 686f/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/202d 6e32 202f 7072 6f63 2f63 7075 696e/2027 4861 6b35 2057 6946 6920 5069 6e65/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/666f 207c 2074 6169 6c20 2d6e 2031 207c/6170 706c 6520 4d61 726b 2037 2720 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2061 776b 2027 7b70 7269 6e74 2824 332c/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2434 2c24 352c 2436 2c24 3729 7d27 0000/2020 2020 2020 2020 2020 2020 2020 0000/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/6865 6164 202d 6e31 3020 2f70 726f 632f/6563 686f 2027 5b30 7830 6666 632c 2030/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/6370 7569 6e66 6f20 7c20 7461 696c 202d/7830 6666 632c 2030 7830 6666 622c 2030/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/6e20 3120 7c20 6177 6b20 277b 2070 7269/7830 6666 625d 2720 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/6e74 2824 392c 2431 302c 2431 312c 2431/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/3229 3b20 7d27 0000 6865 6164 202d 6e35/2020 2020 2020 0000 6563 686f 2027 3338/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/202f 7072 6f63 2f63 7075 696e 666f 207c/352e 3834 2720 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2074 6169 6c20 2d6e 2031 207c 2061 776b/2020 2020 2020 2020 2020 2020 2020 2020/' "$ROOT_FS/usr/sbin/pineapd.hex" + sed -i 's/2027 7b70 7269 6e74 2824 3329 7d27 0000/2020 2020 2020 2020 2020 2020 2020 0000/' "$ROOT_FS/usr/sbin/pineapd.hex" + xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd" + rm "$ROOT_FS/usr/sbin/pineapd.hex" + fi +} + # implement.... @@ -290,6 +292,7 @@ if [[ "$ARCHITECTURE" == "mipsel" ]]; then mipsel_patch fi common_patch +elf_patch echo "[*] Setting target as: $FLAVOR" if [[ $FLAVOR = 'nano' ]]