make_fw.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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='DIR505A1'
  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='testing' ## 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. make image PROFILE=$_TARGET PACKAGES="bash gawk sudo procps-ps 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 kmod-fs-vfat kmod-fs-btrfs btrfs-progs 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" FILES=$_PWD/$_TARGET.tmp BIN_DIR=$_BUILDS/$_VERSION/$_TARGET/openwrt &&
  47. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-factory.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-factory.bin
  48. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-sysupgrade.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-sysupgrade.bin
  49. cd $_BUILDS/$_VERSION/$_TARGET
  50. md5sum *.bin > md5sums
  51. cd -
  52. _ERR=$?
  53. if [[ $_ERR -eq 0 ]]; then
  54. echo -e "\n$_TARGET build completed\n"
  55. else
  56. rm -Rf $_BUILDS/$_VERSION/$_TARGET
  57. fi
  58. echo 'Cleaning up..'
  59. make clean
  60. cd $_PWD
  61. rm -Rf $_TARGET.tmp
  62. done
  63. if [[ $_ERR -eq 0 ]]; then
  64. ## if build succeeded bump revision
  65. echo $_MINOR > sg_$_MAJOR.revision
  66. echo -e "\nBuilding SUCCEEDED! :)\n"
  67. ## create symlinks to latest
  68. [[ -e $_BUILDS/latest ]] && touch $_BUILDS/latest || mkdir $_BUILDS/latest
  69. for _TARGET in $_TARGETS; do
  70. [[ -e $_BUILDS/latest/$_TARGET ]] && rm -f $_BUILDS/latest/$_TARGET/* || mkdir $_BUILDS/latest/$_TARGET
  71. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-factory.bin $_BUILDS/latest/$_TARGET/superglue-firmware-latest-$(echo $_TARGET | tr [:upper:] [:lower:])-factory.bin
  72. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-sysupgrade.bin $_BUILDS/latest/$_TARGET/superglue-firmware-latest-$(echo $_TARGET | tr [:upper:] [:lower:])-sysupgrade.bin
  73. done
  74. else
  75. echo -e "\nBuilding FAILED.. :/\n"
  76. fi
  77. exit $_ERR