utils/deb_build_incontainer.sh

#!/bin/bash

#cd 到用户的根目录
cd ~
#导出全局变量,给后面的shell使用
export DEBEMAIL=sjtuhjh@hotmail.com
export DEBFULLNAME=Open-Estuary

ppa_test_enable=$5
#字符串判断相等应该用=,不知道这里为啥又用==
#字符串判断前面加x是为了防止null字符串时可能出现的问题
if [ x"${ppa_test_enable}" == x"yes" ] ; then
    echo "Enable PPA test repository"
    add-apt-repository -y ppa:ubuntu-toolchain-r/test
fi
wget -O - http://repo.estuarydev.org/releases/ESTUARY-GPG-KEY | apt-key add -
wget -O - http://repo.linaro.org/ubuntu/linarorepo.key | apt-key add -
wget -O /etc/apt/sources.list.d/estuary.list https://raw.githubusercontent.com/open-estuary/distro-repo/master/estuaryftp_${3}.list

#通过apt-get 更新系统到最新,并安装下面的安装包
apt-get update
apt-get install expect -y
apt-get install automake -y
apt-get install dh-make -y
apt-get install devscripts -y
apt-get install equivs -y
apt-get install dh-systemd -y

echo "DEBSIGN_KEYID=3108CDA4" >> /etc/devscripts.conf
passphrase=$(cat /root/KEY_PASSPHRASE)
gpg --import /root/ESTUARY-GPG-SECURE-KEY

SRC_DIR=$1
TAR_FILENAME=$2
#判断参数${4}是否为零
if [ ! -z "${4}" ] ; then
    export DEB_BUILD_OPTIONS="${4}"
fi
#去掉字符串里面的orig.tar.gz
FILENAME="${TAR_FILENAME%*.orig.tar.gz}"
#如果name相等的话,则给FILENAME 的赋值为TAR_FILENAME 去掉.tar.bz2 后的值
if [ x"${TAR_FILENAME}" == x"${FILENAME}" ] ; then
    FILENAME=${TAR_FILENAME%*.tar.gz}
fi
if [ x"${TAR_FILENAME}" == x"${FILENAME}" ] ; then
    FILENAME=${TAR_FILENAME%*.tar.bz2}
fi
DISTRI=$3
#这里同样是字符串就使用=来判断字符串是否相等
if [ $DISTRI = "debian" ]; then
	DESDIR=debbuild
fi
if [ $DISTRI = "ubuntu" ]; then
	DESDIR=ububuild
fi
# !-d表示不存在目录
if [ ! -d ${SRC_DIR} ]; then
    echo "${SRC_DIR} directory does not exist !"
    exit 1
fi

if [ $TAR_FILENAME = "oprofile-1.1.0.tar.gz" ];then
	apt-get update
	apt-get install default-jdk=2:1.7-52 default-jre=2:1.7-52 default-jre-headless=2:1.7-52 -y
fi

if [ -d /root/${DESDIR}/SOURCES/${FILENAME} ]; then
    echo "${FILENAME} had been builded before, now begin clean the directory."
    rm -rf /root/${DESDIR}/SOURCES/${FILENAME}/*
else
    mkdir -p /root/${DESDIR}/SOURCES/${FILENAME}
fi

#Step1 : Copy necessary files to SOURCES directory
#将SRC_DIR 目录下的所有东西copy到/root/${DESDIR}/SOURCES/${FILENAME}/ 目录下
cp ${SRC_DIR}/* /root/${DESDIR}/SOURCES/${FILENAME}/

#Step2 : Decompress necessary files
cd /root/${DESDIR}/SOURCES/${FILENAME}/
#通过ls *.dsc 来检查是否有以.dsc 结尾的文件,2>/dev/null 用于将ls的结果输入到/dev/null 中
if [ ! -z "$(ls *.dsc 2>/dev/null)" ] ; then
    dpkg-source --no-check -x *.dsc
else
#通过echo 来检查TAR_FILENAME 中是否以tar.bz2 结尾,这里为啥不用字符串截取呢?
    if [ ! -z "$(echo ${TAR_FILENAME} | grep 'tar.bz2')" ] ; then
        tar -jxvf /root/${DESDIR}/SOURCES/${FILENAME}/${TAR_FILENAME} -C /root/${DESDIR}/SOURCES/${FILENAME}/
    else 
        tar -zxvf /root/${DESDIR}/SOURCES/${FILENAME}/${TAR_FILENAME} -C /root/${DESDIR}/SOURCES/${FILENAME}/
    fi
fi

SUBDIR=""
for filename in /root/${DESDIR}/SOURCES/${FILENAME}/*
do
#scan 目录的时候要去掉对.和..的判断
    if [ x"${filename}" == x"." ] || [ x"${filename}" == x".." ] ; then
        continue
    fi

    if [ -d ${filename} ] ; then
        SUBDIR=${filename}
        break
    fi
done
#通过tar打包
if [ -f /root/${DESDIR}/SOURCES/${FILENAME}/debian.tar.gz ] ; then
    tar -zxvf /root/${DESDIR}/SOURCES/${FILENAME}/debian.tar.gz -C ${SUBDIR}/
fi

#Step3: Build deb packages
cd ${SUBDIR}
dh_make -s --copyright gpl2 -f ../${TAR_FILENAME} -y
#apt-get build-dep ${FILENAME} -y
if [ $TAR_FILENAME = "linux-4.9.20.estuary.3.1.tar.gz" ];then
        apt-get update
        apt-get install bc gcc-4.9 quilt kernel-wedge libssl-dev asciidoc xmlto bison flex libaudit-dev libdw-dev libelf-dev libiberty-dev libnewt-dev libnuma-dev libperl-dev libunwind8-dev python-dev libtool libglib2.0-dev libudev-dev libwrap0-dev libpci-dev dh-systemd python-sphinx python-sphinx-rtd-theme -y
else
	mk-build-deps -i -t 'apt-get -y' debian/control
	rm *build-deps*.deb
fi
#执行debuild的时候需要输入,所以这里用expect
expect <<-END
        set timeout -1
        spawn debuild --no-tgz-check -j32
        expect {
                "Enter passphrase:" {send "${passphrase}\r"}
                timeout {send_user "Enter pass phrase timeout\n"}
        }
        expect {
                "Enter passphrase:" {send "${passphrase}\r"}
                timeout {send_user "Enter pass phrase timeout\n"}
        }
        expect eof
END
#判断没有目录就新建
if [ ! -d /root/${DESDIR}/DEBS ]; then
        mkdir -p /root/${DESDIR}/DEBS
fi

if [ ! -d /root/${DESDIR}/SDEBS ]; then
        mkdir -p /root/${DESDIR}/SDEBS
fi

if [ ! -d /root/${DESDIR}/BUILDS ]; then
        mkdir -p /root/${DESDIR}/BUILDS
fi

if [ ! -d /root/${DESDIR}/CHANGES ]; then
        mkdir -p /root/${DESDIR}/CHANGES
fi
#将不用的后缀名的文件copy到不同的文件夹中.
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.deb /root/${DESDIR}/DEBS/
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.udeb /root/${DESDIR}/DEBS/
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.dsc /root/${DESDIR}/SDEBS/
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.orig.tar.gz /root/${DESDIR}/SDEBS/
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.debian.tar.xz /root/${DESDIR}/SDEBS/
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.build /root/${DESDIR}/BUILDS/
cp /root/${DESDIR}/SOURCES/${FILENAME}/*.changes /root/${DESDIR}/CHANGES/

echo "Build has done, Please check deb under ~/${DESDIR}/DEBS/ or ~/${DESDIR}/SDEBS/ directory !"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值