fs-patcher.sh 14 KB

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