2 Star 0 Fork 3

guoxiaoqi/check_pkg_install_uninstall_function_service

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
build_indocker.sh 3.84 KB
一键复制 编辑 原始数据 按行查看 历史
root 提交于 2021-11-02 19:28 +08:00 . hide output
#!/bin/bash
pkg=""
pkglist=""
init_path=/root
function parse_params() {
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
cat <<EOF
Usage: bash build_indocker.sh [Options]
Options:
--packages
Specify the package name. The value can be one package or list of packages as format of "pkg1,pkg2,pkg3..."
--path
Specify the path for running the script. The default is /root.
EOF
fi
yum install util-linux -y 2>&1
args=$(getopt -o p: -al packages:,path: -- "$@")
if [ $? -ne 0 ]; then
echo "Terminating..."
exit
fi
eval set -- "${args}"
while [ -n "$1" ]
do
case "$1" in
-p|--packages) pkglist=$2; shift 2;;
--path) init_path=$2; shift 2;;
--) break;;
*) echo "unknown args:${args}"
exit 1
esac
done
}
function check_file_and_dir() {
if [ ! -s "${init_path}"/*.repo ];then
echo "repo file does not exist in docker!"
exit 1
fi
}
function config_yum() {
for file in `ls /etc/yum.repos.d/`
do
mv /etc/yum.repos.d/${file} /etc/yum.repos.d/${file}.bak
done
cp ${init_path}/*repo /etc/yum.repos.d/
if [ $? -ne 0 ]; then
echo "copying yum repo file failed!"
for file in `ls /etc/yum.repos.d/*.bak`
do
old_name=`echo ${file} | sed 's/.bak//g'`
mv ${file} ${old_name}
done
exit 1
fi
yum makecache &>/dev/null
if [ $? -ne 0 ]; then
echo "yum makecache failed!"
exit 1
fi
# prepare basic command packages
echo "Downloading tools for build, please wait..."
yum install rpm-build 'dnf-command(download)' -y &> /dev/null
if [ $? -eq 0 ]; then
echo "Download tools succeed!!"
else
echo "Download tools failed!"
exit 1
fi
}
function check_build()
{
for pkg in ${pkglist//,/ }
do
mkdir -p ${init_path}/build_result/all_srcrpm
# download source rpm
echo "Downloading source rpm of ${pkg}, please wait..."
yum download --source ${pkg} -y > download_src_res 2>&1
if [ $? -eq 0 ] &>/dev/null;then
echo "Download ${pkg} source file succeed!"
echo "${pkg}" >> ${init_path}/build_result/succeed_download_src_list
mkdir -p ${init_path}/build_result/success_log/${pkg}
mv download_src_res ${init_path}/build_result/success_log/${pkg}/
mv ${pkg}*src.rpm ${init_path}/build_result/all_srcrpm/
else
echo "Download ${pkg} source file failed!"
echo "${pkg}" >> ${init_path}/build_result/failed_download_src_list
mkdir -p ${init_path}/build_result/failed_log/${pkg}
mv download_src_res ${init_path}/build_result/failed_log/${pkg}/
continue
fi
# download dependencies
echo "Downloading dependencies of ${pkg}, please wait..."
rpm -ivh ${init_path}/build_result/all_srcrpm/${pkg}*src.rpm > download_dep_res 2>&1
yum-builddep ${init_path}/rpmbuild/SPECS/${pkg}*.spec -y > download_dep_res 2>&1
if [ `cat download_dep_res | grep "Complete!"` == "Complete!" ] &>/dev/null;then
echo "Install ${pkg} build dependencies succeed!"
echo "${pkg}" >> ${init_path}/build_result/succeed_download_dep_list
mv download_dep_res ${init_path}/build_result/success_log/${pkg}/
else
echo "Install ${pkg} build dependencies failed!"
echo "${pkg}" >> ${init_path}/build_result/failed_download_dep_list
mkdir -p ${init_path}/build_result/failed_log/${pkg}
mv download_dep_res ${init_path}/build_result/failed_log/${pkg}/
continue
fi
# start building
echo "Start building ${pkg}, please wait..."
rpmbuild --rebuild ${init_path}/build_result/all_srcrpm/${pkg}*src.rpm > self_build_res 2>&1
if [ $? -eq 0 ]; then
echo "Package ${pkg} build succeed!"
echo "${pkg}" >> ${init_path}/build_result/succeed_build_list
mv self_build_res ${init_path}/build_result/success_log/${pkg}/
else
echo "Package ${pkg} build failed!"
echo "${pkg}" >> ${init_path}/build_result/failed_build_list
mkdir -p ${init_path}/build_result/failed_log/${pkg}
mv self_build_res ${init_path}/build_result/failed_log/${pkg}/
continue
fi
done
}
parse_params $@
config_yum
check_file_and_dir
check_build
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/angela7/check_pkg_install_uninstall_function_service.git
git@gitee.com:angela7/check_pkg_install_uninstall_function_service.git
angela7
check_pkg_install_uninstall_function_service
check_pkg_install_uninstall_function_service
master

搜索帮助

371d5123 14472233 46e8bd33 14472233