make_fw.sh 3.8 KB

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