本地build包并自动解决依赖的shell代码

发布时间:2019-12-13编辑:脚本学堂
本地build包并自动解决依赖的shell代码,不可错过哦。

本地build包并自动解决依赖的shell代码,不可错过哦。
 

复制代码 代码如下:

#!/bin/bash
# 本地build包并自动解决依赖
# link:www.jb200.com
# date:2013/2/26

clear
ls /root/rpmbuild/SPECS/ > /home/spec-auto.list
cd /root/rpmbuild/SPECS/
####build error info
mkdir /home/Ero/
####build log
mkdir /home/log/
####put spec that successed
mkdir /home/spec/

linuxjishu/13830.html target=_blank class=infotextkey>awk '{print NR, $1}' /home/spec-auto.list > /home/test.list
i=2
n=1
m=0
k=0
tmp=`ls /root/rpmbuild/SPECS|wc -l`
num=$(($tmp+2))
echo "There have $tmp specs;Auto-locabuild start!"

while [ $i != $num ]
do
    obj=`awk -v j=$n '$1==j{print $2}' /home/test.list`
    echo ""
    Time=`date +%Y-%m-%d---%R`
    echo "[$Time]---------[$tmp:$n]"
    echo "$obj"
    rpmbuild -ba $obj &>/home/log/$obj.log
    if [ $? != 0 ];
    then
# echo "Failed!!!!XXXX"
# tail -n 20 /home/log/$obj.log
# add auto yum pakg and rebuild,back results
        cat /home/log/$obj.log |while read line
        do
            echo "$line" &> /line.list
            two=`awk '{print $2}' /line.list`
            one=`awk '{print $1}' /line.list`
            if [ "$two" == "is" ];then
                yum install $one -y &> /dev/null
            elif [ "$two" == ">=" ];then
                yum install $one -y &> /dev/null
            else
                echo "" &> /dev/null
            fi
        done
        rpmbuild -ba $obj &>/home/log/$obj.log
        if [ $? != 0 ];
        then
            echo "Failed!!!!XXXX"
            tail -n 20 /home/log/$obj.log
            echo "$obj " &>> /home/Ero/ero.log
            m=$(($m+1))
        else
            echo "Succssed!!"
            rm -rf /home/log/$obj.log
            mv /root/rpmbuild/SPECS/$obj /home/spec/
        fi
#---------------------------------------------
#       echo "$obj " &>> /home/Ero/ero.log
#       m=$(($m+1))
    else
        echo "Succssed!!"
        rm -rf /home/log/$obj.log
        mv /root/rpmbuild/SPECS/$obj /home/spec/
    fi
    i=$(($i+1))
    n=$(($n+1))
done

k=$(($tmp-$m))
echo ""
echo ""
echo "-------------------------------------------- "
echo "[total:$tmp   succeeded:$k    failed:$m] "
echo ""
if [ $m != 0 ];
then
    awk '{print NR, $1}' /home/Ero/ero.log > /home/Ero/ero.nr.log
    echo "See the Errorinfo at /home/log/*.spec.log, and The following is failed list:"
    cat /home/Ero/ero.nr.log
else
    echo "Congratulations!! All build succssed!!"
fi
echo "---------------------------------------------- "
rm -rf /home/spec-auto.list /home/test.list /home/Ero /line/list
echo -n "End!"
echo ""