#!/bin/bash # board BOARD=igkboard-rk3576 # openwrt branch BRANCH=openwrt-25.12 #openwrt url GITURL=https://github.com/openwrt/openwrt.git # this project absolute path PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) # binaries build prefix install path PRFX_PATH=$PRJ_PATH/install # binaries finally install path if needed #INST_PATH=/tftp # config file path CONF_FILE=$PRJ_PATH/config.json # shell script will exit once get command error set -e #+-------------------------+ #| Shell script functions | #+-------------------------+ function pr_error() { echo -e "\033[40;31m $1 \033[0m" } function pr_warn() { echo -e "\033[40;33m $1 \033[0m" } function pr_info() { echo -e "\033[40;32m $1 \033[0m" } # decompress a packet to destination path function do_unpack() { tarball=$1 dstpath=`pwd` if [[ $# == 2 ]] ; then dstpath=$2 fi pr_info "decompress $tarball => $dstpath" mkdir -p $dstpath case $tarball in *.tar.gz) tar -xzf $tarball -C $dstpath ;; *.tar.bz2) tar -xjf $tarball -C $dstpath ;; *.tar.xz) tar -xJf $tarball -C $dstpath ;; *.tar.zst) tar -I zstd -xf $tarball -C $dstpath ;; *.tar) tar -xf $tarball -C $dstpath ;; *.zip) unzip -qo $tarball -d $dstpath ;; *) pr_error "decompress Unsupport packet: $tarball" return 1; ;; esac } # parser configure file and export environment variable function do_export() { export SDK=$BRANCH } function do_fetch() { cd $PRJ_PATH if [ -f $SDK/Makefile ] ; then pr_info "$SDK source code fetched already" return 0; fi pr_info "start fetch source code" git clone $GITURL -b $BRANCH $SDK --depth=1 cd $SDK && pwd sed -i 's#https://git.openwrt.org/feed/#https://github.com/openwrt/#g' feeds.conf.default sed -i 's#https://git.openwrt.org/project/#https://github.com/openwrt/#g' feeds.conf.default sed -i 's#https://git.openwrt.org/#https://github.com/openwrt/#g' feeds.conf.default pr_info "start feeds update and install " ./scripts/feeds update -a ./scripts/feeds install -a } function do_patch() { PATCH_FILE=$PRJ_PATH/patch/${BRANCH}-${BOARD}.patch cd $PRJ_PATH/$SDK if [ ! -f patched.tag ] ; then pr_info "do patch $(basename $PATCH_FILE)" patch -p1 < $PATCH_FILE fi } function do_build() { DEF_CONFIG=.${BOARD}.defconfig IMAGE_PATH=bin/targets/*/*/ cd $PRJ_PATH/$SDK pr_info "make defconfig: $DEF_CONFIG" cp $DEF_CONFIG .config echo "" pr_warn "startu build..." #make V=s -j$(nproc) make -j1 echo "" pr_warn "output images path: $IMAGE_PATH" ls $IMAGE_PATH echo "" } function do_clean() { cd $WKSP/SDK && pwd pr_warn "start clean" make clean } #+-------------------------+ #| Shell script body entry | #+-------------------------+ do_export if [[ $# == 1 && $1 == -c ]] ;then do_clean exit; fi pr_warn "start build $SDK SDK for ${BOARD}" do_fetch do_patch do_build