builder.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #!/bin/bash
  2. # by DSR! from https://github.com/xchwarze/wifi-pineapple-cloner
  3. ARCHITECTURE="$1"
  4. FLAVOR="$2"
  5. IMAGEBUILDER_FOLDER="$3"
  6. PROFILE="$4"
  7. declare -a ARCHITECTURE_TYPES=("mips" "mipsel")
  8. declare -a FLAVOR_TYPES=("nano" "tetra" "universal")
  9. if [[ ! -d "$IMAGEBUILDER_FOLDER" || "$PROFILE" == "" ]] || ! grep -q "$ARCHITECTURE" <<< "${ARCHITECTURE_TYPES[*]}" || ! grep -q "$FLAVOR" <<< "${FLAVOR_TYPES[*]}"; then
  10. echo "Run with \"builder.sh [ARCHITECTURE] [FLAVOR] [IMAGEBUILDER_FOLDER] [PROFILE]\""
  11. echo " ARCHITECTURE -> must be one of these values: mips, mipsel"
  12. echo " FLAVOR -> must be one of these values: nano, tetra, universal"
  13. echo " IMAGEBUILDER_FOLDER -> path to openwrt imagebuilder"
  14. echo " PROFILE -> profile for use in imagebuilder build"
  15. exit 1
  16. fi
  17. # the order in which the dependencies are installed and those that are removed is deliberate!
  18. # no rtl-sdr, no kmod-usb-net-*, no kmod-rtl8192cu, no kmod-usb-acm
  19. PACKAGES_NANO="iw at autossh base-files block-mount ca-certificates chat dnsmasq e2fsprogs ethtool firewall hostapd-utils ip6tables iperf3 iwinfo kmod-crypto-manager kmod-fs-ext4 kmod-fs-nfs kmod-fs-vfat kmod-gpio-button-hotplug kmod-ipt-offload kmod-leds-gpio kmod-ledtrig-default-on kmod-ledtrig-netdev kmod-ledtrig-timer kmod-mt76x2u kmod-nf-nathelper kmod-rt2800-usb kmod-rtl8187 kmod-scsi-generic kmod-usb-ohci kmod-usb-storage-extras kmod-usb-uhci kmod-usb2 libbz2-1.0 libcurl4 libelf1 libffi libgmp10 libiconv-full2 libintl libltdl7 libnet-1.2.x libnl200 libreadline8 libustream-mbedtls20150806 libxml2 logd macchanger mtd nano ncat netcat nginx openssh-client openssh-server openssh-sftp-server openssl-util php7-fpm php7-mod-hash php7-mod-json php7-mod-mbstring php7-mod-session php7-mod-sqlite3 ppp ppp-mod-pppoe procps-ng-pkill procps-ng-ps python-logging python-openssl python-sqlite3 ssmtp tcpdump-mini uci uclibcxx uclient-fetch urandom-seed urngd usb-modeswitch usbreset usbutils wget wireless-tools wpad busybox libatomic1 libstdcpp6 -wpad-basic -dropbear -swconfig -odhcpd-ipv6only -odhcp6c"
  20. # no rtl-sdr, no kmod-usb-net-*, no kmod-usb-serial-*, no kmod-rtl8192cu, no kmod-usb-acm, no kmod-usb-wdm, no kmod-lib-crc-itu-t
  21. PACKAGES_TETRA="iw at autossh base-files bash block-mount ca-certificates chat dnsmasq e2fsprogs ethtool firewall hostapd-utils ip6tables iwinfo kmod-crypto-manager kmod-fs-ext4 kmod-fs-nfs kmod-fs-vfat kmod-gpio-button-hotplug kmod-ipt-offload kmod-leds-gpio kmod-ledtrig-default-on kmod-ledtrig-netdev kmod-ledtrig-timer kmod-mt76x2u kmod-nf-nathelper kmod-rt2800-usb kmod-rtl8187 kmod-scsi-generic kmod-usb-ohci kmod-usb-storage-extras kmod-usb-uhci kmod-usb2 libbz2-1.0 libcurl4 libelf1 libffi libgdbm libgmp10 libiconv-full2 libltdl7 libnet-1.2.x libnl200 libustream-mbedtls20150806 libxml2 logd macchanger mtd nano ncat netcat nginx openssh-client openssh-server openssh-sftp-server openssl-util php7-fpm php7-mod-hash php7-mod-json php7-mod-mbstring php7-mod-session php7-mod-sqlite3 ppp ppp-mod-pppoe procps-ng-pkill procps-ng-ps python-logging python-openssl python-sqlite3 ssmtp tcpdump-mini uci uclibcxx uclient-fetch urandom-seed urngd usb-modeswitch usbreset usbutils wget wireless-tools wpad busybox libatomic1 libstdcpp6 -wpad-basic -dropbear -odhcp6c -odhcpd-ipv6only"
  22. # if you don't install a custom build of busybox you have to install fdisk
  23. # no rtl-sdr, no kmod-usb-net-*, no kmod-usb-serial-*, no kmod-rtl8192cu, no kmod-usb-acm, no kmod-usb-wdm, no kmod-lib-crc-itu-t, no ppp*, no python-*
  24. PACKAGES_UNIVERSAL="iw at autossh base-files bash block-mount ca-certificates chat dnsmasq e2fsprogs ethtool firewall hostapd-utils ip6tables iwinfo kmod-crypto-manager kmod-fs-ext4 kmod-fs-nfs kmod-fs-vfat kmod-gpio-button-hotplug kmod-ipt-offload kmod-leds-gpio kmod-ledtrig-default-on kmod-ledtrig-netdev kmod-ledtrig-timer kmod-mt76x2u kmod-nf-nathelper kmod-rt2800-usb kmod-rtl8187 kmod-scsi-generic kmod-usb-ohci kmod-usb-storage-extras kmod-usb-uhci kmod-usb2 libbz2-1.0 libcurl4 libelf1 libffi libgdbm libgmp10 libiconv-full2 libltdl7 libnet-1.2.x libnl200 libustream-mbedtls20150806 libxml2 logd macchanger mtd nano ncat netcat nginx openssh-client openssh-server openssh-sftp-server openssl-util php7-fpm php7-mod-hash php7-mod-json php7-mod-mbstring php7-mod-session php7-mod-sqlite3 procps-ng-pkill procps-ng-ps ssmtp tcpdump-mini uci uclibcxx uclient-fetch urandom-seed urngd usb-modeswitch usbreset usbutils wget wireless-tools wpad busybox libatomic1 libstdcpp6 -wpad-basic -dropbear -odhcpd-ipv6only -ppp -ppp-mod-pppoe"
  25. # add missing deps and custom busybox build
  26. declare -a FORCE_PACKAGES=("libubus20191227_2019-12-27-041c9d1c-1" "busybox_1.30.1-6")
  27. IMAGEBUILDER_FOLDER="$(realpath $IMAGEBUILDER_FOLDER)"
  28. TOOL_FOLDER="$(realpath $(dirname $0)/../tools)"
  29. BUILD_FOLDER="$(realpath $(dirname $0)/../build)"
  30. FW_FOLDER="$(realpath $(dirname $0)/../build/fw-base)"
  31. # steps
  32. check_deps () {
  33. echo "[*] Checking dependencies"
  34. echo "******************************"
  35. echo ""
  36. if [ ! -f "$FW_FOLDER/basefw.bin" ]; then
  37. echo "[!] Attention!"
  38. echo ""
  39. echo "File 'build/fw-base/basefw.bin' was not found."
  40. echo "You must download the original firmware version 2.7.0 and place it with the name basefw.bin in this path:"
  41. echo "$FW_FOLDER"
  42. echo ""
  43. exit 1
  44. fi
  45. if [ ! -f "$FW_FOLDER/basefw-mk7.bin" ] && [ "$ARCHITECTURE" == "mipsel" ]; then
  46. echo "[!] Attention!"
  47. echo ""
  48. echo "File 'build/fw-base/basefw-mk7.bin' was not found."
  49. echo "You must download the original MK7 firmware version 1.1.1 and place it with the name basefw-mk7.bin in this path:"
  50. echo "$FW_FOLDER"
  51. echo ""
  52. exit 1
  53. fi
  54. }
  55. prepare_builder () {
  56. echo "[*] Prepare builder"
  57. echo "******************************"
  58. echo ""
  59. PACKAGES_ARQ="${ARCHITECTURE}_24kc"
  60. DOWNLOAD_BASE_URL="https://github.com/xchwarze/wifi-pineapple-community/raw/main/packages/experimental"
  61. for TARGET in ${FORCE_PACKAGES[@]}; do
  62. PACKAGE_IPK="${TARGET}_${PACKAGES_ARQ}.ipk"
  63. PACKAGE_PATH="$IMAGEBUILDER_FOLDER/packages/$PACKAGE_IPK"
  64. if [ ! -f "$PACKAGE_PATH" ]; then
  65. echo "[+] Install: $TARGET"
  66. wget -q "$DOWNLOAD_BASE_URL/$PACKAGES_ARQ/$PACKAGE_IPK" -O "$PACKAGE_PATH"
  67. else
  68. echo "[+] Already exist: $TARGET"
  69. fi
  70. done
  71. echo "[+] Builder setup complete"
  72. echo ""
  73. }
  74. prepare_build () {
  75. echo "[*] Prepare build"
  76. echo "******************************"
  77. echo ""
  78. # clean
  79. rm -rf _basefw.* basefw.bin
  80. rm -rf "$BUILD_FOLDER/rootfs-base"
  81. rm -rf "$BUILD_FOLDER/rootfs"
  82. mkdir "$BUILD_FOLDER/release"
  83. # get target firmware
  84. # this work only with lastest binwalk version!
  85. if [[ "$FLAVOR" == "tetra" || "$FLAVOR" == "universal" ]]; then
  86. #echo "[+] Downloading TETRA firmware..."
  87. #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-tetra.bin -O basefw.bin
  88. echo "[+] Unpack firmware for get file system"
  89. binwalk basefw.bin -e
  90. binwalk _basefw.bin.extracted/sysupgrade-pineapple-tetra/root -e --preserve-symlinks
  91. mv _basefw.bin.extracted/sysupgrade-pineapple-tetra/_root.extracted/squashfs-root/ "$BUILD_FOLDER/rootfs-base"
  92. else
  93. #echo "[+] Downloading NANO firmware..."
  94. #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-nano.bin -O basefw.bin
  95. echo "[+] Unpack firmware for get file system"
  96. binwalk basefw.bin -e --preserve-symlinks
  97. mv _basefw.bin.extracted/squashfs-root/ "$BUILD_FOLDER/rootfs-base"
  98. fi
  99. rm -rf _basefw.* basefw.bin
  100. #sudo chmod +x "$TOOL_FOLDER/*.sh"
  101. echo "[+] Copying the original files"
  102. "$TOOL_FOLDER/copier.sh" "$TOOL_FOLDER/../lists/$FLAVOR.filelist" "$BUILD_FOLDER/rootfs-base" "$BUILD_FOLDER/rootfs"
  103. if [ $? -ne 0 ]; then
  104. echo "[!] An error occurred while copying the original files. Check the log for errors."
  105. exit 1
  106. fi
  107. # I'm deleting it because I don't use it anymore
  108. rm -rf "$BUILD_FOLDER/rootfs-base"
  109. if [[ "$ARCHITECTURE" == "mipsel" ]]; then
  110. #echo "[+] Downloading old MK7 firmware..."
  111. #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/1.1.1-mk7.bin -O basefw-mk7.bin
  112. echo "[+] Unpack mipsel firmware for get file system"
  113. binwalk basefw-mk7.bin -e --preserve-symlinks
  114. mv _basefw-mk7.bin.extracted/squashfs-root/ "$BUILD_FOLDER/rootfs-mk7-base"
  115. echo "[+] Copying the original mipsel files"
  116. "$TOOL_FOLDER/copier.sh" "$TOOL_FOLDER/../lists/mipsel-support.filelist" "$BUILD_FOLDER/rootfs-mk7-base" "$BUILD_FOLDER/rootfs" "true"
  117. if [ $? -ne 0 ]; then
  118. echo "[!] An error occurred while copying the original mipsel files. Check the log for errors."
  119. exit 1
  120. fi
  121. rm -rf "$BUILD_FOLDER/rootfs-mk7-base"
  122. fi
  123. echo "[+] Patch file system"
  124. "$TOOL_FOLDER/fs-patcher.sh" "$ARCHITECTURE" "$FLAVOR" "$BUILD_FOLDER/rootfs"
  125. if [ $? -ne 0 ]; then
  126. echo "[!] An error occurred during the execution of the process. Check the log for errors."
  127. exit 1
  128. fi
  129. echo ""
  130. }
  131. build () {
  132. echo "[*] Build"
  133. echo "******************************"
  134. echo ""
  135. # clean
  136. echo "[+] Clean last build data"
  137. #make clean
  138. rm -rf "$IMAGEBUILDER_FOLDER/tmp/"
  139. rm -rf "$IMAGEBUILDER_FOLDER/build_dir/target-*/root*"
  140. rm -rf "$IMAGEBUILDER_FOLDER/build_dir/target-*/json_*"
  141. rm -rf "$IMAGEBUILDER_FOLDER/bin/targets/*"
  142. # set selected packages
  143. echo "[+] Executing make"
  144. selected_packages="$PACKAGES_UNIVERSAL"
  145. if [[ "$FLAVOR" == "nano" ]];
  146. then
  147. selected_packages="$PACKAGES_NANO"
  148. elif [[ "$FLAVOR" == "tetra" ]];
  149. then
  150. selected_packages="$PACKAGES_TETRA"
  151. fi
  152. # build
  153. cd "$IMAGEBUILDER_FOLDER"
  154. make image PROFILE="$1" PACKAGES="$selected_packages" FILES="$BUILD_FOLDER/rootfs" BIN_DIR="$BUILD_FOLDER/release" > "$BUILD_FOLDER/release/make.log"
  155. if [ $? -ne 0 ]; then
  156. echo ""
  157. echo "[!] An error occurred in the build process. Check file release/make.log for more information."
  158. exit 1
  159. fi
  160. # add this second check for build process
  161. checkFwFileExist=$(ls "$BUILD_FOLDER/release"/*-sysupgrade.* 2>/dev/null | wc -l)
  162. if [ $checkFwFileExist -eq 0 ]; then
  163. echo ""
  164. echo "[!] OpenWRT finished the build process but no firmware was found. Check the release/make.log to see if the process was completed correctly."
  165. #exit 1
  166. fi
  167. echo ""
  168. }
  169. # implement this shitty logic
  170. echo "Wifi Pineapple Cloner - builder"
  171. echo "************************************** by DSR!"
  172. echo ""
  173. check_deps
  174. prepare_builder
  175. prepare_build
  176. build "$PROFILE"
  177. echo "[*] Firmware folder: $BUILD_FOLDER/release"
  178. echo "******************************"
  179. ls -l "$BUILD_FOLDER/release"
  180. echo ""