make_fw.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. ## dir with common files
  28. _COMMON='common'
  29. _SG_REVISION="$_PWD/superglue.revision"
  30. if [[ -e $_SG_REVISION ]]; then
  31. source $_SG_REVISION
  32. else
  33. ## versioning defaults
  34. ## change these in $_SG_REVISION
  35. _MAJOR='0.1'
  36. _MINOR='0'
  37. _SUFFIX='testing'
  38. echo -e "_MAJOR=$_MAJOR\n_MINOR=$_MINOR\n_SUFFIX=$_SUFFIX" > $_SG_REVISION
  39. fi
  40. let _MINOR++
  41. _OPENWRT_REVISION="$_PWD/openwrt.revision"
  42. ## browser extension (if any)
  43. _EXT_SRC="$_PWD/../../editor/build/superglue-firefox.xpi"
  44. ## get OpenWRT revision
  45. _OPENWRT=$(fgrep -m1 'REVISION:=' $_IMAGEBUILDER/include/version.mk || echo 'r00000')
  46. _OPENWRT=${_OPENWRT/REVISION:=/}
  47. echo $_OPENWRT > $_OPENWRT_REVISION
  48. _VERSION="$_MAJOR"."$_MINOR"-"$_SUFFIX"
  49. ## define how firmware files are named
  50. _FN_PREFIX='superglue-firmware'
  51. echo -e "Build ver: $_VERSION
  52. Targets: $_TARGETS\n"
  53. trap abort INT
  54. abort() {
  55. echo -e "Bye..\n"
  56. exit 1
  57. }
  58. echo 'Ready? [Y/n] '; read _USER_ANSW
  59. if [[ $_USER_ANSW == 'n' ]]; then
  60. abort
  61. elif [[ $_USER_ANSW == 'y' || $_USER_ANSW == '' ]]; then
  62. true
  63. fi
  64. echo 'Removing temporary dirs (if any)'
  65. find -maxdepth 1 -name *.tmp -exec rm -Rf {} \;
  66. for _TARGET in $_TARGETS; do
  67. _BIN_DIR=$_BUILDS/$_VERSION/$_TARGET
  68. echo 'cleaning target and binary directories..'
  69. [[ -e $_TARGET.tmp ]] && rm -Rf $_TARGET.tmp
  70. [[ -e $_BIN_DIR ]] && rm -Rf $_BIN_DIR
  71. sleep 1
  72. echo 'copying common and target specific files..'
  73. cp -Ra $_COMMON $_TARGET.tmp
  74. cp -Ra $_TARGET/* $_TARGET.tmp/
  75. sleep 1
  76. if [[ -e $_EXT_SRC ]]; then
  77. echo 'copying browser extension..'
  78. _EXT_DST="$_TARGET.tmp/opt/lib/extension/superglue.xpi"
  79. [[ -e $(dirname $_EXT_DST) ]] || mkdir $(dirname $_EXT_DST)
  80. cp -Ra $_EXT_SRC $_EXT_DST
  81. sleep 1
  82. fi
  83. echo 'cleaning temporary files..'
  84. find . -name '*.swp' -o -iname "[._]*.s[a-w][a-z]" -o -iname '*.tmp' -o -iname '*.bup' -o -iname '*.bak' -exec rm -Rf {} \;
  85. sed -e "s/%REVISION%/$_OPENWRT/g" -e "s/%VERSION%/$_VERSION/g" $_COMMON/etc/banner > $_TARGET.tmp/etc/banner
  86. echo $_VERSION > $_TARGET.tmp/etc/superglue_version
  87. cd $_IMAGEBUILDER && make clean
  88. echo -e "\nbuilding $_TARGET image!\n"
  89. sleep 2
  90. ## currently unused packages
  91. # kmod-fs-vfat kmod-fs-btrfs btrfs-progs kmod-fs-ext4 sudo
  92. 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
  93. _ERR=$?
  94. if [[ $_ERR -gt 0 ]]; then
  95. echo -e "\nFAILED to build $_TARGET image :/ (are we missing packages?) \n"
  96. exit 1
  97. fi
  98. _FILENAME="$_FN_PREFIX"_"$_VERSION"_"$(echo $_TARGET | tr [:upper:] [:lower:])"
  99. cd $_BIN_DIR
  100. ln -s ./openwrt/openwrt-*-factory.bin ./$_FILENAME'_initial.bin'
  101. ln -s ./openwrt/openwrt-*-sysupgrade.bin ./$_FILENAME'_upgrade.bin'
  102. [[ -e ./$_FILENAME'_initial.bin' ]] && [[ -e ./$_FILENAME'_upgrade.bin' ]] &&
  103. md5sum *.bin > md5sums
  104. _ERR=$?
  105. cd -
  106. if [[ $_ERR -eq 0 ]]; then
  107. echo -e "\n$_TARGET build completed\n"
  108. else
  109. echo -e "\nError making symlinks! Images not built. Were they too large?\n"
  110. rm -Rf $_BIN_DIR
  111. fi
  112. echo 'Cleaning up..'
  113. make clean
  114. cd $_PWD
  115. rm -Rf $_TARGET.tmp
  116. done
  117. if [[ $_ERR -eq 0 ]]; then
  118. ## if build succeeded bump revision
  119. echo -e "_MAJOR=$_MAJOR\n_MINOR=$_MINOR\n_SUFFIX=$_SUFFIX" > $_SG_REVISION
  120. echo -e "\n$_TARGET build SUCCEEDED! :)\n"
  121. ## create symlinks to the latest
  122. [[ -h $_BUILDS/latest ]] || rm -rf $_BUILDS/latest
  123. ln -sf $_BUILDS/$_VERSION -T $_BUILDS/latest
  124. else
  125. echo -e "\n$_TARGET build FAILED.. :/ \n"
  126. sleep 5
  127. fi
  128. exit $_ERR