fs-patcher.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #!/bin/bash
  2. # by DSR! from https://github.com/xchwarze/wifi-pineapple-cloner
  3. ARCHITECTURE="$1"
  4. FLAVOR="$2"
  5. ROOT_FS="$3"
  6. declare -a ARCHITECTURE_TYPES=("mips" "mipsel")
  7. declare -a FLAVOR_TYPES=("nano" "tetra" "universal")
  8. if [[ ! -d "$ROOT_FS" ]] || ! grep -q "$ARCHITECTURE" <<< "${ARCHITECTURE_TYPES[*]}" || ! grep -q "$FLAVOR" <<< "${FLAVOR_TYPES[*]}"; then
  9. echo "Run with \"fs-patcher.sh [ARCHITECTURE] [FLAVOR] [FS_FOLDER]\""
  10. echo " ARCHITECTURE -> must be one of these values: mips, mipsel"
  11. echo " FLAVOR -> must be one of these values: nano, tetra, universal"
  12. echo " FS_FOLDER -> folder containing the fs to use"
  13. exit 1
  14. fi
  15. ROOT_FS="$(realpath $ROOT_FS)"
  16. FILES_FOLDER="$(realpath $(dirname $0)/../files)"
  17. common_patch () {
  18. echo "[*] Device detection fix"
  19. # fix "unknown operand" error
  20. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/hotplug.d/block/20-sd"
  21. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/hotplug.d/usb/30-sd"
  22. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/init.d/pineapple"
  23. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/rc.button/BTN_1"
  24. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/rc.button/reset"
  25. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/rc.local"
  26. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/uci-defaults/90-firewall.sh"
  27. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/uci-defaults/91-fstab.sh"
  28. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/uci-defaults/92-system.sh"
  29. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/uci-defaults/95-network.sh"
  30. sed -i 's/print $6/print $1/' "$ROOT_FS/etc/uci-defaults/97-pineapple.sh"
  31. sed -i 's/print $6/print $1/' "$ROOT_FS/sbin/led"
  32. # force setup
  33. sed -i 's/..Get Device/device="NANO"/' "$ROOT_FS/etc/rc.button/BTN_1"
  34. sed -i 's/..Get Device/device="NANO"/' "$ROOT_FS/etc/rc.button/reset"
  35. sed -i 's/..Get Device/device="NANO"/' "$ROOT_FS/etc/rc.local"
  36. sed -i 's/..Get Version and Device/device="TETRA"/' "$ROOT_FS/etc/uci-defaults/90-firewall.sh"
  37. sed -i 's/..Get Version and Device/device="NANO"/' "$ROOT_FS/etc/uci-defaults/91-fstab.sh"
  38. sed -i 's/..Get Version and Device/device="NANO"/' "$ROOT_FS/etc/uci-defaults/95-network.sh"
  39. sed -i 's/..Get Version and Device/device="NANO"/' "$ROOT_FS/etc/uci-defaults/97-pineapple.sh"
  40. sed -i 's/..Get device type/device="NANO"/' "$ROOT_FS/etc/uci-defaults/92-system.sh"
  41. #sed -i 's/..led (C) Hak5 2018/device="NANO"/' "$ROOT_FS/sbin/led"
  42. echo "[*] Correct OPKG feed url"
  43. cp "$FILES_FOLDER/$ARCHITECTURE/customfeeds.conf" "$ROOT_FS/etc/opkg/customfeeds.conf"
  44. echo "[*] Install panel fixes and improvements"
  45. # update panel code
  46. rm -rf "$ROOT_FS/pineapple"
  47. wget -q https://github.com/xchwarze/wifi-pineapple-panel/archive/refs/heads/wpc.zip -O updated-panel.zip
  48. unzip -q updated-panel.zip
  49. cp -r wifi-pineapple-panel-wpc/src/* "$ROOT_FS/"
  50. rm -rf wifi-pineapple-panel-wpc updated-panel.zip
  51. chmod +x "$ROOT_FS/etc/init.d/pineapd"
  52. chmod +x "$ROOT_FS/etc/uci-defaults/93-pineap.sh"
  53. chmod +x "$ROOT_FS/pineapple/modules/Advanced/formatSD/format_sd"
  54. chmod +x "$ROOT_FS/pineapple/modules/Help/files/debug"
  55. chmod +x "$ROOT_FS/pineapple/modules/PineAP/executable/executable"
  56. chmod +x "$ROOT_FS/pineapple/modules/Reporting/files/reporting"
  57. cp "$FILES_FOLDER/common/pineapple/favicon.ico" "$ROOT_FS/pineapple/img/favicon.ico"
  58. cp "$FILES_FOLDER/common/pineapple/favicon-16x16.png" "$ROOT_FS/pineapple/img/favicon-16x16.png"
  59. cp "$FILES_FOLDER/common/pineapple/favicon-32x32.png" "$ROOT_FS/pineapple/img/favicon-32x32.png"
  60. # fix docs size
  61. truncate -s 0 "$ROOT_FS/pineapple/modules/Setup/eula.txt"
  62. truncate -s 0 "$ROOT_FS/pineapple/modules/Setup/license.txt"
  63. echo "[*] Enable ssh by default"
  64. sed -i 's/\/etc\/init.d\/sshd/#\/etc\/init.d\/sshd/' "$ROOT_FS/etc/rc.local"
  65. echo "[*] Change root password to: root"
  66. cp "$FILES_FOLDER/common/etc/shadow" "$ROOT_FS/etc/shadow"
  67. echo "[*] Fix uci-defaults"
  68. cp "$FILES_FOLDER/common/etc/92-system.sh" "$ROOT_FS/etc/uci-defaults/92-system.sh"
  69. cp "$FILES_FOLDER/common/etc/95-network.sh" "$ROOT_FS/etc/uci-defaults/95-network.sh"
  70. cp "$FILES_FOLDER/common/etc/97-pineapple.sh" "$ROOT_FS/etc/uci-defaults/97-pineapple.sh"
  71. echo "[*] Fix pendrive hotplug"
  72. cp "$FILES_FOLDER/common/etc/20-sd-universal" "$ROOT_FS/etc/hotplug.d/block/20-sd-universal"
  73. rm "$ROOT_FS/etc/hotplug.d/block/20-sd"
  74. rm "$ROOT_FS/etc/hotplug.d/usb/30-sd"
  75. echo "[*] Add support for reflash"
  76. mkdir -p "$ROOT_FS/lib/upgrade/keep.d"
  77. cp "$FILES_FOLDER/common/lib/pineapple.keep" "$ROOT_FS/lib/upgrade/keep.d/pineapple"
  78. echo "[*] Fix airmon-ng listInterfaces()"
  79. mkdir -p "$ROOT_FS/usr/sbin"
  80. cp "$FILES_FOLDER/common/usr/airmon-ng" "$ROOT_FS/usr/sbin/airmon-ng"
  81. chmod +x "$ROOT_FS/usr/sbin/airmon-ng"
  82. echo "[*] Add wpc-tools and service"
  83. cp "$FILES_FOLDER/common/etc/wpc-tools" "$ROOT_FS/etc/init.d/wpc-tools"
  84. cp "$FILES_FOLDER/common/usr/wpc-tools" "$ROOT_FS/usr/bin/wpc-tools"
  85. chmod +x "$ROOT_FS/etc/init.d/wpc-tools"
  86. chmod +x "$ROOT_FS/usr/bin/wpc-tools"
  87. echo "[*] Other fixs"
  88. # clean files
  89. rm -f "$ROOT_FS/etc/pineapple/changes"
  90. rm -f "$ROOT_FS/etc/pineapple/pineapple_version"
  91. # default wifi config
  92. cp "$FILES_FOLDER/common/lib/mac80211.sh" "$ROOT_FS/lib/wifi/mac80211.sh"
  93. # fix wifi detection
  94. cp "$FILES_FOLDER/common/etc/30-fix_wifi" "$ROOT_FS/etc/hotplug.d/usb/30-fix_wifi"
  95. # copy clean version of led script
  96. cp "$FILES_FOLDER/common/sbin/led" "$ROOT_FS/sbin/led"
  97. chmod +x "$ROOT_FS/sbin/led"
  98. # add setup support for routers that do not have a reset button but do have wps
  99. # this modified the package "hostapd-common" wps button script
  100. mkdir -p "$ROOT_FS/etc/rc.button"
  101. cp "$FILES_FOLDER/common/etc/wps" "$ROOT_FS/etc/rc.button/wps"
  102. chmod +x "$ROOT_FS/etc/rc.button/wps"
  103. # add new banner
  104. cp "$FILES_FOLDER/common/etc/banner" "$ROOT_FS/etc/banner"
  105. }
  106. mipsel_patch () {
  107. echo "[*] Add mipsel support"
  108. if [ ! -f "$ROOT_FS/usr/sbin/sniffer" ]; then
  109. echo "[!] Attention!"
  110. echo ""
  111. echo "File '/usr/sbin/sniffer' was not found."
  112. echo "If you want to generate a mipsel-compatible build you must first perform the following steps:"
  113. echo " 1. Download the firmware v1.1.1 of the Mark VII"
  114. echo " 2. Execute the mass copy script with the mipsel-support.filelist list"
  115. echo " tools/copier.sh lists/mipsel-support.filelist rootfs-mk7 rootfs true"
  116. echo ""
  117. exit 1
  118. fi
  119. # use old name for sniffer
  120. rm "$ROOT_FS/usr/sbin/http_sniffer"
  121. mv "$ROOT_FS/usr/sbin/sniffer" "$ROOT_FS/usr/sbin/http_sniffer"
  122. }
  123. nano_patch () {
  124. # correct python-codecs version (from python-codecs_2.7.18-3_mips_24kc.ipk)
  125. mkdir -p "$ROOT_FS/usr/lib/python2.7/encodings"
  126. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/__init__.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/__init__.pyc"
  127. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/aliases.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/aliases.pyc"
  128. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/base64_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/base64_codec.pyc"
  129. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/hex_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/hex_codec.pyc"
  130. # panel changes
  131. # sed -i "s/\$data = file_get_contents('\/proc\/cpuinfo')/return 'nano'/" "$ROOT_FS/pineapple/api/pineapple.php"
  132. cp "$FILES_FOLDER/common/pineapple/config.php.nano" "$ROOT_FS/pineapple/config.php"
  133. # other changes
  134. sed -i "s/exec(\"cat \/proc\/cpuinfo | grep 'machine'\")/'nano'/" "$ROOT_FS/usr/bin/pineapple/site_survey"
  135. # fix banner info
  136. sed -i 's/DEVICE/NANO/' "$ROOT_FS/etc/banner"
  137. }
  138. tetra_patch () {
  139. # correct python-codecs version (from python-codecs_2.7.18-3_mips_24kc.ipk)
  140. mkdir -p "$ROOT_FS/usr/lib/python2.7/encodings"
  141. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/__init__.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/__init__.pyc"
  142. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/aliases.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/aliases.pyc"
  143. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/base64_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/base64_codec.pyc"
  144. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/hex_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/hex_codec.pyc"
  145. # panel changes
  146. # sed -i 's/tetra/nulled/' "$ROOT_FS/pineapple/js/directives.js"
  147. # sed -i 's/tetra/nulled/' "$ROOT_FS/pineapple/modules/ModuleManager/js/module.js"
  148. # sed -i 's/tetra/nulled/' "$ROOT_FS/pineapple/modules/Advanced/module.html"
  149. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/html/install-modal.html"
  150. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/Advanced/module.html"
  151. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/ModuleManager/js/module.js"
  152. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/Reporting/js/module.js"
  153. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/Reporting/api/module.php"
  154. # sed -i "s/\$data = file_get_contents('\/proc\/cpuinfo')/return 'tetra'/" "$ROOT_FS/pineapple/api/pineapple.php"
  155. cp "$FILES_FOLDER/common/pineapple/config.php.tetra" "$ROOT_FS/pineapple/config.php"
  156. # other changes
  157. sed -i "s/exec(\"cat \/proc\/cpuinfo | grep 'machine'\")/'tetra'/" "$ROOT_FS/usr/bin/pineapple/site_survey"
  158. # fix banner info
  159. sed -i 's/DEVICE/TETRA/' "$ROOT_FS/etc/banner"
  160. }
  161. universal_patch () {
  162. # panel changes
  163. cp "$FILES_FOLDER/common/pineapple/config.php.tetra" "$ROOT_FS/pineapple/config.php"
  164. # other changes
  165. sed -i "s/exec(\"cat \/proc\/cpuinfo | grep 'machine'\")/'tetra'/" "$ROOT_FS/usr/bin/pineapple/site_survey"
  166. # fix banner info
  167. sed -i 's/DEVICE/OMEGA/' "$ROOT_FS/etc/banner"
  168. }
  169. elf_patch () {
  170. echo "[*] Patch elf files"
  171. if [[ "$ARCHITECTURE" == "mips" ]]; then
  172. xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex"
  173. 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"
  174. 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"
  175. 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"
  176. 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"
  177. 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"
  178. xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap"
  179. rm "$ROOT_FS/usr/bin/pineap.hex"
  180. xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex"
  181. 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"
  182. 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"
  183. 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"
  184. 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"
  185. 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"
  186. 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"
  187. 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"
  188. 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"
  189. 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"
  190. xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd"
  191. rm "$ROOT_FS/usr/sbin/pineapd.hex"
  192. else
  193. xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex"
  194. 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"
  195. xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap"
  196. rm "$ROOT_FS/usr/bin/pineap.hex"
  197. xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex"
  198. 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"
  199. 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"
  200. 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"
  201. 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"
  202. 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"
  203. 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"
  204. 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"
  205. 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"
  206. 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"
  207. 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"
  208. 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"
  209. 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"
  210. 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"
  211. xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd"
  212. rm "$ROOT_FS/usr/sbin/pineapd.hex"
  213. fi
  214. }
  215. # implement....
  216. echo "Wifi Pineapple Cloner v4"
  217. echo "by DSR!"
  218. echo "******************************"
  219. echo ""
  220. # apply patches in order
  221. if [[ "$ARCHITECTURE" == "mipsel" ]]; then
  222. mipsel_patch
  223. fi
  224. common_patch
  225. elf_patch
  226. echo "[*] Setting target as: $FLAVOR"
  227. if [[ $FLAVOR = 'nano' ]]
  228. then
  229. nano_patch
  230. elif [[ $FLAVOR = 'tetra' ]]
  231. then
  232. tetra_patch
  233. elif [[ $FLAVOR = 'universal' ]]
  234. then
  235. universal_patch
  236. fi
  237. echo "[*] Done!"
  238. echo ""