make_fw.sh 5.5 KB

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