make_fw.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/bin/bash
  2. ## Firmware image building script
  3. ## http://superglue.it | Danja Vasiliev, 2014
  4. ##
  5. ## Needs:
  6. ## - OpenWRT ImageBuilder blob:
  7. ## http://downloads.openwrt.org/barrier_breaker/14.07-rc3/ar71xx/generic
  8. ## or http://downloads.openwrt.org/snapshots/trunk/ar71xx
  9. ## - Superglue serverfiles local repo (which this script is part of):
  10. ## http://git.superglue.it/superglue/serverfiles/tree/master
  11. _PWD=$(pwd)
  12. _IMAGEBUILDER="$_PWD/../../../openwrt/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64"
  13. _BUILDS="$_PWD/../../../sg-builds"
  14. [[ -e $_IMAGEBUILDER ]] || (echo 'ImageBuilder is missing'; exit 1;)
  15. [[ -e $_BUILDS ]] || (echo 'Builds directory is missing'; exit 1;)
  16. ## dirs with platform specific files
  17. #_TARGETS='DIR505A1 TLWR710 WRT160NL'
  18. _TARGETS='TLWR710'
  19. ## dir with common files
  20. _COMMON='common'
  21. _MAJOR='0.1' ## bump that on major changes
  22. #_SUFFIX='git' ## could be 'beta', 'rc', etc
  23. _SUFFIX='k0a1a' ## could be 'beta', 'rc', etc
  24. ## read build serial, incremented on every successful build
  25. if [[ -e sg_$_MAJOR.revision ]]; then
  26. read _MINOR < sg_$_MAJOR.revision
  27. let _MINOR++
  28. else _MINOR=0
  29. fi
  30. ## get OpenWRT revision number
  31. _OPENWRT=$(fgrep -m1 'REVISION:=' $_IMAGEBUILDER/include/version.mk || echo 'r00000')
  32. _OPENWRT=${_OPENWRT/REVISION:=/}
  33. echo $_OPENWRT > openwrt.revision
  34. _VERSION="$_MAJOR"."$_MINOR"-"$_SUFFIX"
  35. echo "About to start building version: $_VERSION"
  36. echo -e "Targets for this build: $_TARGETS\n"
  37. echo 'Removing temporary dirs (if any)'
  38. find -maxdepth 1 -name *.tmp -exec rm -Rf {} \;
  39. for _TARGET in $_TARGETS; do
  40. [[ -e $_TARGET.tmp ]] && rm -Rf $_TARGET.tmp
  41. cp -Ra $_COMMON $_TARGET.tmp
  42. cp -Ra $_TARGET/* $_TARGET.tmp/
  43. sed -e "s/%REVISION%/$_OPENWRT/g" -e "s/%VERSION%/$_VERSION/g" $_COMMON/etc/banner > $_TARGET.tmp/etc/banner
  44. echo $_VERSION > $_TARGET.tmp/etc/superglue_version
  45. cd $_IMAGEBUILDER && make clean
  46. ## package stash, might need these:
  47. # kmod-fs-vfat kmod-fs-btrfs btrfs-progs
  48. make image PROFILE=$_TARGET PACKAGES="bash gawk sudo procps-ps openssh-sftp-server haserl lighttpd lighttpd-mod-access lighttpd-mod-cgi lighttpd-mod-compress lighttpd-mod-accesslog lighttpd-mod-rewrite lighttpd-mod-auth lighttpd-mod-alias lighttpd-mod-setenv blkid kmod-fs-ext4 block-mount mini-sendmail kmod-usb-storage kmod-scsi-generic mount-utils kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-utf8 kmod-nls-base coreutils-stat mini-httpd-htpasswd wireless-tools avahi-daemon kmod-fs-vfat kmod-fs-btrfs btrfs-progs swap-utils" FILES=$_PWD/$_TARGET.tmp BIN_DIR=$_BUILDS/$_VERSION/$_TARGET/openwrt &&
  49. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-factory.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-factory.bin
  50. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-sysupgrade.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-sysupgrade.bin
  51. cd $_BUILDS/$_VERSION/$_TARGET
  52. md5sum *.bin > md5sums
  53. cd -
  54. _ERR=$?
  55. if [[ $_ERR -eq 0 ]]; then
  56. echo -e "\n$_TARGET build completed\n"
  57. else
  58. rm -Rf $_BUILDS/$_VERSION/$_TARGET
  59. fi
  60. echo 'Cleaning up..'
  61. make clean
  62. cd $_PWD
  63. rm -Rf $_TARGET.tmp
  64. done
  65. if [[ $_ERR -eq 0 ]]; then
  66. ## if build succeeded bump revision
  67. echo $_MINOR > sg_$_MAJOR.revision
  68. echo -e "\nBuilding SUCCEEDED! :)\n"
  69. ## create symlinks to latest
  70. [[ -e $_BUILDS/latest ]] && touch $_BUILDS/latest || mkdir $_BUILDS/latest
  71. for _TARGET in $_TARGETS; do
  72. [[ -e $_BUILDS/latest/$_TARGET ]] && rm -f $_BUILDS/latest/$_TARGET/* || mkdir $_BUILDS/latest/$_TARGET
  73. set -o xtrace
  74. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-factory.bin $_BUILDS/latest/$_TARGET/superglue-firmware-latest-$(echo $_TARGET | tr [:upper:] [:lower:])-factory.bin
  75. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-sysupgrade.bin $_BUILDS/latest/$_TARGET/superglue-firmware-latest-$(echo $_TARGET | tr [:upper:] [:lower:])-sysupgrade.bin
  76. set +o xtrace
  77. done
  78. else
  79. echo -e "\nBuilding FAILED.. :/\n"
  80. fi
  81. exit $_ERR