123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #!/bin/bash
- # This is a script for build avalon controller image
- #
- # Copyright 2014-2015 Mikeqin <Fengling.Qin@gmail.com>
- # Copyright 2012-2015 Xiangfu <xiangfu@openmobilefree.com>
- #
- # OPENWRT_DIR is ${ROOT_DIR}/openwrt, build the image in it
- # Controller's image should include the following configurations:
- # ${AVA_MACHINE}_owrepo : OpenWrt repo, format: repo_url@repo_ver
- # feeds.${AVA_MACHINE}.conf : OpenWrt feeds, file locate in cgminer-openwrt-packages
- # ${AVA_TARGET_BOARD}_brdcfg : OpenWrt target and config, file locate in cgminer-openwrt-packages
- #
- # Learn bash: http://explainshell.com/
- set -e
- SCRIPT_VERSION=30092017
- # Support machine: avalon6, avalon4
- [ -z "${AVA_MACHINE}" ] && AVA_MACHINE=gekko
- # Support target board: rpi2-modelb, rpi1-modelb, tl-wr703n-v1, tl-mr3020-v1
- [ -z "${AVA_TARGET_BOARD}" ] && AVA_TARGET_BOARD=tl-mr3020-v1
- # OpenWrt repo
- gekko_owrepo="http://gogserver.dnsalias.com:3000/wareck/openwrt_chaos_calmer.git@master"
- if [ "${AVA_TARGET_BOARD}" == "rpi3" ]; then
- gekko_owrepo="https://github.com/openwrt/openwrt.git@e046500"
- fi
- # OpenWrt feeds
- FEEDS_CONF=feeds.${AVA_MACHINE}.conf
- # Board config: target(get it in the OpenWrt bin), config
- rpi3_modelb_brdcfg=("brcm2708" "config.${AVA_MACHINE}.rpi3")
- rpi2_modelb_brdcfg=("brcm2708" "config.${AVA_MACHINE}.rpi2")
- rpi1_modelb_brdcfg=("brcm2708" "config.${AVA_MACHINE}.raspberry-pi")
- tl_wr703n_v1_brdcfg=("ar71xx" "config.${AVA_MACHINE}.703n")
- tl_mr3020_v1_brdcfg=("ar71xx" "config.${AVA_MACHINE}.mr3020")
- wrt1200ac_brdcfg=("mvebu" "config.${AVA_MACHINE}.wrt1200ac")
- zedboard_brdcfg=("zynq" "config.${AVA_MACHINE}.zedboard")
- orangepi_2_brdcfg=("sunxi" "config.${AVA_MACHINE}.orangepi2")
- which wget > /dev/null && DL_PROG=wget && DL_PARA="-nv -O"
- which curl > /dev/null && DL_PROG=curl && DL_PARA="-L -o"
- # According to http://wiki.openwrt.org/doc/howto/build
- unset SED
- unset GREP_OPTIONS
- [ "`id -u`" == "0" ] && echo "[ERROR]: Please use non-root user" && exit 1
- # Adjust CORE_NUM by yourself
- [ -z "${CORE_NUM}" ] && CORE_NUM="$(expr $(nproc) + 1)"
- DATE=`date +%Y%m%d`
- SCRIPT_FILE="$(readlink -f $0)"
- SCRIPT_DIR=`dirname ${SCRIPT_FILE}`
- ROOT_DIR=${SCRIPT_DIR}/avalon
- OPENWRT_DIR=${ROOT_DIR}/openwrt
- prepare_version() {
- cd ${OPENWRT_DIR}
- GIT_VERSION=`git ls-remote https://github.com/wareck/cgminer-gekko master | cut -f1 | cut -c1-7`
- LUCI_GIT_VERSION=`git --git-dir=./feeds/luci/.git rev-parse HEAD | cut -c1-7`
- OW_GIT_VERSION=`git --git-dir=./feeds/cgminer/.git rev-parse HEAD | cut -c1-7`
- cat > ./files/etc/avalon_version << EOL
- Firmware - $DATE
- luci: $LUCI_GIT_VERSION
- cgminer: $GIT_VERSION
- cgminer-packages: $OW_GIT_VERSION
- EOL
- }
- prepare_config() {
- cd ${OPENWRT_DIR}
- eval OPENWRT_CONFIG=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[1]} && cp ./feeds/cgminer/cgminer/data/${OPENWRT_CONFIG} .config
- }
- prepare_feeds() {
- cd ${OPENWRT_DIR}
- $DL_PROG https://raw.github.com/wareck/gekko-openwrt-packages/master/cgminer/data/${FEEDS_CONF} $DL_PARA feeds.conf && \
- ./scripts/feeds update -a && \
- ./scripts/feeds install -a
- if [ ! -e files ]; then
- ln -s feeds/cgminer/cgminer/root-files files
- fi
- }
- prepare_source() {
- echo "Gen firmware for ${AVA_TARGET_BOARD}:${AVA_MACHINE}"
- echo "TARGET BOARD :${AVA_TARGET_BOARD}"
- echo "TARGET MACHINE :${AVA_MACHINE}"
- cd ${SCRIPT_DIR}
- [ ! -d avalon ] && mkdir -p avalon/bin
- cd avalon
- if [ ! -d openwrt ]; then
- eval OPENWRT_URL=\${${AVA_MACHINE}_owrepo}
- PROTOCOL="`echo ${OPENWRT_URL} | cut -d : -f 1`"
- case "${PROTOCOL}" in
- git)
- GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
- GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
- git clone -b ${GITBRANCH} ${GITREPO} openwrt
- ;;
- svn)
- SVNVER="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
- SVNREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
- svn co ${SVNREPO}@${SVNVER} openwrt
- ;;
- http)
- GITBRANCH="`echo ${OPENWRT_URL} | cut -d @ -f 2`"
- GITREPO="`echo ${OPENWRT_URL} | cut -d @ -f 1`"
- git clone ${GITREPO} openwrt
- ;;
- *)
- echo "Protocol not supported"; exit 1;
- ;;
- esac
- fi
- sed -i -e "s/git:\/\/github.com/https:\/\/github.com/g" openwrt/package/network/services/odhcpd/Makefile
- [ ! -e dl ] && mkdir dl
- cd ${OPENWRT_DIR}
- ln -sf ../dl
- }
- build_image() {
- cd ${OPENWRT_DIR}
- yes "" | make oldconfig > /dev/null
- # clean before build
- make -j${CORE_NUM} clean world
- #make -j${CORE_NUM} world V=s
- }
- build_cgminer() {
- cd ${OPENWRT_DIR}
- rm -f ./dl/cgminer-*.tar.bz2
- yes "" | make oldconfig > /dev/null
- make -j${CORE_NUM} package/cgminer/{clean,compile}
- if [ "$?" == "0" ]; then
- eval AVA_TARGET_PLATFORM=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[0]}
- cd ..
- mkdir -p ./bin/${AVA_TARGET_BOARD}
- cp ./openwrt/bin/${AVA_TARGET_PLATFORM}/packages/cgminer/cgminer*.ipk ./bin/${AVA_TARGET_BOARD}
- fi
- }
- do_release() {
- cd ${ROOT_DIR}
- eval AVA_TARGET_PLATFORM=\${"`echo ${AVA_TARGET_BOARD//-/_}`"_brdcfg[0]}
- mkdir -p ./bin/${DATE}/${AVA_TARGET_BOARD}/
- cp -a ./openwrt/bin/${AVA_TARGET_PLATFORM}/* ./bin/${DATE}/${AVA_TARGET_BOARD}/
- }
- cleanup() {
- cd ${ROOT_DIR}
- rm -rf openwrt/ > /dev/null
- }
- show_help() {
- echo "\
- Usage: $0 [--version] [--help] [--build] [--cgminer] [--cleanup]
- --version
- --help Display help message
- --build Get .config file and build firmware
- --cgminer Re-compile only cgminer openwrt package
- --test Dowload and prebuild files
- --cleanup Remove all files
- AVA_TARGET_BOARD Environment variable, available target:
- tl-wr703n-v1, pi-modelb-v1
- pi-modelb-v2, tl-mr3020-v1
- use pi-modelb-v2 if unset
- AVA_MACHINE Environment variable, available machine:
- avalon6, avalon4, gekko, rockminer
- use avalon6 if unset
- Written by: Xiangfu <xiangfu@openmobilefree.net>
- Fengling <Fengling.Qin@gmail.com>
- wareck <wareck@gmail.com>
- Version: ${SCRIPT_VERSION}"
- }
- if [ "$#" == "0" ]; then
- $0 --help
- exit 0
- fi
- for i in "$@"
- do
- case $i in
- --version|--help)
- show_help
- exit
- ;;
- --build)
- prepare_source && prepare_feeds && prepare_config && prepare_version && build_image && do_release
- ;;
- --cgminer)
- prepare_source && prepare_feeds && prepare_config && prepare_version && build_cgminer
- ;;
- --test)
- prepare_source && prepare_feeds && prepare_config && prepare_version
- ;;
- --cleanup)
- cleanup
- ;;
- *)
- show_help
- exit
- ;;
- esac
- done
|