1. 程式人生 > 其它 >專用機deb 指令碼打包

專用機deb 指令碼打包

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


clear
function cecho {
echo -e "\033[$1m$2\033[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 <[email protected]>
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 <[email protected]> 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