utils/deb_build.sh

#!/bin/bash

#得到当前目录
CUR_DIR=$(cd `dirname $0`; pwd)

usage()
{
        echo "Usage: deb_build.sh srcdir tarfile debian/ubuntu"
}

if [ $# -lt 3 ]; then
	usage
	exit 1
fi

#configure build enviroment
sudo sh ${CUR_DIR}/config.sh
#通过票键得到service  这个命令的结果来来判断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/debian"| grep "latest" | awk '{print $3}'`

SRC_DIR_1=$1
#从左向右截取第一个string右的字符串
#
#[root@localhost ~]# SRC_DIR_1="123/456/789"
#[root@localhost ~]# echo $SRC_DIR_1
#123/456/789
#[root@localhost ~]# echo ${SRC_DIR_1#*/}
#456/789

#这里的意思就是从左向右第一个/之后的字符串
SRC_DIR_2=${SRC_DIR_1#*/}
SRC_DIR_3=${SRC_DIR_2#*/}
SRC_DIR_4=${SRC_DIR_3#*/}
TAR_FILENAME=$2
DISTRI=$3
BUILD_OPTIONS=$4
PPA_TEST_ENABLE=$5
#[root@localhost ~]# TAR_FILENAME="12-32-56"
#[root@localhost ~]# echo ${TAR_FILENAME%-*}
#12-32
#这里的% 表示从右向左第一个-之后的字符串
CONTAINER_NAME=${TAR_FILENAME%-*}-$DISTRI

# 这一句的作用是干啥??
CONTAINER_NAME=${CONTAINER_NAME/+/}

#如果不存在则copy 过去
if [ ! -f ~/KEY_PASSPHRASE ] ; then
    cp /home/KEY_PASSPHRASE  ~/KEY_PASSPHRASE
fi
#根据发行版不同来运行docker ,这里用=来判断字符串是否相等
#docker run 对参数的继续如下:简单的解释就是在docker中运行deb_build_incontainer.sh ,后面指定这个基本的参数
--network string              Connect a container to a network (default "default")
-d, --detach                      Run container in background and print container ID
--name string                 Assign a name to the container
  -v, --volume value                Bind mount a volume (default [])

if [ $DISTRI = "debian" ]; then
	docker run --network=host -d -v ~/:/root/ --name ${CONTAINER_NAME} openestuary/debian:3.1-full bash /root/distro-repo/utils/deb_build_incontainer.sh /root/${SRC_DIR_4} ${TAR_FILENAME} ${DISTRI} "${BUILD_OPTIONS}" "${PPA_TEST_ENABLE}"
elif [ $DISTRI = "ubuntu" ]; then
	docker run --network=host -d -v ~/:/root/ --name ${CONTAINER_NAME} openestuary/ubuntu:3.1-full bash /root/distro-repo/utils/deb_build_incontainer.sh /root/${SRC_DIR_4} ${TAR_FILENAME} ${DISTRI} "${BUILD_OPTIONS}" "${PPA_TEST_ENABLE}"
fi


#  -f, --follow         Follow log output

docker logs -f ${CONTAINER_NAME}
#通过echo输出log
echo "Begin to remove building container."
#删除这个docker
docker rm ${CONTAINER_NAME}
#判断docker 删除是否成功.
if [ $? -ne 0 ]; then
        echo "Remove building container failed!"
else
        echo "Building container have been removed successfully!"
fi

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值