构建工具dh_make
准备构建文件包含:prerm、postrm、preinst、postinst、install、control、changlog、rules另外一个syncthing执行程序。
- vi ~/.bashrc,加入以下三行:
DEBFULLNAME="包名称任取"
DEBEMAIL="邮箱地址"
export DEBFULLNAME DEBEMAIL
创建构建包目录
syncthingdeb
|____syncthing-1.7.1
| |_____syncthing #执行文件
|——debian
|____syncthing@.service
注意:syncthing-1.7.1代表<package>-<version>,dh_make工具需求。
切换到syncthingdeb目录下执行
dh_make --createorig -s
在syncthing-1.7.1同级目录边生成debian目录,里面包含开篇我们需要的各种文件,但我们需要根据自己需求更改。
changlog文件自动生成好基本无需更改,可以看下里面有版本号与1.7.1对应,还有电子邮箱即前面环境变量中信息。也可自行修改。
control文件:
Architecture 属性填些适应平台,我这里写amd64
Description属性是软件描述,我这里写sync thing tool
rules文件:
找到
%:
dh $@
在下面添加三行命令:
%:
dh $@
override_dh_auto_build:
override_dh_shlibdeps:
override_dh_strip:
prerm.ex文件为预删除前处理,这里无需求不做修改。
postrm.ex文件删除过程处理
找到条件判断句,类似switch判断
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
修改成
case "$1" in
remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;
purge)
#获取设备名称可根据用户自行修改
#hn=`hostname`
#un=${hn,,}
hn=`whoami`
un=$(echo $hn | tr '[A-Z]' '[a-z]')
systemctl --no-reload disable --now syncthing@$un.service > /dev/null 2>&1 || :
rm -f /usr/bin/syncthing
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
preinst.ex文件预安装处理,无需求不修改。
postinst.ex文件安装处理
找到
configure)
修改为
configure)
#获取设备名称可根据用户自行修改
#hn=`hostname`
#un=${hn,,}
hn=`whoami`
un=$(echo $hn | tr '[A-Z]' '[a-z]')
#chown -R $un:$un /opt/latentrans/
chmod a+x /usr/bin/syncthing
systemctl --no-reload enable syncthing@$un.service >/dev/null 2>&1 || :
service syncthing@$un start
;;
install文件内指令在旧程序卸载与新程序安装之间运行。
在debian目录内创建文件install,内容为:
syncthing/syncthing /usr/bin
syncthing@.service /lib/systemd/system/
syncthing@.service文件是提供syncthing服务启动文件
在syncthing同级目录下创建syncthing@.service,内容:
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target
[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
# Hardening
ProtectSystem=full
PrivateTmp=true
SystemCallArchitectures=native
MemoryDenyWriteExecute=true
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
在syncthing-1.7.1目录下执行生成debian包描述文件
dpkg-source -b ./ #生成debian包描述文件
dpkg-buildpackage #打包文件
上条命令若失败,则用 sudo dpkg-buildpackage -uc -us
在syncthingdeb目录下生成syncthing_1.7.1-1_amd64.deb安装文件。
本文详细介绍了使用dh_make工具构建Debian包的过程,包括环境变量设置、构建目录创建、文件编辑及打包命令。涵盖control、rules等关键文件的配置与修改。
1286

被折叠的 条评论
为什么被折叠?



