fs-patcher.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. # patch elf files
  106. if [[ "$ARCHITECTURE" == "mips" ]]; then
  107. xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex"
  108. 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"
  109. 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"
  110. 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"
  111. 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"
  112. 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"
  113. xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap"
  114. rm "$ROOT_FS/usr/bin/pineap.hex"
  115. xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex"
  116. 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"
  117. 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"
  118. 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"
  119. 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"
  120. 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"
  121. 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"
  122. 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"
  123. 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"
  124. 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"
  125. xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd"
  126. rm "$ROOT_FS/usr/sbin/pineapd.hex"
  127. fi
  128. }
  129. mipsel_patch () {
  130. echo "[*] Add mipsel support"
  131. if [ ! -f "$ROOT_FS/usr/sbin/sniffer" ]; then
  132. echo "[!] Attention!"
  133. echo ""
  134. echo "File '/usr/sbin/sniffer' was not found."
  135. echo "If you want to generate a mipsel-compatible build you must first perform the following steps:"
  136. echo " 1. Download the firmware v1.1.1 of the Mark VII"
  137. echo " 2. Execute the mass copy script with the mipsel-support.filelist list"
  138. echo " tools/copier.sh lists/mipsel-support.filelist rootfs-mk7 rootfs true"
  139. echo ""
  140. exit 1
  141. fi
  142. # use old name for sniffer
  143. rm "$ROOT_FS/usr/sbin/http_sniffer"
  144. mv "$ROOT_FS/usr/sbin/sniffer" "$ROOT_FS/usr/sbin/http_sniffer"
  145. # patch elf files
  146. xxd "$ROOT_FS/usr/bin/pineap" "$ROOT_FS/usr/bin/pineap.hex"
  147. 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"
  148. xxd -r "$ROOT_FS/usr/bin/pineap.hex" "$ROOT_FS/usr/bin/pineap"
  149. rm "$ROOT_FS/usr/bin/pineap.hex"
  150. xxd "$ROOT_FS/usr/sbin/pineapd" "$ROOT_FS/usr/sbin/pineapd.hex"
  151. 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"
  152. 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"
  153. 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"
  154. 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"
  155. 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"
  156. 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"
  157. 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"
  158. 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"
  159. 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"
  160. 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"
  161. 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"
  162. 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"
  163. 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"
  164. xxd -r "$ROOT_FS/usr/sbin/pineapd.hex" "$ROOT_FS/usr/sbin/pineapd"
  165. rm "$ROOT_FS/usr/sbin/pineapd.hex"
  166. }
  167. nano_patch () {
  168. # correct python-codecs version (from python-codecs_2.7.18-3_mips_24kc.ipk)
  169. mkdir -p "$ROOT_FS/usr/lib/python2.7/encodings"
  170. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/__init__.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/__init__.pyc"
  171. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/aliases.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/aliases.pyc"
  172. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/base64_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/base64_codec.pyc"
  173. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/hex_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/hex_codec.pyc"
  174. # panel changes
  175. # sed -i "s/\$data = file_get_contents('\/proc\/cpuinfo')/return 'nano'/" "$ROOT_FS/pineapple/api/pineapple.php"
  176. cp "$FILES_FOLDER/common/pineapple/config.php.nano" "$ROOT_FS/pineapple/config.php"
  177. # other changes
  178. sed -i "s/exec(\"cat \/proc\/cpuinfo | grep 'machine'\")/'nano'/" "$ROOT_FS/usr/bin/pineapple/site_survey"
  179. # fix banner info
  180. sed -i 's/DEVICE/NANO/' "$ROOT_FS/etc/banner"
  181. }
  182. tetra_patch () {
  183. # correct python-codecs version (from python-codecs_2.7.18-3_mips_24kc.ipk)
  184. mkdir -p "$ROOT_FS/usr/lib/python2.7/encodings"
  185. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/__init__.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/__init__.pyc"
  186. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/aliases.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/aliases.pyc"
  187. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/base64_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/base64_codec.pyc"
  188. cp "$FILES_FOLDER/$ARCHITECTURE/python/encodings/hex_codec.pyc" "$ROOT_FS/usr/lib/python2.7/encodings/hex_codec.pyc"
  189. # panel changes
  190. # sed -i 's/tetra/nulled/' "$ROOT_FS/pineapple/js/directives.js"
  191. # sed -i 's/tetra/nulled/' "$ROOT_FS/pineapple/modules/ModuleManager/js/module.js"
  192. # sed -i 's/tetra/nulled/' "$ROOT_FS/pineapple/modules/Advanced/module.html"
  193. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/html/install-modal.html"
  194. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/Advanced/module.html"
  195. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/ModuleManager/js/module.js"
  196. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/Reporting/js/module.js"
  197. # sed -i 's/nano/tetra/' "$ROOT_FS/pineapple/modules/Reporting/api/module.php"
  198. # sed -i "s/\$data = file_get_contents('\/proc\/cpuinfo')/return 'tetra'/" "$ROOT_FS/pineapple/api/pineapple.php"
  199. cp "$FILES_FOLDER/common/pineapple/config.php.tetra" "$ROOT_FS/pineapple/config.php"
  200. # other changes
  201. sed -i "s/exec(\"cat \/proc\/cpuinfo | grep 'machine'\")/'tetra'/" "$ROOT_FS/usr/bin/pineapple/site_survey"
  202. # fix banner info
  203. sed -i 's/DEVICE/TETRA/' "$ROOT_FS/etc/banner"
  204. }
  205. universal_patch () {
  206. # panel changes
  207. cp "$FILES_FOLDER/common/pineapple/config.php.tetra" "$ROOT_FS/pineapple/config.php"
  208. # other changes
  209. sed -i "s/exec(\"cat \/proc\/cpuinfo | grep 'machine'\")/'tetra'/" "$ROOT_FS/usr/bin/pineapple/site_survey"
  210. # fix banner info
  211. sed -i 's/DEVICE/OMEGA/' "$ROOT_FS/etc/banner"
  212. }
  213. # implement....
  214. echo "Wifi Pineapple Cloner v4"
  215. echo "by DSR!"
  216. echo "******************************"
  217. echo ""
  218. # apply patches in order
  219. if [[ "$ARCHITECTURE" == "mipsel" ]]; then
  220. mipsel_patch
  221. fi
  222. common_patch
  223. echo "[*] Setting target as: $FLAVOR"
  224. if [[ $FLAVOR = 'nano' ]]
  225. then
  226. nano_patch
  227. elif [[ $FLAVOR = 'tetra' ]]
  228. then
  229. tetra_patch
  230. elif [[ $FLAVOR = 'universal' ]]
  231. then
  232. universal_patch
  233. fi
  234. echo "[*] Done!"
  235. echo ""