专用机deb 脚本打包

#!/bin/bash
#Author: haodongzhang
#Date: 6/16/2021
#Version: 1.1
#Function: 快速制作不同平台deb安装包


clear
function cecho {
echo -e "33[$1m$233[0m"
#fonts color: 31-red;32-green;36-deepgreen;34-blue;
}

###########################选择菜单##################################
function menu {
read -p "请输入即将要制作的包名:" softname
read -p "请输入即将要制作的包的版本:" version

cat <<EOF
*************************************************************
1) mips64el platform
2) amd64 platform
3) i386 platform
4) arm64 platform
5) all platform
6) exit
*************************************************************
EOF

read -p "请选择你要制作什么平台的安装包:" platform
case $platform in
1)
platform=mips64el;;
2)
platform=amd64;;
3)
platform=i386;;
4)
platform=arm64;;
5)
platform=all;;
6)
cecho 32 Byebye
exit;;
*)
cecho 31 "选择有误,程序将退出,请重新选择!"
exit;;
esac
}

###################################编写control文件#####################################
function make-control {
mkdir -p debian/
touch debian/{control,postinst,preinst,postrm,prerm,install,rules,changelog,compat}
chmod -R 0775 debian/{postinst,preinst,postrm,prerm,rules}
chmod -R a-x debian/install
cat >debian/control<<EOF
Source: $softname
Section: unknown
Priority: optional
Maintainer: none <xxx@xxx.xx>
Build-Depends: debhelper (>= 9)
Standards-Version: 3.9.8
#Homepage: <insert the upstream URL, if relevant>


Package: $softname
Architecture: $platform
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: this package is made by autotools!
EOF

##################### 生成install文件 ##############################################
files=`ls -a`
echo "" > debian/install
for f in $files
do
if [ "$f" != "." -a "$f" != ".." -a "$f" != "debian" ];then
if [ -d $f ];then
echo "$f/* /$f" >> debian/install
else
echo "$f /" >> debian/install
fi
fi
done


##################### 生成rules文件 #################################

cat >debian/rules<<EOF
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
dh $@


# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

EOF

echo 9 > debian/compat
####################### 生成changelog #####################################################
cat >debian/changelog<<EOF
$softname ($version) 3.0; urgency=medium

* here is some changes.

-- none <xxx@xxx.xx> Thur, 13 Mar 2021 13:32:27 +0800

EOF
}
####################################主程序编包#########################################

function make-soft {
dpkg-buildpackage
}

cat <<EOF


***************使用说明**********************************************************

新建一个文件夹,比如 mkdir testdir,然后将需要导入系统的文件(夹)放入此文件夹下,文件层次与安装路径保持一致.
例如我要将test.sh安装到系统的 /usr/bin/目录下,那么就在testdir路径下新建usr/bin/文件夹,然后将test.sh
放到testdir/usr/bin/ 目录下。
然后执行此脚本,将testdir 路径作为参数传给脚本,即 ./automake-deb-package.sh testdir/
最后生成的软件包在当前路径下。

*******************************************************************************

EOF

read -p "是否继续 [Y/N]? " yn
while true; do
case $yn in
[Yy]|[Yy][Ee][Ss] )
break
;;

* )
exit
;;
esac
done

if [ "$#" != "1" ];then
cecho 31 "请将源码路径作为参数输入!"
exit
fi

cecho
menu
mkdir -p ~/mypackage/$softname
cd ~/mypackage/$softname/
cp -rf $1/* ~/mypackage/$softname/
make-control
make-soft

cd -
cp ~/mypackage/*.deb ./

rm -rf ~/mypackage

本文来自博客园,作者:zwbsoft,转载请注明原文链接:https://www.cnblogs.com/zwbsoft/p/15413463.html

电话微信:13514280351
原文地址:https://www.cnblogs.com/zwbsoft/p/15413463.html