shell自动编译脚本

#!/bin/bash

###############################   Script configuration area start  ###################################
CODE_PATH="repo init -u buic-scm:gm/manifest -b gm-imx8-phantom-gm-3.y -g all --repo-url=buic-scm:IIC_SW_Tools/git-repo --repo-branch=stable-conti --no-repo-verify"
BUILD_PROJECT=imx8-phantom-gm
###############################   Script configuration area stop  ####################################



###############################   Script code area start  ############################################

WsRootDir=`pwd`
SELF_NAME=$0

function delete_all()
{
    notify_start "delete_all"
    
    mkdir ./.backup
    
    if [ -f ./A35_Auto_build_script.sh ]; then    
        cp ./A35_Auto_build_script.sh ./.backup/
    fi

    if [ -f ./Auto_build.log ]; then    
        cp ./Auto_build.log ./.backup/
    fi

    rm -rf *

    if [ -d ./.repo ]; then
        rm -rf ./.repo
    fi
    
    cp ./.backup/* ./
    rm -rf ./.backup
    
    notify_done "delete_all"
}

function download_code()
{
    notify_start "download_code"

$CODE_PATH << EOF
EOF
    repo sync -j4
    repo sync -j4
    return 1
}

function update_code()
{
    notify_start "update_code"
    if [ ! -d ./.repo ]; then
        echo "$(date +%Y-%m-%d_%H:%M:%S) This code is not complete, Miss .repo">>Auto_build.log
        return 0
    fi
    
    repo forall -c 'git clean -df'
    repo forall -c 'git checkout .'
    repo sync -j4

    return 1
}

function build_code()
{
    notify_start "build_code"
    if [ ! -d ./.repo ]; then
        echo "$(date +%Y-%m-%d_%H:%M:%S) This code is not complete, Miss .repo">>Auto_build.log
        return 0
    fi

    make M=1 clobber CAS_TARGET_HW=$BUILD_PROJECT
    make image-4k CAS_TARGET_HW=$BUILD_PROJECT
    return 1
}

function notify_error()
{
    echo    "##############################################################################"
    echo -e "\033[31m $1 ERROR!!! ERROR!!! ERROR!!! ERROR!!! ERROR!!! ERROR!!! ERROR!!!\033[0m"
    echo    "##############################################################################"

    echo "$(date +%Y-%m-%d_%H:%M:%S) $1 ERROR">>Auto_build.log
}

function notify_start()
{
    echo "/****************************************************************************/"
    echo "/*                          $1 start"
    echo "/****************************************************************************/"

    echo "$(date +%Y-%m-%d_%H:%M:%S) $1 start">>Auto_build.log
}

function notify_done()
{
    echo "/****************************************************************************/"
    echo "/*                          $1 done"
    echo "/****************************************************************************/"

    echo "$(date +%Y-%m-%d_%H:%M:%S) $1 done">>Auto_build.log
}

function check_var()
{
case $1 in
    1) result=1 ;;
    2) result=1 ;;
    3) result=1 ;;
    4) result=1 ;;
    *) result=0 ;;
esac

return $result
}

function is_exist()
{
case $1 in
    $var_1) result=1 ;;
    $var_2) result=1 ;;
    $var_3) result=1 ;;
    $var_4) result=1 ;;
    *) result=0 ;;
esac

return $result
}

function main()
{
echo -e "\033[36m/****************************************************************************/\033[0m"
echo -e "\033[36m/*                                                                 */\033[0m"
echo -e "\033[36m/*                               Auto Build                         */\033[0m"
echo -e "\033[36m/*                                        ---V1.0 by zhangheting      */\033[0m"
echo -e "\033[36m/*                                                                 */\033[0m"
echo -e "\033[36m/****************************************************************************/\033[0m"

echo ""

echo -e  "\033[32m##############################################################################\033[0m"
echo -e  "\033[32m#code path   : $CODE_PATH\033[0m"
echo -e  "\033[32m#project     : $BUILD_PROJECT\033[0m"
echo -e  "\033[32m##############################################################################\033[0m"

echo ""

if [ ! -f Auto_build.log ]; then
:>Auto_build.log
fi
echo "">>Auto_build.log
echo "">>Auto_build.log
echo "#########################################################">>Auto_build.log
echo "$(date +%Y-%m-%d_%H:%M:%S) build time">>Auto_build.log

echo "1. only download code"
echo "2. clean and update code"
echo "3. only build code"
echo -e "\033[31m4. delete all\033[0m"

read "var_1" "var_2"

echo "input command : $var_1 -- $var_2">>Auto_build.log

check_var $var_1
res_var=$?
if [ $res_var = "0" ] ; then
var_1=""
fi

check_var $var_2
res_var=$?
if [ $res_var = "0" ] ; then
var_2=""
fi

echo "valid command : $var_1 -- $var_2">>Auto_build.log

is_exist 1
res_exist=$?
if [ $res_exist = "1" ] ; then
{
    download_code
    res_var=$?
    if [ $res_var = "0" ] ; then
        notify_error "download_code"
        return;
    fi
}
fi

is_exist 2
res_exist=$?
if [ $res_exist = "1" ] ; then
{
    update_code
    res_var=$?
    if [ $res_var = "0" ] ; then
        notify_error "update_code"
        return;
    fi
}
fi

is_exist 3
res_exist=$?
if [ $res_exist = "1" ] ; then
{
    build_code
    res_var=$?
    if [ $res_var = "0" ] ; then
        notify_error "build_code"
        return;
    fi
}
fi

is_exist 4
res_exist=$?
if [ $res_exist = "1" ] ; then
    delete_all
fi

}

main $1 $2

###############################   Script code area stop  ############################################

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AllenSun-1990

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值