make_fw.sh 5.3 KB

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