dh_make构建deb包

构建工具dh_make

准备构建文件包含:prerm、postrm、preinst、postinst、install、control、changlog、rules另外一个syncthing执行程序。

  1. 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安装文件。

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值