make_fw.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. set -e
  12. ## make sure we are running from upper level directory
  13. [[ $(pwd) == $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) ]] && (echo "ERROR: must be run as ./tools/$(basename $0), exiting"; exit 1;)
  14. _PWD=$(pwd)
  15. _IMAGEBUILDER="$_PWD/../../../openwrt/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64"
  16. _BUILDS="$_PWD/../../../sg-builds"
  17. [[ -e $_IMAGEBUILDER ]] || (echo 'ImageBuilder is missing'; exit 1;)
  18. [[ -e $_BUILDS ]] || (echo 'Builds directory is missing'; exit 1;)
  19. set +e
  20. ## dirs with platform specific files
  21. #_TARGETS='DIR505A1 TLWR710 WRT160NL'
  22. _TARGETS='TLWR710'
  23. ## dir with common files
  24. _COMMON='common'
  25. _MAJOR='0.1' ## bump that on major changes
  26. #_SUFFIX='git' ## could be 'beta', 'rc', etc
  27. _SUFFIX='k0a1a' ## could be 'beta', 'rc', etc
  28. _SG_REVISION="$_PWD/include/superglue.revision"
  29. _OPENWRT_REVISION="$_PWD/include/openwrt.revision"
  30. ## read build serial, incremented on every successful build
  31. if [[ -e $_SG_REVISION ]]; then
  32. read _MINOR < $_SG_REVISION
  33. let _MINOR++
  34. else _MINOR=0
  35. fi
  36. ## get OpenWRT revision number
  37. _OPENWRT=$(fgrep -m1 'REVISION:=' $_IMAGEBUILDER/include/version.mk || echo 'r00000')
  38. _OPENWRT=${_OPENWRT/REVISION:=/}
  39. echo $_OPENWRT > $_OPENWRT_REVISION
  40. _VERSION="$_MAJOR"."$_MINOR"-"$_SUFFIX"
  41. echo "About to start building version: $_VERSION"
  42. echo -e "Targets for this build: $_TARGETS\n"
  43. echo 'Removing temporary dirs (if any)'
  44. find -maxdepth 1 -name *.tmp -exec rm -Rf {} \;
  45. for _TARGET in $_TARGETS; do
  46. [[ -e $_TARGET.tmp ]] && rm -Rf $_TARGET.tmp
  47. cp -Ra $_COMMON $_TARGET.tmp
  48. cp -Ra $_TARGET/* $_TARGET.tmp/
  49. echo 'cleaning temporary files'
  50. find . -name '*.swp' -o -name '*.swo' -o -name '*.tmp' -o -name '*.bup' -o -name '*.bak' -exec rm -rf {} \;
  51. sed -e "s/%REVISION%/$_OPENWRT/g" -e "s/%VERSION%/$_VERSION/g" $_COMMON/etc/banner > $_TARGET.tmp/etc/banner
  52. echo $_VERSION > $_TARGET.tmp/etc/superglue_version
  53. cd $_IMAGEBUILDER && make clean
  54. ## package stash, might need these:
  55. # kmod-fs-vfat kmod-fs-btrfs btrfs-progs
  56. 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-btrfs btrfs-progs swap-utils sfdisk coreutils-base64 rpcd-mod-iwinfo" FILES=$_PWD/$_TARGET.tmp BIN_DIR=$_BUILDS/$_VERSION/$_TARGET/openwrt &&
  57. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-factory.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-factory.bin
  58. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-sysupgrade.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-sysupgrade.bin
  59. cd $_BUILDS/$_VERSION/$_TARGET
  60. md5sum *.bin > md5sums
  61. cd -
  62. _ERR=$?
  63. if [[ $_ERR -eq 0 ]]; then
  64. echo -e "\n$_TARGET build completed\n"
  65. else
  66. rm -Rf $_BUILDS/$_VERSION/$_TARGET
  67. fi
  68. echo 'Cleaning up..'
  69. make clean
  70. cd $_PWD
  71. rm -Rf $_TARGET.tmp
  72. done
  73. if [[ $_ERR -eq 0 ]]; then
  74. ## if build succeeded bump revision
  75. echo $_MINOR > $_SG_REVISION
  76. echo -e "\nBuilding SUCCEEDED! :)\n"
  77. ## create symlinks to latest
  78. [[ -e $_BUILDS/latest ]] && touch $_BUILDS/latest || mkdir $_BUILDS/latest
  79. for _TARGET in $_TARGETS; do
  80. [[ -e $_BUILDS/latest/$_TARGET ]] && rm -f $_BUILDS/latest/$_TARGET/* || mkdir $_BUILDS/latest/$_TARGET
  81. #set -o xtrace
  82. _FACTORY="$_BUILDS"/latest/"$_TARGET"/superglue-firmware-$(echo "$_TARGET" | tr [:upper:] [:lower:])-"${_VERSION}"-factory.bin
  83. _SYSUPGRADE=$_BUILDS/latest/"$_TARGET"/superglue-firmware-$(echo "$_TARGET" | tr [:upper:] [:lower:])-"${_VERSION}"-sysupgrade.bin
  84. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-factory.bin $_FACTORY &&
  85. echo -e "$_FACTORY\n"
  86. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-sysupgrade.bin $_SYSUPGRADE &&
  87. echo -e "$_SYSUPGRADE\n"
  88. # set +o xtrace
  89. done
  90. else
  91. echo -e "\nBuilding FAILED.. :/\n"
  92. fi
  93. exit $_ERR