#!/bin/bash
#赋值当前目录,也可以用'./'赋值为当前目录
CUR_DIR=$(cd `dirname $0`; pwd)
#定义一个函数,说明这个脚本的用法.
usage()
{
echo "Usage: rpm_build.sh srcdir spec "
}
#形参个数小于2,则退出
if [ $# -lt 2 ]; then
usage
exit 1
fi
#configure build enviroment
#通过sh执行脚本
sudo sh ${CUR_DIR}/config.sh
#判断docker 是否运行正常,如果不正常的话,重新启动docker 服务器。这里通过飘键得到执行的结果
docker_status=`service docker status | grep "inactive" | awk '{print $2}'`
if [ ! -z ${docker_status} ]; then
echo "Docker service is inactive, begin to start docker service"
sudo service docker start
if [ $? -ne 0 ] ; then
echo "Starting docker service failed!"
exit 1
else
echo "Docker service start sucessfully!"
fi
fi
echo "Start container to build."
#Image_ID=`docker images | grep "openestuary/centos"| grep "latest" | awk '{print $3}'`
# id参数 -g, --group print only the effective group ID
# id参数 -u, --user print only the effective user ID
uid=`id -u`
gid=`id -g`
SRC_DIR_1=$1
#下面这一段是字符串的截取,之前已经分析过
SRC_DIR_2=${SRC_DIR_1#*/}
SRC_DIR_3=${SRC_DIR_2#*/}
SRC_DIR_4=${SRC_DIR_3#*/}
SPEC_NAME=$2
CONTAINER_NAME=${SPEC_NAME%.*}
#下面这句不知道啥意思?
CONTAINER_NAME=${CONTAINER_NAME/+/}
#如果key 不存在就copy 过去
if [ ! -f ~/KEY_PASSPHRASE ] ; then
cp /home/KEY_PASSPHRASE ~/KEY_PASSPHRASE
fi
执行dcoker ,并输出log到文件中
docker run --network=host -d -v ~/:/root/ --name ${CONTAINER_NAME} openestuary/centos:5.0-full bash /root/distro-repo/utils/rpm_build_incontainer.sh /root/${SRC_DIR_4} ${SPEC_NAME} ${uid} ${gid} ${@:3}
#bash ~/distro-repo/utils/rpm_build_incontainer.sh ~/${SRC_DIR_4} ${SPEC_NAME} ${uid} ${gid} ${@:3}
docker logs -f ${CONTAINER_NAME}
echo "Begin to remove building container."
删除docker,并通过$? 返回值判断输出是否成功
docker rm ${CONTAINER_NAME}
if [ $? -ne 0 ]; then
echo "Remove building container failed!"
else
echo "Building container have been removed successfully!"
fi
utils/rpm_build.sh
最新推荐文章于 2022-03-03 14:49:12 发布