openwrtbuilder 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright 2022-23 Bryan C. Roessler
  4. #
  5. # Build and deploy OpenWRT images
  6. #
  7. # Apache 2.0 License
  8. # Set default release
  9. : "${RELEASE:="22.03.3"}"
  10. printHelp() {
  11. debug "${FUNCNAME[0]}"
  12. cat <<-'EOF'
  13. Build and deploy OpenWRT images
  14. USAGE:
  15. openwrtbuilder [OPTION [VALUE]] -p PROFILE [-p PROFILE2]...
  16. OPTIONS
  17. --profile, -p PROFILE
  18. --info, -i (print profile info)
  19. --list-profiles, -l
  20. --release, --version, -r, -v RELEASE ("snapshot", "22.03.3")
  21. --buildroot, -b PATH
  22. --ssh-upgrade HOST
  23. Example: root@192.168.1.1
  24. --ssh-backup SSH_PATH
  25. (Enabled by default for --ssh-upgrade)
  26. --flash, -f DEVICE
  27. Example: /dev/sdX
  28. --reset
  29. Cleanup all source and output files
  30. --debug, -d
  31. --help, -h
  32. EOF
  33. }
  34. init() {
  35. debug "${FUNCNAME[0]}"
  36. declare -g ID RPM_MGR SCRIPTDIR
  37. debug || echo "To enable debugging output, use --debug or -d"
  38. # Save the script directory
  39. SCRIPTDIR="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit $? ; pwd -P)"
  40. if [[ -e "/etc/os-release" ]]; then
  41. source "/etc/os-release"
  42. else
  43. err "/etc/os-release not found"
  44. err "Your OS is unsupported"
  45. printHelp
  46. exit 1
  47. fi
  48. debug "Detected host platform: $ID"
  49. # normalize distro ID
  50. case "$ID" in
  51. debian|arch)
  52. ;;
  53. centos|fedora)
  54. if hash dnf &>/dev/null; then
  55. RPM_MGR="dnf"
  56. elif hash yum &>/dev/null; then
  57. RPM_MGR="yum"
  58. fi
  59. ;;
  60. rhel)
  61. ID="centos"
  62. ;;
  63. linuxmint|neon|*ubuntu*)
  64. ID="ubuntu"
  65. ;;
  66. *suse*)
  67. ID="suse"
  68. ;;
  69. raspbian)
  70. ID="debian"
  71. ;;
  72. *)
  73. echo "Autodetecting distro, this may be unreliable"
  74. if hash dnf &>/dev/null; then
  75. ID="fedora"
  76. RPM_MGR="dnf"
  77. elif hash yum &>/dev/null; then
  78. ID="centos"
  79. RPM_MGR="yum"
  80. elif hash apt &>/dev/null; then
  81. ID="ubuntu"
  82. elif hash pacman &>/dev/null; then
  83. ID="arch"
  84. else
  85. return 1
  86. fi
  87. ;;
  88. esac
  89. debug "Using host platform: $ID"
  90. # Set distro-specific functions
  91. case "$ID" in
  92. fedora|centos)
  93. pkg_install(){ sudo "$RPM_MGR" install -y "$@"; }
  94. ;;
  95. debian|ubuntu)
  96. pkg_install(){ sudo apt-get install -y -q0 "$@"; }
  97. ;;
  98. suse)
  99. pkg_install(){ sudo zypper --non-interactive -q install --force --no-confirm "$@"; }
  100. ;;
  101. arch)
  102. pkg_install(){ sudo pacman -S --noconfirm --needed "$@"; }
  103. ;;
  104. esac
  105. }
  106. readInput() {
  107. debug "${FUNCNAME[0]}"
  108. unset RESET
  109. declare -ga PROFILES
  110. declare -g PROFILE_INFO
  111. declare long_opts
  112. long_opts='release:,version:,profile:,info:,list-profiles,buildroot:,'
  113. long_opts+='source,ssh-upgrade:,ssh-backup:,flash:,reset,debug,help'
  114. if _input=$(getopt -o +r:v:p:i:lb:sf:dh -l $long_opts -- "$@"); then
  115. eval set -- "$_input"
  116. while true; do
  117. case "$1" in
  118. --release|-r|--version|-v)
  119. shift && declare -g USER_RELEASE="$1"
  120. ;;
  121. --profile|-p)
  122. shift && PROFILES+=("$1")
  123. ;;
  124. --info|-i)
  125. PROFILE_INFO=1
  126. ;;
  127. --list-profiles|-l)
  128. listProfiles && exit $?
  129. ;;
  130. --buildroot|-b)
  131. shift && BUILDROOT="$1"
  132. ;;
  133. --source|-s)
  134. FROM_SOURCE=1
  135. ;;
  136. --ssh-upgrade)
  137. shift && SSH_UPGRADE_PATH="$1"
  138. ;;
  139. --ssh-backup)
  140. shift && SSH_BACKUP_PATH="$1"
  141. ;;
  142. --flash|-f)
  143. shift && FLASH_DEV="$1"
  144. ;;
  145. --reset)
  146. RESET=1
  147. ;;
  148. --debug|-d)
  149. echo "Debugging on"
  150. DEBUG=1
  151. ;;
  152. --help|-h)
  153. printHelp && exit 0
  154. ;;
  155. --)
  156. shift
  157. break
  158. ;;
  159. esac
  160. shift
  161. done
  162. else
  163. echo "Incorrect options provided"
  164. printHelp && exit 1
  165. fi
  166. }
  167. listProfiles() {
  168. debug "${FUNCNAME[0]}"
  169. grep "declare -Ag" "$PFILE" | cut -d" " -f3
  170. }
  171. installDependencies() {
  172. debug "${FUNCNAME[0]}"
  173. declare -a pkg_list
  174. # TODO please contribute your platform here
  175. if (( FROM_SOURCE )); then
  176. # For building from source with make
  177. # https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem
  178. case "$ID" in
  179. fedora|centos)
  180. pkg_list+=(
  181. "bash-completion"
  182. "bzip2"
  183. "gcc"
  184. "gcc-c++"
  185. "git"
  186. "make"
  187. "ncurses-devel"
  188. "patch"
  189. "rsync"
  190. "tar"
  191. "unzip"
  192. "wget"
  193. "which"
  194. "diffutils"
  195. "python2"
  196. "python3"
  197. "perl-base"
  198. "perl-Data-Dumper"
  199. "perl-File-Compare"
  200. "perl-File-Copy"
  201. "perl-FindBin"
  202. "perl-Thread-Queue"
  203. )
  204. ;;
  205. debian|ubuntu)
  206. pkg_list+=(
  207. "build-essential"
  208. "clang"
  209. "flex"
  210. "g++"
  211. "gawk"
  212. "gcc-multilib"
  213. "gettext"
  214. "git"
  215. "libncurses5-dev"
  216. "libssl-dev"
  217. "python3-distutils"
  218. "rsync"
  219. "unzip"
  220. "zlib1g-dev"
  221. "file"
  222. "wget"
  223. )
  224. ;;
  225. arch)
  226. pkg_list+=(
  227. "base-devel"
  228. "autoconf"
  229. "automake"
  230. "bash"
  231. "binutils"
  232. "bison"
  233. "bzip2"
  234. "fakeroot"
  235. "file"
  236. "findutils"
  237. "flex"
  238. "gawk"
  239. "gcc"
  240. "gettext"
  241. "git"
  242. "grep"
  243. "groff"
  244. "gzip"
  245. "libelf"
  246. "libtool"
  247. "libxslt"
  248. "m4"
  249. "make"
  250. "ncurses"
  251. "openssl"
  252. "patch"
  253. "pkgconf"
  254. "python"
  255. "rsync"
  256. "sed"
  257. "texinfo"
  258. "time"
  259. "unzip"
  260. "util-linux"
  261. "wget"
  262. "which"
  263. "zlib"
  264. )
  265. ;;
  266. esac
  267. else
  268. # For Imagebuilder
  269. case "$ID" in
  270. fedora|centos)
  271. pkg_list+=(
  272. "@c-development"
  273. "@development-tools"
  274. "@development-libs"
  275. "perl-FindBin"
  276. "zlib-static"
  277. "elfutils-libelf-devel"
  278. "gawk"
  279. "unzip"
  280. "file"
  281. "wget"
  282. "python3"
  283. "python2"
  284. "axel"
  285. )
  286. ;;
  287. debian|ubuntu)
  288. pkg_list+=(
  289. "build-essential"
  290. "libncurses5-dev"
  291. "libncursesw5-dev"
  292. "zlib1g-dev"
  293. "gawk"
  294. "git"
  295. "gettext"
  296. "libssl-dev"
  297. "xsltproc"
  298. "wget"
  299. "unzip"
  300. "python"
  301. "axel"
  302. )
  303. ;;
  304. esac
  305. fi
  306. pkg_install "${pkg_list[@]}"
  307. }
  308. getImageBuilder() {
  309. debug "${FUNCNAME[0]}"
  310. declare dl_tool checksum
  311. if [[ -f "$IB_ARCHIVE" ]]; then
  312. echo "Image Builder $IB_ARCHIVE exists"
  313. if askOk "Redownload Image Builder archive?"; then
  314. rm -f "$IB_ARCHIVE"
  315. else
  316. return 0
  317. fi
  318. fi
  319. if hash axel &>/dev/null; then
  320. dl_tool="axel"
  321. elif hash curl &>/dev/null; then
  322. dl_tool="curl"
  323. else
  324. echo "Downloading the Image Builder requires axel or curl!"
  325. return 1
  326. fi
  327. echo "Downloading Image Builder archive using $dl_tool"
  328. debug "$dl_tool -o $IB_ARCHIVE $IB_URL"
  329. if ! "$dl_tool" -o "$IB_ARCHIVE" "$IB_URL"; then
  330. echo "Could not download Image Builder archive"
  331. return 1
  332. fi
  333. if [[ ! -f "$IB_ARCHIVE" ]]; then
  334. echo "Archive missing"
  335. return 1
  336. fi
  337. if hash sha256sum &>/dev/null; then
  338. debug "Verifying checksums"
  339. if [[ -f $SHA256_FILE ]] && askOk "$SHA256_FILE exists. Re-download?"; then
  340. if ! $dl_tool -o "$SHA256_FILE" "$SHA256_URL"; then
  341. debug "Failed to download checksum"
  342. fi
  343. elif ! $dl_tool -o "$SHA256_FILE" "$SHA256_URL"; then
  344. debug "Failed to download checksum"
  345. fi
  346. checksum=$(grep "${IB_ARCHIVE##*/}" "$SHA256_FILE" | cut -f1 -d' ')
  347. debug "checksum: $checksum"
  348. echo "$checksum ${IB_ARCHIVE##*/}" | sha256sum --check --status
  349. debug "checksum return code: $?"
  350. fi
  351. echo "Extracting Image Builder archive"
  352. [[ ! -d "$BUILDDIR" ]] && mkdir -p "$BUILDDIR"
  353. debug "tar -xf $IB_ARCHIVE -C $BUILDDIR --strip-components 1"
  354. if ! tar -xf "$IB_ARCHIVE" -C "$BUILDDIR" --strip-components 1; then
  355. echo "Extraction failed"
  356. return 1
  357. fi
  358. }
  359. addRepos() {
  360. debug "${FUNCNAME[0]}"
  361. if [[ -v P_ARR[repo] ]]; then
  362. if ! grep -q "${P_ARR[repo]}" "$BUILDDIR/repositories.conf"; then
  363. echo "${P_ARR[repo]}" >> "$BUILDDIR/repositories.conf"
  364. fi
  365. sed -i '/option check_signature/d' "$BUILDDIR/repositories.conf"
  366. fi
  367. }
  368. sshBackup() {
  369. debug "${FUNCNAME[0]}"
  370. local _date _hostname _backup_fname
  371. [[ -d "$FILESDIR" ]] || mkdir -p "$FILESDIR"
  372. printf -v _date '%(%Y-%m-%d-%H-%M-%S)T'
  373. _hostname=$(ssh -qt "$SSH_BACKUP_PATH" echo -n \$HOSTNAME)
  374. _backup_fname="backup-$_hostname-$_date.tar.gz"
  375. # Make backup archive on remote
  376. debug "ssh -t $SSH_BACKUP_PATH sysupgrade -b /tmp/$_backup_fname"
  377. if ! ssh -t "$SSH_BACKUP_PATH" "sysupgrade -b /tmp/$_backup_fname"; then
  378. echo "SSH backup failed"
  379. exit 1
  380. fi
  381. # Move backup archive locally
  382. debug "rsync -avz --remove-source-files $SSH_BACKUP_PATH:/tmp/$_backup_fname $BUILDDIR/"
  383. if ! rsync -avz --remove-source-files \
  384. "$SSH_BACKUP_PATH":"/tmp/$_backup_fname" "$BUILDDIR/"; then
  385. echo "Could not copy SSH backup"
  386. exit 1
  387. fi
  388. # Extract backup archive
  389. debug "tar -C $FILESDIR -xzf $BUILDDIR/$_backup_fname"
  390. if ! tar -C "$FILESDIR" -xzf "$BUILDDIR/$_backup_fname"; then
  391. echo "Could not extract SSH backup"
  392. exit 1
  393. fi
  394. rm "$BUILDDIR/$_backup_fname"
  395. }
  396. makeImage() {
  397. debug "${FUNCNAME[0]}"
  398. # Reuse the existing output
  399. if [[ -d "$THIS_BINDIR" ]]; then
  400. if askOk "$THIS_BINDIR exists. Rebuild?"; then
  401. rm -rf "$THIS_BINDIR"
  402. else
  403. return 0
  404. fi
  405. fi
  406. [[ -d "$BUILDDIR" ]] || mkdir -p "$BUILDDIR"
  407. if ! make image \
  408. BIN_DIR="$THIS_BINDIR" \
  409. PROFILE="${P_ARR[profile]}" \
  410. PACKAGES="${P_ARR[packages]}" \
  411. FILES="${FILESDIR}" \
  412. --directory="$BUILDDIR" \
  413. --jobs="$(nproc)" \
  414. > "$BUILDDIR/make.log"; then
  415. echo "Make image failed!"
  416. exit 1
  417. fi
  418. }
  419. flashImage() {
  420. debug "${FUNCNAME[0]}"
  421. declare img img_gz partitions
  422. if [[ ! -e "$FLASH_DEV" ]]; then
  423. echo "The device specified by --flash could not be found"
  424. exit 1
  425. fi
  426. # TODO Roughly choose the correct image
  427. if [[ -f "$FACTORYIMGGZ" ]]; then
  428. img_gz="$FACTORYIMGGZ"
  429. img="$FACTORYIMG"
  430. elif [[ -f "$SYSUPGRADEIMGGZ" ]]; then
  431. img_gz="$SYSUPGRADEIMGGZ"
  432. img="$SYSUPGRADEIMG"
  433. else
  434. return 1
  435. fi
  436. debug "$img_gz $img"
  437. debug "gunzip -qfk $img_gz"
  438. gunzip -qfk "$img_gz"
  439. echo "Unmounting target device $FLASH_DEV partitions"
  440. partitions=( "$FLASH_DEV"?* )
  441. debug "umount ${partitions[*]}"
  442. sudo umount "${partitions[@]}"
  443. debug "sudo dd if=\"$img\" of=\"$FLASH_DEV\" bs=2M conv=fsync"
  444. if sudo dd if="$img" of="$FLASH_DEV" bs=2M conv=fsync; then
  445. sync
  446. echo "Image flashed sucessfully!"
  447. else
  448. echo "dd failed!"
  449. exit 1
  450. fi
  451. }
  452. sshUpgrade() {
  453. debug "${FUNCNAME[0]}"
  454. echo "Copying '$SYSUPGRADEIMGGZ' to $SSH_UPGRADE_PATH/tmp/"
  455. debug "scp \"$SYSUPGRADEIMGGZ\" \"$SSH_UPGRADE_PATH\":\"/tmp/$SYSUPGRADEIMGGZFNAME\""
  456. if ! scp "$SYSUPGRADEIMGGZ" "$SSH_UPGRADE_PATH":"/tmp/$SYSUPGRADEIMGGZFNAME"; then
  457. echo "Could not access the --ssh-upgrade PATH"
  458. exit 1
  459. fi
  460. echo "Executing remote sysupgrade"
  461. debug "ssh \"$SSH_UPGRADE_PATH\" \"sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME\""
  462. # shellcheck disable=SC2029
  463. ssh "$SSH_UPGRADE_PATH" "sysupgrade -F /tmp/$SYSUPGRADEIMGGZFNAME"
  464. }
  465. fromSource() {
  466. debug "${FUNCNAME[0]}"
  467. declare src_url="https://github.com/openwrt/openwrt.git"
  468. declare -a pkg_list
  469. echo "Building from source is under development"
  470. if [[ ! -d "$GITSRCDIR" ]]; then
  471. mkdir -p "$GITSRCDIR"
  472. git clone "$src_url" "$GITSRCDIR"
  473. fi
  474. pushd "$GITSRCDIR" &>/dev/null || return 1
  475. if [[ ${P_ARR[release]} == "snapshot" ]]; then
  476. git checkout master
  477. else
  478. git checkout "v$RELEASE"
  479. fi
  480. # Update packages
  481. ./scripts/feeds update -a &&
  482. ./scripts/feeds install -a
  483. # Grab the release seed config
  484. if [[ -f "$SEED_FILE" ]]; then
  485. echo "$SEED_FILE already exists"
  486. if askOk "Replace?"; then
  487. if ! curl -so "$SEED_FILE" "$SEED_URL"; then
  488. echo "Could not obtain seed config"
  489. fi
  490. fi
  491. else
  492. echo "Reusing existing $SEED_FILE"
  493. fi
  494. # Override default .config seed with profile packages
  495. for package in ${P_ARR[packages]}; do
  496. if [[ $package == -* ]]; then
  497. echo "CONFIG_PACKAGE_${package#-}=n" >> "$SEED_FILE"
  498. else
  499. echo "CONFIG_PACKAGE_$package=y" >> "$SEED_FILE"
  500. fi
  501. done
  502. make defconfig # normalize .config and remove dupes
  503. # Only compile our target
  504. # Causes a "configuration is out of sync" error
  505. echo "CONFIG_TARGET_MULTI_PROFILE=n" >> "$SEED_FILE"
  506. sed -i '/CONFIG_TARGET_DEVICE_/d' "$SEED_FILE"
  507. echo "CONFIG_TARGET_DEVICE_${P_ARR[target]//\//_}_DEVICE_${P_ARR[profile]}=y" >> "$SEED_FILE"
  508. # output to bindir instead of builddir
  509. echo "CONFIG_BINARY_FOLDER=\"$THIS_BINDIR\"" >> "$SEED_FILE"
  510. make targetclean
  511. make download &&
  512. make -j"$(nproc)" world
  513. popd &>/dev/null || return 1
  514. exit # TODO exit here for fromSource() testing
  515. }
  516. debug() { (( DEBUG )) && echo "Debug: $*"; }
  517. askOk() {
  518. local _response
  519. read -r -p "$* [y/N]" _response
  520. _response=${_response,,}
  521. [[ "$_response" =~ ^(yes|y)$ ]]
  522. }
  523. resetAll() {
  524. debug "${FUNCNAME[0]}"
  525. askOk "Remove $SRCDIR and $BINDIR?" || exit $?
  526. debug "rm -rf $SRCDIR $BINDIR"
  527. rm -rf "$SRCDIR" "$BINDIR"
  528. }
  529. resetProfile() {
  530. debug "${FUNCNAME[0]}"
  531. askOk "Remove $BUILDDIR and $THIS_BINDIR?" || exit $?
  532. debug "rm -rf $BUILDDIR $THIS_BINDIR"
  533. rm -rf "$BUILDDIR" "$THIS_BINDIR"
  534. }
  535. loadProfiles() {
  536. debug "${FUNCNAME[0]}"
  537. declare -g PFILE
  538. # https://stackoverflow.com/a/4774063
  539. PFILE="$SCRIPTDIR/profiles"
  540. # shellcheck source=./profiles
  541. ! source "$PFILE" && echo "profiles file missing!" && return 1
  542. }
  543. main() {
  544. debug "${FUNCNAME[0]}"
  545. init
  546. loadProfiles
  547. readInput "$@"
  548. # Fallback to SCRIPTDIR if BUILDROOT has not been set
  549. declare -g BUILDROOT="${BUILDROOT:=$SCRIPTDIR}"
  550. [[ $BUILDROOT == "/" ]] && echo "Invalid --buildroot" && exit 1
  551. declare -g FILESDIR="${FILESDIR:=$BUILDROOT/src/files}"
  552. declare -g SRCDIR="$BUILDROOT/src" # input/build
  553. declare -g BINDIR="$BUILDROOT/bin" # output
  554. declare -g GITSRCDIR="$SRCDIR/openwrt"
  555. for dir in "$SRCDIR" "$BINDIR"; do
  556. [[ -d "$dir" ]] || mkdir -p "$dir"
  557. done
  558. # Allow --reset without a profile
  559. if [[ ${#PROFILES} -lt 1 ]]; then
  560. if (( RESET )); then
  561. resetAll
  562. exit
  563. else
  564. echo "No profile supplied" && return 1
  565. fi
  566. fi
  567. installDependencies
  568. for profile in "${PROFILES[@]}"; do
  569. debug "Starting profile: $profile"
  570. if [[ ! ${!profile@a} = A ]]; then
  571. echo "Profile '$profile' does not exist"
  572. return 1
  573. fi
  574. # Store profile settings in P_ARR
  575. declare -gn P_ARR="$profile"
  576. # release precedence: user input>profile>env>hardcode
  577. declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}"
  578. declare -g BUILDDIR="$SRCDIR/${P_ARR[profile]}-$RELEASE"
  579. declare -g IB_ARCHIVE="$SRCDIR/${P_ARR[profile]}-$RELEASE.tar.xz"
  580. declare -g FILESYSTEM="${P_ARR[filesystem]:="squashfs"}"
  581. declare -g THIS_BINDIR="$BINDIR/${P_ARR[profile]}-$RELEASE"
  582. if [[ "$RELEASE" == "snapshot" ]]; then
  583. declare url_prefix="https://downloads.openwrt.org/snapshots/targets/${P_ARR[target]}"
  584. declare url_filename="openwrt-imagebuilder-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
  585. declare img_prefix="$BUILDDIR/openwrt-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
  586. else
  587. declare url_prefix="https://downloads.openwrt.org/releases/$RELEASE/targets/${P_ARR[target]}"
  588. declare url_filename="openwrt-imagebuilder-$RELEASE-${P_ARR[target]//\//-}.Linux-x86_64.tar.xz"
  589. declare img_prefix="$BUILDDIR/openwrt-$RELEASE-${P_ARR[target]//\//-}-${P_ARR[profile]}-$FILESYSTEM"
  590. fi
  591. declare -g IB_URL="$url_prefix/$url_filename"
  592. declare -g SHA256_URL="$url_prefix/sha256sums"
  593. declare -g SHA256_FILE="$BUILDDIR/sha256sums"
  594. declare -g SEED_URL="$url_prefix/config.buildinfo"
  595. declare -g SEED_FILE="$GITSRCDIR/.config"
  596. declare -g FACTORYIMG="$img_prefix-factory.img"
  597. declare -g FACTORYIMGGZ="$img_prefix-factory.img.gz"
  598. declare -g SYSUPGRADEIMG="$img_prefix-sysupgrade.img"
  599. declare -g SYSUPGRADEIMGGZ="$img_prefix-sysupgrade.img.gz"
  600. declare -g SYSUPGRADEIMGGZFNAME="${SYSUPGRADEIMGGZ##*/}"
  601. if (( DEBUG )) || (( PROFILE_INFO )); then
  602. echo "Profile settings:"
  603. for x in "${!P_ARR[@]}"; do printf "%s=%s\n" "$x" "${P_ARR[$x]}"; done
  604. echo "Build settings:"
  605. cat <<- EOF
  606. ALIAS: $profile
  607. BUILDROOT: $BUILDROOT
  608. BUILDDIR: $BUILDDIR
  609. SRCDIR: $SRCDIR
  610. BINDIR: $BINDIR
  611. GITSRCDIR: $GITSRCDIR
  612. THIS_BINDIR: $THIS_BINDIR
  613. TARGET: ${P_ARR[target]}
  614. PROFILE: ${P_ARR[profile]}
  615. RELEASE: $RELEASE
  616. FILESYSTEM: $FILESYSTEM
  617. IB_URL: $IB_URL
  618. IB_ARCHIVE: $IB_ARCHIVE
  619. SEED_URL: $SEED_URL
  620. SEED_FILE: $SEED_FILE
  621. SHA256_URL: $SHA256_URL
  622. SHA256_FILE: $SHA256_FILE
  623. EOF
  624. fi
  625. (( RESET )) && resetProfile
  626. (( FROM_SOURCE )) && fromSource
  627. getImageBuilder || return $?
  628. addRepos
  629. #copyFiles
  630. [[ -v SSH_BACKUP_PATH ]] && sshBackup
  631. if makeImage; then
  632. [[ -v SSH_UPGRADE_PATH ]] && sshUpgrade
  633. [[ -v FLASH_DEV ]] && flashImage
  634. fi
  635. done
  636. }
  637. main "$@"
  638. exit