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. if [ ! -f "$FW_FOLDER/basefw.bin" ]; then
  36. VARIANT=$([[ "$FLAVOR" == "nano" ]] && echo "NANO" || echo "TETRA")
  37. echo "[!] Attention!"
  38. echo ""
  39. echo "File 'build/fw-base/basefw.bin' was not found."
  40. echo "You must download the original $VARIANT 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. echo " [+] Check completed"
  55. echo ""
  56. }
  57. prepare_builder () {
  58. echo "[*] Prepare builder"
  59. echo "******************************"
  60. PACKAGES_ARQ="${ARCHITECTURE}_24kc"
  61. DOWNLOAD_BASE_URL="https://github.com/xchwarze/wifi-pineapple-community/raw/main/packages/experimental"
  62. for TARGET in ${FORCE_PACKAGES[@]}; do
  63. PACKAGE_IPK="${TARGET}_${PACKAGES_ARQ}.ipk"
  64. PACKAGE_PATH="$IMAGEBUILDER_FOLDER/packages/$PACKAGE_IPK"
  65. if [ ! -f "$PACKAGE_PATH" ]; then
  66. echo " [+] Install: $TARGET"
  67. wget -q "$DOWNLOAD_BASE_URL/$PACKAGES_ARQ/$PACKAGE_IPK" -O "$PACKAGE_PATH"
  68. else
  69. echo " [+] Already exist: $TARGET"
  70. fi
  71. done
  72. echo " [+] Builder setup complete"
  73. echo ""
  74. }
  75. prepare_build () {
  76. echo "[*] Prepare build"
  77. echo "******************************"
  78. # clean
  79. rm -rf "$FW_FOLDER/_basefw.*"
  80. rm -rf "$BUILD_FOLDER/rootfs-base"
  81. rm -rf "$BUILD_FOLDER/rootfs"
  82. rm -rf "$BUILD_FOLDER/release"
  83. mkdir "$BUILD_FOLDER/release"
  84. # get target firmware
  85. # this work only with lastest binwalk version!
  86. if [[ "$FLAVOR" == "tetra" || "$FLAVOR" == "universal" ]]; then
  87. #echo " [+] Downloading TETRA firmware..."
  88. #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-tetra.bin -O "$FW_FOLDER/basefw.bin"
  89. echo " [+] Unpack firmware for get file system"
  90. binwalk "$FW_FOLDER/basefw.bin" -e
  91. binwalk "$FW_FOLDER/_basefw.bin.extracted/sysupgrade-pineapple-tetra/root" -e --preserve-symlinks
  92. mv "$FW_FOLDER/_basefw.bin.extracted/sysupgrade-pineapple-tetra/_root.extracted/squashfs-root/" "$BUILD_FOLDER/rootfs-base"
  93. else
  94. #echo " [+] Downloading NANO firmware..."
  95. #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-nano.bin -O "$FW_FOLDER/basefw.bin"
  96. echo " [+] Unpack firmware for get file system"
  97. binwalk "$FW_FOLDER/basefw.bin" -e --preserve-symlinks
  98. mv "$FW_FOLDER/_basefw.bin.extracted/squashfs-root/" "$BUILD_FOLDER/rootfs-base"
  99. fi
  100. echo " [+] Copying the original files"
  101. "$TOOL_FOLDER/copier.sh" "$TOOL_FOLDER/../lists/$FLAVOR.filelist" "$BUILD_FOLDER/rootfs-base" "$BUILD_FOLDER/rootfs"
  102. if [ $? -ne 0 ]; then
  103. echo " [!] An error occurred while copying the original files. Check the log for errors."
  104. exit 1
  105. fi
  106. rm -rf "$BUILD_FOLDER/rootfs-base"
  107. rm -rf "$FW_FOLDER"/_basefw.*
  108. if [[ "$ARCHITECTURE" == "mipsel" ]]; then
  109. #echo " [+] Downloading old MK7 firmware..."
  110. #wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/1.1.1-mk7.bin -O "$FW_FOLDER/basefw-mk7.bin"
  111. echo " [+] Unpack mipsel firmware for get file system"
  112. binwalk "$FW_FOLDER/basefw-mk7.bin" -e --preserve-symlinks
  113. mv "$FW_FOLDER/_basefw-mk7.bin.extracted/squashfs-root/" "$BUILD_FOLDER/rootfs-mk7-base"
  114. echo " [+] Copying the original mipsel files"
  115. "$TOOL_FOLDER/copier.sh" "$TOOL_FOLDER/../lists/mipsel-support.filelist" "$BUILD_FOLDER/rootfs-mk7-base" "$BUILD_FOLDER/rootfs" "true"
  116. if [ $? -ne 0 ]; then
  117. echo " [!] An error occurred while copying the original mipsel files. Check the log for errors."
  118. exit 1
  119. fi
  120. rm -rf "$BUILD_FOLDER/rootfs-mk7-base"
  121. rm -rf "$FW_FOLDER"/_basefw-mk7.*
  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. # clean
  135. echo " [+] Clean last build data"
  136. #make clean
  137. rm -rf "$IMAGEBUILDER_FOLDER/tmp/"
  138. rm -rf "$IMAGEBUILDER_FOLDER/build_dir/target-*/root*"
  139. rm -rf "$IMAGEBUILDER_FOLDER/build_dir/target-*/json_*"
  140. rm -rf "$IMAGEBUILDER_FOLDER/bin/targets/*"
  141. # set selected packages
  142. echo " [+] Executing make"
  143. selected_packages="$PACKAGES_UNIVERSAL"
  144. if [[ "$FLAVOR" == "nano" ]];
  145. then
  146. selected_packages="$PACKAGES_NANO"
  147. elif [[ "$FLAVOR" == "tetra" ]];
  148. then
  149. selected_packages="$PACKAGES_TETRA"
  150. fi
  151. # build
  152. cd "$IMAGEBUILDER_FOLDER"
  153. make image PROFILE="$1" PACKAGES="$selected_packages" FILES="$BUILD_FOLDER/rootfs" BIN_DIR="$BUILD_FOLDER/release" > "$BUILD_FOLDER/release/make.log"
  154. if [ $? -ne 0 ]; then
  155. echo ""
  156. echo " [!] An error occurred in the build process. Check file release/make.log for more information."
  157. exit 1
  158. fi
  159. # add this second check for build process
  160. checkFwFileExist=$(ls "$BUILD_FOLDER/release"/*-sysupgrade.* 2>/dev/null | wc -l)
  161. if [ $checkFwFileExist -eq 0 ]; then
  162. echo ""
  163. echo " [!] OpenWRT finished the build process but no firmware was found. Check the release/make.log to see if the process was completed correctly."
  164. #exit 1
  165. fi
  166. echo ""
  167. }
  168. # implement this shitty logic
  169. echo "Wifi Pineapple Cloner - builder"
  170. echo "************************************** by DSR!"
  171. echo ""
  172. check_deps
  173. prepare_builder
  174. prepare_build
  175. build "$PROFILE"
  176. echo "[*] Firmware folder: $BUILD_FOLDER/release"
  177. echo "******************************"
  178. ls -l "$BUILD_FOLDER/release"
  179. echo ""