make_fw.sh 4.9 KB

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