#!/bin/bash
|
|
PRJ_PATH=`pwd`
|
PRJ_NAME=`basename $PRJ_PATH`
|
|
# update by top build.sh
|
BOARD=igkboard
|
CROSS_TOOL=/opt/gcc-arm-10.3-2021.07/bin/arm-none-linux-gnueabihf-
|
|
# Source code download address
|
SRV_URL=http://weike-iot.com:2211
|
#SRV_URL=http://127.0.0.1:2211
|
BSP_VER=lf-5.15.32-2.0.0
|
BSP_URL=${SRV_URL}/imx/bsp/${BSP_VER}
|
|
# SYSTEM should be: yocto or debian
|
# DISTRO should be: hardknott, buster
|
# SYSNAME should be: yocto, buster
|
SYSTEM=yocto
|
DISTRO=kirkstone
|
|
TARBALL_DIR=${PRJ_PATH}/../tarballs/
|
|
if [ $SYSTEM == "debian" ] ; then
|
SYSNAME=${DISTRO}
|
else
|
SYSNAME=${SYSTEM}
|
fi
|
|
ROOTFS_DIR=rootfs_${DISTRO}
|
|
JSON_CONF=${PRJ_PATH}/${BOARD}.json
|
JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
|
|
set -u
|
set -e
|
|
# display in red
|
function pr_error() {
|
echo -e "\033[40;31m --E-- $1 \033[0m"
|
}
|
|
# display in yellow
|
function pr_warn() {
|
echo -e "\033[40;33m --W-- $1 \033[0m"
|
}
|
|
# display in green
|
function pr_info() {
|
echo -e "\033[40;32m --I-- $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"
|
|
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)
|
tar -xf $tarball -C $dstpath
|
;;
|
|
*.zip)
|
unzip -qo $tarball -d $dstpath
|
;;
|
|
*)
|
pr_error "decompress Unsupport packet: $tarball"
|
return 1;
|
;;
|
esac
|
}
|
|
# copy a file and decompress it if needed
|
function install_file()
|
{
|
# parameters maybe got variable, use eval to fix it.
|
src=`eval echo $1`
|
dst=`eval echo $2`
|
|
pr_info "install $src => $dst"
|
|
mkdir -p $dst
|
|
if [[ "$src" =~ ".tar" ]] || [[ "$src" =~ ".zip" ]] ; then
|
do_unpack $src ${dst}
|
else
|
rm -rf ${dst}/`basename ${src}`
|
cp -rf `eval ls -d ${src}` ${dst}
|
fi
|
}
|
|
# install all the files specified in JSON configure file
|
function do_install_json()
|
{
|
json_conf=$1
|
json_id=$2
|
|
jq_args=".$json_id | keys[] as \$k | \"\(\$k):\(.[\$k])\""
|
for row in $( jq -r "${jq_args}" $json_conf ) ; do
|
# parser the source file and destination install path
|
src=`echo $row | cut -d: -f1`
|
dst=`echo $row | cut -d: -f2`
|
|
# $src maybe got * to match all the files, use eval to extend it
|
for f in `eval ls -d $src` ; do
|
install_file $f $dst
|
done
|
done
|
}
|
|
# fetch source code by git
|
function do_fetch_git() {
|
url=$1
|
branch=$2
|
dirname=$3
|
|
if [ $branch != "null" ] ; then
|
pr_info "git clone -b ${branch} ${url} ${dirname}"
|
git clone -b ${branch} ${url} ${dirname}
|
else
|
pr_info "git clone ${url} ${dirname}"
|
git clone ${url} ${dirname}
|
fi
|
}
|
|
# fetch source code by wget
|
function do_fetch_wget() {
|
url=`eval echo $1`
|
dirname=$2
|
tarfile=`basename $url`
|
|
mkdir -p ${TARBALL_DIR}
|
|
if [ ! -f ${TARBALL_DIR}/$tarfile ] ; then
|
pr_info "wget $url"
|
|
wget $url -P ${TARBALL_DIR} > /dev/null 2>&1
|
fi
|
do_unpack ${TARBALL_DIR}/$tarfile $dirname
|
}
|
|
# fetch source code by copy
|
function do_fetch_file() {
|
url=`eval echo $1`
|
dirname=$2
|
tarfile=`basename $url`
|
|
cp -rf $url $tarfile
|
|
if [[ "$tarfile" =~ ".tar" ]] || [[ "$tarfile" =~ ".zip" ]] ; then
|
do_unpack $tarfile $dirname
|
fi
|
}
|
|
# parser JSON configure file to find the way to fetch source code
|
function do_fetch_json() {
|
json_conf=$1
|
node_src=$2
|
dirname=$3
|
|
pr_info "start fetch $dirname source code."
|
|
method=`jq -r ".$node_src.PROTOCAL" $json_conf`
|
url=`jq -r ".$node_src.URL" $json_conf`
|
|
if [[ "$method" =~ "git" ]] ; then
|
branch=`jq -r ".$node_src.BRANCH" $json_conf`
|
do_fetch_git $url $branch $dirname
|
elif [[ "$method" =~ "wget" ]] ; then
|
do_fetch_wget $url $dirname
|
elif [[ "$method" =~ "file" ]] ; then
|
do_fetch_file $url $dirname
|
fi
|
}
|