builder.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. # dependencies installed, uninstalled and the order in which they are installed is for a reason!
  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. # steps
  31. prepare_builder () {
  32. echo "[*] Prepare builder"
  33. echo "******************************"
  34. echo ""
  35. PACKAGES_ARQ="${ARCHITECTURE}_24kc"
  36. DOWNLOAD_BASE_URL="https://github.com/xchwarze/wifi-pineapple-community/raw/main/packages/experimental"
  37. for TARGET in ${FORCE_PACKAGES[@]}; do
  38. PACKAGE_IPK="${TARGET}_${PACKAGES_ARQ}.ipk"
  39. PACKAGE_PATH="$IMAGEBUILDER_FOLDER/packages/$PACKAGE_IPK"
  40. if [ ! -f "$PACKAGE_PATH" ]; then
  41. echo "[+] Install: $TARGET"
  42. wget -q "$DOWNLOAD_BASE_URL/$PACKAGES_ARQ/$PACKAGE_IPK" -O "$PACKAGE_PATH"
  43. else
  44. echo "[+] Already exist: $TARGET"
  45. fi
  46. done
  47. echo "[+] Builder setup complete"
  48. echo ""
  49. }
  50. prepare_build () {
  51. echo "[*] Prepare build"
  52. echo "******************************"
  53. echo ""
  54. # clean
  55. rm -rf _basefw.* basefw.bin
  56. rm -rf "$BUILD_FOLDER"
  57. mkdir -p "$BUILD_FOLDER/release"
  58. # get target firmware
  59. # this work only with lastest binwalk version!
  60. if [[ "$FLAVOR" == "tetra" || "$FLAVOR" == "universal" ]]; then
  61. echo "[+] Downloading TETRA firmware..."
  62. wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-tetra.bin -O basefw.bin
  63. echo "[+] Unpack firmware for get file system"
  64. binwalk basefw.bin -e
  65. binwalk _basefw.bin.extracted/sysupgrade-pineapple-tetra/root -e --preserve-symlinks
  66. mv _basefw.bin.extracted/sysupgrade-pineapple-tetra/_root.extracted/squashfs-root/ "$BUILD_FOLDER/rootfs-base"
  67. else
  68. echo "[+] Downloading NANO firmware..."
  69. wget -q https://github.com/xchwarze/wifi-pineapple-community/raw/main/firmwares/2.7.0-nano.bin -O basefw.bin
  70. echo "[+] Unpack firmware for get file system"
  71. binwalk basefw.bin -e --preserve-symlinks
  72. mv _basefw.bin.extracted/squashfs-root/ "$BUILD_FOLDER/rootfs-base"
  73. fi
  74. rm -rf _basefw.* basefw.bin
  75. #sudo chmod +x "$TOOL_FOLDER/*.sh"
  76. echo "[+] Copying the original files"
  77. "$TOOL_FOLDER/copier.sh" "$TOOL_FOLDER/../lists/$FLAVOR.filelist" "$BUILD_FOLDER/rootfs-base" "$BUILD_FOLDER/rootfs"
  78. if [ $? -ne 0 ]; then
  79. echo "[!] An error occurred while copying the original files. Check the log for errors."
  80. exit 1
  81. fi
  82. echo "[+] Patch file system"
  83. "$TOOL_FOLDER/fs-patcher.sh" "$ARCHITECTURE" "$FLAVOR" "$BUILD_FOLDER/rootfs"
  84. if [ $? -ne 0 ]; then
  85. echo "[!] An error occurred during the execution of the process. Check the log for errors."
  86. exit 1
  87. fi
  88. rm -rf "$BUILD_FOLDER/rootfs-base"
  89. echo ""
  90. }
  91. build () {
  92. echo "[*] Build"
  93. echo "******************************"
  94. echo ""
  95. # clean
  96. echo "[+] Clean last build data"
  97. #make clean
  98. rm -rf "$IMAGEBUILDER_FOLDER/tmp/"
  99. rm -rf "$IMAGEBUILDER_FOLDER/build_dir/target-*/root*"
  100. rm -rf "$IMAGEBUILDER_FOLDER/build_dir/target-*/json_*"
  101. rm -rf "$IMAGEBUILDER_FOLDER/bin/targets/*"
  102. # set selected packages
  103. echo "[+] Executing make"
  104. selected_packages="$PACKAGES_UNIVERSAL"
  105. if [[ "$FLAVOR" == "nano" ]];
  106. then
  107. selected_packages="$PACKAGES_NANO"
  108. elif [[ "$FLAVOR" == "tetra" ]];
  109. then
  110. selected_packages="$PACKAGES_TETRA"
  111. fi
  112. # build
  113. cd "$IMAGEBUILDER_FOLDER"
  114. make image PROFILE="$1" PACKAGES="$selected_packages" FILES="$BUILD_FOLDER/rootfs" BIN_DIR="$BUILD_FOLDER/release" > "$BUILD_FOLDER/release/make.log"
  115. if [ $? -ne 0 ]; then
  116. echo ""
  117. echo "[!] An error occurred in the build process. Check file release/make.log for more information."
  118. exit 1
  119. fi
  120. # add this second check for build process
  121. checkFwFileExist=$(ls "$BUILD_FOLDER/release"/*-sysupgrade.* 2>/dev/null | wc -l)
  122. if [ $checkFwFileExist -eq 0 ]; then
  123. echo ""
  124. echo "[!] OpenWRT finished the build process but no firmware was found. Check the release/make.log to see if the process was completed correctly."
  125. #exit 1
  126. fi
  127. echo ""
  128. }
  129. # implement this shitty logic
  130. echo "Wifi Pineapple Cloner - builder"
  131. echo "************************************** by DSR!"
  132. echo ""
  133. prepare_builder
  134. prepare_build
  135. build "$PROFILE"
  136. echo "[*] Firmware folder: $BUILD_FOLDER/release"
  137. echo "******************************"
  138. ls -l "$BUILD_FOLDER/release"
  139. echo ""