make_fw.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. echo 'cleaning temporary files'
  44. find . -name '*.swp' -o -name '*.swo' -o -name '*.tmp' -o -name '*.bup' -o -name '*.bak' -exec rm -rf {} \;
  45. sed -e "s/%REVISION%/$_OPENWRT/g" -e "s/%VERSION%/$_VERSION/g" $_COMMON/etc/banner > $_TARGET.tmp/etc/banner
  46. echo $_VERSION > $_TARGET.tmp/etc/superglue_version
  47. cd $_IMAGEBUILDER && make clean
  48. ## package stash, might need these:
  49. # kmod-fs-vfat kmod-fs-btrfs btrfs-progs
  50. 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 &&
  51. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-factory.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-factory.bin
  52. ln -s $_BUILDS/$_VERSION/$_TARGET/openwrt/openwrt-*-sysupgrade.bin $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-$_VERSION-$(echo $_TARGET | tr [:upper:] [:lower:])-sysupgrade.bin
  53. cd $_BUILDS/$_VERSION/$_TARGET
  54. md5sum *.bin > md5sums
  55. cd -
  56. _ERR=$?
  57. if [[ $_ERR -eq 0 ]]; then
  58. echo -e "\n$_TARGET build completed\n"
  59. else
  60. rm -Rf $_BUILDS/$_VERSION/$_TARGET
  61. fi
  62. echo 'Cleaning up..'
  63. make clean
  64. cd $_PWD
  65. rm -Rf $_TARGET.tmp
  66. done
  67. if [[ $_ERR -eq 0 ]]; then
  68. ## if build succeeded bump revision
  69. echo $_MINOR > sg_$_MAJOR.revision
  70. echo -e "\nBuilding SUCCEEDED! :)\n"
  71. ## create symlinks to latest
  72. [[ -e $_BUILDS/latest ]] && touch $_BUILDS/latest || mkdir $_BUILDS/latest
  73. for _TARGET in $_TARGETS; do
  74. [[ -e $_BUILDS/latest/$_TARGET ]] && rm -f $_BUILDS/latest/$_TARGET/* || mkdir $_BUILDS/latest/$_TARGET
  75. #set -o xtrace
  76. _FACTORY="$_BUILDS"/latest/"$_TARGET"/superglue-firmware-$(echo "$_TARGET" | tr [:upper:] [:lower:])-"${_VERSION}"-factory.bin
  77. _SYSUPGRADE=$_BUILDS/latest/"$_TARGET"/superglue-firmware-$(echo "$_TARGET" | tr [:upper:] [:lower:])-"${_VERSION}"-sysupgrade.bin
  78. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-factory.bin $_FACTORY &&
  79. echo -e "$_FACTORY\n"
  80. ln -sf $_BUILDS/$_VERSION/$_TARGET/superglue-firmware-*-sysupgrade.bin $_SYSUPGRADE &&
  81. echo -e "$_SYSUPGRADE\n"
  82. # set +o xtrace
  83. done
  84. else
  85. echo -e "\nBuilding FAILED.. :/\n"
  86. fi
  87. exit $_ERR