操作系统: raspbian/debian

制作如下目录及文件

mydeb    
|----DEBIAN
   |------- control           (描述文件)
   |------- postinst          (安装后执行有脚本)
   |------- postrm            (卸载时执行的脚本)
|---- usr/local/bin               
   |----- helloworld.sh       (待安装的文件)
|---- lib/systemd/system               
   |----- helloworld.service  (启动服务,可选)

control文件 内容如下:

Package: helloworld
Version: 1.0                
Section: free             
Prioritt: optional        
Architecture: armhf      
Maintainer: admin@oroct.com        
Description: make deb package example

postinst文件: 软件安装后执行的脚本(可选)

# !/bin/sh
echo "install mydeb" >> /var/log/mydeb.log

postrm文件:软件删除后执行的脚本(可选)

# !/bin/sh
echo "remove mydeb" >> /var/log/mydeb.log

生成deb安装包: 第一个参数为将要打包的目录名,第二个参数为生成包的名称

$ dpkg -b mydeb mydeb.deb

安装测试:

$ dpkg -i  mydeb.deb

删除测试:

$ dpkg -r  mydeb.deb

一键创建相关文件脚本:

#!/bin/sh
PKGNAME=helloworld 
VERSION=1.0

# 创建相关目录
if [ ! -d DEBIAN ] ; then 
    mkdir DEBIAN 
fi
if [ ! -d usr/local/bin ] ; then 
    mkdir -p usr/local/bin
fi
if [ ! -d lib/systemd/system ] ; then 
    mkdir -p lib/systemd/system
fi

# 创建相关文件
echo "#!/bin/sh" > DEBIAN/postinst
echo "systemctl enable ${PKGNAME}.service" >> DEBIAN/postinst
echo "systemctl start ${PKGNAME}.service"  >> DEBIAN/postinst

echo "#!/bin/sh" > DEBIAN/postrm
echo "systemctl stop ${PKGNAME}.service"    >> DEBIAN/postrm
echo "systemctl disable ${PKGNAME}.service" >> DEBIAN/postrm

echo "Package: ${PKGNAME}"   > DEBIAN/control
echo "Version: ${VERSION}"  >> DEBIAN/control               
echo "Section: free "       >> DEBIAN/control            
echo "Prioritt: optional"   >> DEBIAN/control       
echo "Architecture: armhf"  >> DEBIAN/control     
echo "Maintainer: admin@oroct.com" >> DEBIAN/control      
echo "Description: " >> DEBIAN/control

https://www.cnblogs.com/xiang--liu/p/12994429.html