build-ants3.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/bin/bash
  2. #
  3. # OPENWRT_DIR is ${ROOT_DIR}/openwrt, build the image in it
  4. # Controller's image should include the following configurations:
  5. # ${AVA_MACHINE}_owrepo : OpenWrt repo, format: repo_url@repo_ver
  6. # feeds.${AVA_MACHINE}.conf : OpenWrt feeds, file locate in cgminer-openwrt-packages
  7. # ${AVA_TARGET_BOARD}_brdcfg : OpenWrt target and config, file locate in cgminer-openwrt-packages
  8. #
  9. # Learn bash: http://explainshell.com/
  10. set -e
  11. SCRIPT_VERSION=14122022
  12. # Support machine: bitmain
  13. [ -z "${AVA_MACHINE}" ] && AVA_MACHINE=bitmain
  14. [ -z "${AVA_TARGET_BOARD}" ] && AVA_TARGET_BOARD=tl-mr3020-v1
  15. # OpenWrt repo
  16. bitmain_owrepo="http://gogserver.dnsalias.com:3000/wareck/openwrt_chaos_calmer.git@master"
  17. #bitmain_owrepo="http://gogserver.dnsalias.com:3000/wareck/openwrt-archive.git@master"
  18. # OpenWrt feeds
  19. FEEDS_CONF=feeds.${AVA_MACHINE}.conf
  20. # Board config: target(get it in the OpenWrt bin), config
  21. tl_wr703n_v1_brdcfg=("ar71xx" "config.${AVA_MACHINE}.703n")
  22. tl_mr3020_v1_brdcfg=("ar71xx" "config.${AVA_MACHINE}.mr3020")
  23. which wget > /dev/null && DL_PROG=wget && DL_PARA="-nv -O"
  24. which curl > /dev/null && DL_PROG=curl && DL_PARA="-L -o"
  25. # According to http://wiki.openwrt.org/doc/howto/build
  26. unset SED
  27. unset GREP_OPTIONS
  28. [ "`id -u`" == "0" ] && echo "[ERROR]: Please use non-root user" && exit 1
  29. # Adjust CORE_NUM by yourself
  30. [ -z "${CORE_NUM}" ] && CORE_NUM="$(expr $(nproc) + 1)"
  31. DATE=`date +%Y%m%d`
  32. SCRIPT_FILE="$(readlink -f $0)"
  33. SCRIPT_DIR=`dirname ${SCRIPT_FILE}`
  34. ROOT_DIR=${SCRIPT_DIR}/avalon
  35. OPENWRT_DIR=${ROOT_DIR}/openwrt
  36. prepare_version() {
  37. cd ${OPENWRT_DIR}
  38. GIT_VERSION=`git ls-remote https://github.com/wareck/cgminer-gekko master | cut -f1 | cut -c1-7`
  39. LUCI_GIT_VERSION=`git --git-dir=./feeds/luci/.git rev-parse HEAD | cut -c1-7`
  40. OW_GIT_VERSION=`git --git-dir=./feeds/cgminer/.git rev-parse HEAD | cut -c1-7`
  41. cat > ./files/etc/avalon_version << EOL
  42. Firmware - $DATE
  43. luci: $LUCI_GIT_VERSION
  44. cgminer: $GIT_VERSION
  45. cgminer-packages: $OW_GIT_VERSION
  46. EOL
  47. }
  48. prepare_config() {
  49. cd ${OPENWRT_DIR}
  50. eval OPENWRT_CONFIG=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[1]} && cp ./feeds/cgminer/cgminer/data/${OPENWRT_CONFIG} .config
  51. }
  52. prepare_feeds() {
  53. cd ${OPENWRT_DIR}
  54. $DL_PROG https://raw.githubusercontent.com/csa402/cgminer-openwrt-packages/master/cgminer/data/${FEEDS_CONF} $DL_PARA feeds.conf && \
  55. ./scripts/feeds update -a && \
  56. ./scripts/feeds install -a
  57. if [ ! -e files ]; then
  58. ln -s feeds/cgminer/cgminer/root-files files
  59. fi
  60. }
  61. prepare_source() {
  62. echo "Gen firmware for ${AVA_TARGET_BOARD}:${AVA_MACHINE}"
  63. echo "TARGET BOARD :${AVA_TARGET_BOARD}"
  64. echo "TARGET MACHINE :${AVA_MACHINE}"
  65. cd ${SCRIPT_DIR}
  66. [ ! -d avalon ] && mkdir -p avalon/bin
  67. cd avalon
  68. if [ ! -d openwrt ]; then
  69. eval OPENWRT_URL=\${${AVA_MACHINE}_owrepo}
  70. PROTOCOL="`echo ${OPENWRT_URL} | cut -d : -f 1`"
  71. case "${PROTOCOL}" in
  72. git)
  73. GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  74. GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  75. git clone -b ${GITBRANCH} ${GITREPO} openwrt
  76. ;;
  77. svn)
  78. SVNVER="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  79. SVNREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  80. svn co ${SVNREPO}@${SVNVER} openwrt
  81. ;;
  82. http)
  83. GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  84. GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  85. git clone ${GITREPO} openwrt
  86. ;;
  87. https)
  88. GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
  89. GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
  90. git clone ${GITREPO} openwrt
  91. ;;
  92. *)
  93. echo "Protocol not supported"; exit 1;
  94. ;;
  95. esac
  96. fi
  97. sed -i -e "s/git:\/\/github.com/http:\/\/github.com/g" openwrt/package/network/services/odhcpd/Makefile
  98. [ ! -e dl ] && mkdir dl
  99. cd ${OPENWRT_DIR}
  100. ln -sf ../dl
  101. }
  102. build_image() {
  103. cd ${OPENWRT_DIR}
  104. yes "" | make oldconfig > /dev/null
  105. # clean before build
  106. make -j${CORE_NUM} clean world
  107. #make -j${CORE_NUM} world V=s
  108. }
  109. build_cgminer() {
  110. cd ${OPENWRT_DIR}
  111. rm -f ./dl/cgminer-*.tar.bz2
  112. yes "" | make oldconfig > /dev/null
  113. make -j${CORE_NUM} package/cgminer/{clean,compile}
  114. if [ "$?" == "0" ]; then
  115. eval AVA_TARGET_PLATFORM=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[0]}
  116. cd ..
  117. mkdir -p ./bin/${AVA_TARGET_BOARD}
  118. cp ./openwrt/bin/${AVA_TARGET_PLATFORM}/packages/cgminer/cgminer*.ipk ./bin/${AVA_TARGET_BOARD}
  119. fi
  120. }
  121. do_release() {
  122. cd ${ROOT_DIR}
  123. eval AVA_TARGET_PLATFORM=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[0]}
  124. mkdir -p ./bin/${DATE}/${AVA_TARGET_BOARD}/
  125. cp -a ./openwrt/bin/${AVA_TARGET_PLATFORM}/* ./bin/${DATE}/${AVA_TARGET_BOARD}/
  126. }
  127. cleanup() {
  128. cd ${ROOT_DIR}
  129. rm -rf openwrt/ > /dev/null
  130. }
  131. show_help() {
  132. echo "\
  133. Usage: $0 [--version] [--help] [--build] [--cgminer] [--cleanup]
  134. --version
  135. --help Display help message
  136. --build Get .config file and build firmware
  137. --cgminer Re-compile only cgminer openwrt package
  138. --test Dowload and prebuild files
  139. --cleanup Remove all files
  140. AVA_TARGET_BOARD Environment variable, available target:
  141. tl-wr703n-v1, pi-modelb-v1
  142. pi-modelb-v2, tl-mr3020-v1
  143. use pi-modelb-v2 if unset
  144. AVA_MACHINE Environment variable, available machine:
  145. avalon6, avalon4, gekko, rockminer
  146. use avalon6 if unset
  147. Written by: Xiangfu <xiangfu@openmobilefree.net>
  148. Fengling <Fengling.Qin@gmail.com>
  149. wareck <wareck@gmail.com>
  150. Version: ${SCRIPT_VERSION}"
  151. }
  152. if [ "$#" == "0" ]; then
  153. $0 --help
  154. exit 0
  155. fi
  156. for i in "$@"
  157. do
  158. case $i in
  159. --version|--help)
  160. show_help
  161. exit
  162. ;;
  163. --build)
  164. prepare_source && prepare_feeds && prepare_config && prepare_version && build_image && do_release
  165. ;;
  166. --cgminer)
  167. prepare_source && prepare_feeds && prepare_config && prepare_version && build_cgminer
  168. ;;
  169. --test)
  170. prepare_source && prepare_feeds && prepare_config && prepare_version
  171. ;;
  172. --cleanup)
  173. cleanup
  174. ;;
  175. *)
  176. show_help
  177. exit
  178. ;;
  179. esac
  180. done