make_fw.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. ## browser extension (if any)
  31. _EXT_SRC="$_PWD/../../editor/build/firefox/superglue.xpi"
  32. _EXT_DST="$_COMMON/opt/lib/extension/superglue.xpi"
  33. ## read build serial, incremented on every successful build
  34. if [[ -e $_SG_REVISION ]]; then
  35. read _MINOR < $_SG_REVISION
  36. let _MINOR++
  37. else _MINOR=0
  38. fi
  39. ## get OpenWRT revision number
  40. _OPENWRT=$(fgrep -m1 'REVISION:=' $_IMAGEBUILDER/include/version.mk || echo 'r00000')
  41. _OPENWRT=${_OPENWRT/REVISION:=/}
  42. echo $_OPENWRT > $_OPENWRT_REVISION
  43. _VERSION="$_MAJOR"."$_MINOR"-"$_SUFFIX"
  44. echo "About to start building version: $_VERSION"
  45. echo -e "Targets for this build: $_TARGETS\n"
  46. echo 'Removing temporary dirs (if any)'
  47. find -maxdepth 1 -name *.tmp -exec rm -Rf {} \;
  48. for _TARGET in $_TARGETS; do
  49. _BIN_DIR=$_BUILDS/$_VERSION/$_TARGET
  50. echo 'cleaning target and binary directories..'
  51. [[ -e $_TARGET.tmp ]] && rm -Rf $_TARGET.tmp
  52. [[ -e $_BIN_DIR ]] && rm -Rf $_BIN_DIR
  53. sleep 1
  54. echo 'copying common and target specific files..'
  55. cp -Ra $_COMMON $_TARGET.tmp
  56. cp -Ra $_TARGET/* $_TARGET.tmp/
  57. [[ -e $_EXT_SRC ]] && cp -Ra $_EXT_SRC $_EXT_DST
  58. sleep 1
  59. echo 'cleaning temporary files..'
  60. find . -name '*.swp' -o -iname "[._]*.s[a-w][a-z]" -o -iname '*.tmp' -o -iname '*.bup' -o -iname '*.bak' -exec rm -Rf {} \;
  61. sed -e "s/%REVISION%/$_OPENWRT/g" -e "s/%VERSION%/$_VERSION/g" $_COMMON/etc/banner > $_TARGET.tmp/etc/banner
  62. echo $_VERSION > $_TARGET.tmp/etc/superglue_version
  63. cd $_IMAGEBUILDER && make clean
  64. echo 'ready for building an image!'
  65. sleep 1
  66. ## package stash, might need these:
  67. # kmod-fs-vfat kmod-fs-btrfs btrfs-progs
  68. 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=$_BIN_DIR/openwrt &&
  69. ## define how firmware files are named
  70. _FN_PREFIX='superglue-firmware'
  71. _FILENAME="$_FN_PREFIX"_"$_VERSION"_"$(echo $_TARGET | tr [:upper:] [:lower:])"
  72. ln -s $_BIN_DIR/openwrt/openwrt-*-factory.bin $_BIN_DIR/$_FILENAME'_initial.bin'
  73. ln -s $_BIN_DIR/openwrt/openwrt-*-sysupgrade.bin $_BIN_DIR/$_FILENAME'_upgrade.bin'
  74. cd $_BIN_DIR
  75. md5sum *.bin > md5sums
  76. cd -
  77. _ERR=$?
  78. if [[ $_ERR -eq 0 ]]; then
  79. echo -e "\n$_TARGET build completed\n"
  80. else
  81. rm -Rf $_BIN_DIR
  82. fi
  83. echo 'Cleaning up..'
  84. make clean
  85. cd $_PWD
  86. rm -Rf $_TARGET.tmp
  87. done
  88. if [[ $_ERR -eq 0 ]]; then
  89. ## if build succeeded bump revision
  90. echo $_MINOR > $_SG_REVISION
  91. echo -e "\nBuilding SUCCEEDED! :)\n"
  92. ## create symlinks to latest
  93. [[ -e $_BUILDS/latest ]] && touch $_BUILDS/latest || mkdir $_BUILDS/latest
  94. for _TARGET in $_TARGETS; do
  95. [[ -e $_BUILDS/latest/$_TARGET ]] && rm -f $_BUILDS/latest/$_TARGET/* || mkdir $_BUILDS/latest/$_TARGET
  96. #set -o xtrace
  97. _FACTORY="$_BUILDS"/latest/"$_TARGET"/$_FILENAME-initial.bin
  98. _SYSUPGRADE=$_BUILDS/latest/"$_TARGET"/$_FILENAME-upgrade.bin
  99. ln -sf $_BIN_DIR/$_FN_PREFIX-*-initial.bin $_FACTORY &&
  100. echo -e "$_FACTORY\n"
  101. ln -sf $_BIN_DIR/$_FN_PREFIX-*-upgrade.bin $_SYSUPGRADE &&
  102. echo -e "$_SYSUPGRADE\n"
  103. # set +o xtrace
  104. done
  105. else
  106. echo -e "\nBuilding FAILED.. :/\n"
  107. fi
  108. exit $_ERR