make_fw.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. ## SuperGlue project | http://superglue.it | 2014-2015 | GPLv3
  3. ## http://git.superglue.it/superglue/serverfiles
  4. ##
  5. ## make_fw.sh - Superglue firmware image building script
  6. ##
  7. ## Needs:
  8. ## - OpenWRT ImageBuilder blob:
  9. ## http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic
  10. ## or http://downloads.openwrt.org/snapshots/trunk/ar71xx
  11. ## - Fetch (needed) packages:
  12. ## https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages
  13. ## - Superglue serverfiles local repo (which this script is a part of):
  14. ## http://git.superglue.it/superglue/serverfiles/tree/master
  15. ## errors are futile
  16. set -e
  17. ## make sure we are running from the upper level directory
  18. [[ $(pwd) == $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) ]] && (echo "ERROR: must be run as ./tools/$(basename $0), exiting"; exit 1;)
  19. _PWD=$(pwd)
  20. _IMAGEBUILDER="$_PWD/../../../openwrt/OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64"
  21. _BUILDS="$_PWD/../../../sg-builds"
  22. [[ -e $_IMAGEBUILDER ]] || (echo 'ImageBuilder is missing'; exit 1;)
  23. [[ -e $_BUILDS ]] || (echo 'Builds directory is missing'; exit 1;)
  24. set +e
  25. ## dirs with platform specific files
  26. _TARGETS='DIR505A1 TLWR710' ##WRT160NL
  27. #_TARGETS='TLWR710'
  28. ## dir with common files
  29. _COMMON='common'
  30. _SG_REVISION="$_PWD/superglue.revision"
  31. if [[ -e $_SG_REVISION ]]; then
  32. source $_SG_REVISION
  33. else
  34. ## versioning defaults
  35. ## change these in $_SG_REVISION
  36. _MAJOR='0.1'
  37. _MINOR='0'
  38. _SUFFIX='testing'
  39. echo -e "_MAJOR=$_MAJOR\n_MINOR=$_MINOR\n_SUFFIX=$_SUFFIX" > $_SG_REVISION
  40. fi
  41. let _MINOR++
  42. _OPENWRT_REVISION="$_PWD/openwrt.revision"
  43. ## browser extension (if any)
  44. #_EXT_SRC="$_PWD/../../editor/build/superglue-firefox.xpi"
  45. ## get OpenWRT revision
  46. _OPENWRT=$(fgrep -m1 'REVISION:=' $_IMAGEBUILDER/include/version.mk || echo 'r00000')
  47. _OPENWRT=${_OPENWRT/REVISION:=/}
  48. echo $_OPENWRT > $_OPENWRT_REVISION
  49. _VERSION="$_MAJOR"."$_MINOR"-"$_SUFFIX"
  50. ## define how firmware files are named
  51. _FN_PREFIX='superglue-firmware'
  52. echo -e "Build ver: $_VERSION
  53. Targets: $_TARGETS\n"
  54. trap abort INT
  55. abort() {
  56. echo -e "Bye..\n"
  57. exit 1
  58. }
  59. echo 'Ready? [Y/n] '; read _USER_ANSW
  60. if [[ $_USER_ANSW == 'n' ]]; then
  61. abort
  62. elif [[ $_USER_ANSW == 'y' || $_USER_ANSW == '' ]]; then
  63. true
  64. fi
  65. echo 'Removing temporary dirs (if any)'
  66. find -maxdepth 1 -name *.tmp -exec rm -Rf {} \;
  67. for _TARGET in $_TARGETS; do
  68. _BIN_DIR=$_BUILDS/$_VERSION/$_TARGET
  69. echo 'cleaning target and binary directories..'
  70. [[ -e $_TARGET.tmp ]] && rm -Rf $_TARGET.tmp
  71. [[ -e $_BIN_DIR ]] && rm -Rf $_BIN_DIR
  72. sleep 1
  73. echo 'copying common and target specific files..'
  74. cp -Ra $_COMMON $_TARGET.tmp
  75. cp -Ra $_TARGET/* $_TARGET.tmp/
  76. sleep 1
  77. if [[ -e $_EXT_SRC ]]; then
  78. echo 'copying browser extension..'
  79. _EXT_DST="$_TARGET.tmp/opt/lib/extension/superglue.xpi"
  80. [[ -e $(dirname $_EXT_DST) ]] || mkdir $(dirname $_EXT_DST)
  81. cp -Ra $_EXT_SRC $_EXT_DST
  82. sleep 1
  83. fi
  84. echo 'cleaning temporary files..'
  85. find . -name '*.swp' -o -iname "[._]*.s[a-w][a-z]" -o -iname '*.tmp' -o -iname '*.bup' -o -iname '*.bak' -exec rm -Rf {} \;
  86. sed -e "s/%REVISION%/$_OPENWRT/g" -e "s/%VERSION%/$_VERSION/g" $_COMMON/etc/banner > $_TARGET.tmp/etc/banner
  87. echo $_VERSION > $_TARGET.tmp/etc/superglue_version
  88. cd $_IMAGEBUILDER && make clean
  89. echo -e "\nbuilding $_TARGET image!\n"
  90. sleep 2
  91. ## currently unused packages
  92. # kmod-fs-vfat kmod-fs-btrfs btrfs-progs kmod-fs-ext4 sudo
  93. make image PROFILE=$_TARGET PACKAGES="bash gawk 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-proxy lighttpd-mod-setenv blkid 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 coreutils-sha1sum rpcd-mod-iwinfo procps-ps uhttpd uhttpd-mod-ubus openvpn-openssl dtach curl" FILES=$_PWD/$_TARGET.tmp BIN_DIR=$_BIN_DIR/openwrt
  94. _ERR=$?
  95. if [[ $_ERR -gt 0 ]]; then
  96. echo -e "\nFAILED to build $_TARGET image :/ (are we missing packages?) \n"
  97. exit 1
  98. fi
  99. _FILENAME="$_FN_PREFIX"_"$_VERSION"_"$(echo $_TARGET | tr [:upper:] [:lower:])"
  100. cd $_BIN_DIR
  101. ln -s ./openwrt/openwrt-*-factory.bin ./$_FILENAME'_initial.bin' &&
  102. ln -s ./openwrt/openwrt-*-sysupgrade.bin ./$_FILENAME'_upgrade.bin' &&
  103. md5sum *.bin > md5sums
  104. cd -
  105. _ERR=$?
  106. if [[ $_ERR -eq 0 ]]; then
  107. echo -e "\n$_TARGET build completed\n"
  108. else
  109. rm -Rf $_BIN_DIR
  110. fi
  111. echo 'Cleaning up..'
  112. make clean
  113. cd $_PWD
  114. rm -Rf $_TARGET.tmp
  115. done
  116. if [[ $_ERR -eq 0 ]]; then
  117. ## if build succeeded bump revision
  118. echo -e "_MAJOR=$_MAJOR\n_MINOR=$_MINOR\n_SUFFIX=$_SUFFIX" > $_SG_REVISION
  119. echo -e "\nBuilding SUCCEEDED! :)\n"
  120. ## create symlinks to the latest
  121. [[ -h $_BUILDS/latest ]] || rm -rf $_BUILDS/latest
  122. ln -sf $_BUILDS/$_VERSION -T $_BUILDS/latest
  123. else
  124. echo -e "\nBuild FAILED.. :/\n"
  125. fi
  126. exit $_ERR