Skip to content

Shell script debian package

pack minimal shell script to debian package using fakeroot / dpkg-buildpackage

fakeroot / dpkg-buildpackage

When i use dpkg-buildpackage the build process end with error that for now i don't found a solution
the `fakeroot debian/rules binary run the build process without error

.
├── debs
│   ├── settings.json
│   └── tasks.json
├── debian
│   ├── changelog
│   ├── compat
│   ├── control
│   ├── my-tool.install
│   └── rules
├── debs
├── readme.md
├── .gitignore
└── scripts
    └── my-tool.sh
scripts/my-tool
1
2
3
#!/bin/sh

echo "hello my-tool"

debian folder

Using fakeroot/dpkg-buildpackage debian folder must contain few files:

  • rules
  • changelog
  • control
  • my-tool.install

my-tool.install

Mapping file from project to filesystem location for example

debian/my-tool.install
scripts/my-tools.sh /usr/local/bin

external file

We can place file from external project folder relative to project root

../external /usr/local/bin

changelog

dch command create and update changelog file

dch --create -v 0.0.1 --package my-tool "v 0.0.1"
dch -v 0.0.1 "simple script"

Note

Using dch command we update the version my-tool (0.0.2) UNRELEASED; urgency=medium

This version use to set the debian version

dch -v 0.0.2 "simple script ver 2"

changelog

changelog
1
2
3
4
5
6
my-tool (0.0.2) UNRELEASED; urgency=medium

* version 0.0.1
* simple script ver 2

-- user <user@lap>  Tue, 29 Apr 2025 21:14:15 +0300

control

Source: my-tool
Section: misc
Priority: optional
Maintainer: Your Name <youremail@example.com>
Standards-Version: 4.6.2

Package: my-tool
Architecture: all
Description: Minimal Debian package
 A short description of the minimal Debian package.

rules

#!/usr/bin/make -f

%:
    dh $@

override_dh_builddeb:
    dh_builddeb --destdir=$(CURDIR)/debs

override_dh_fixperms:
    dh_fixperms
    chmod 777 debian/my-tool/tmp/demo.sh
change deb output path (debs folder must be exists)
override_dh_builddeb:
    dh_builddeb --destdir=$(CURDIR)/debs
set permissions
1
2
3
override_dh_fixperms:
    dh_fixperms
    chmod 777 debian/my-tool/usr/local/bin/demo.sh

build

1
2
3
fakeroot debian/rules binary
# or 
dpkg-buildpackage -us -uc

clean

fakeroot debian/rules clean

VSCode

tasks.json

  • build using fakeroot debian/rules binary
  • clean fakeroot debian/rules clean
  • update change log using dch
tasks.json
{
    // See https://code.visualstudio.com/docs/editor/tasks for more information
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Debian Package",
            "type": "shell",
            "command": "fakeroot debian/rules binary",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        },
        {
            "label": "Clean",
            "type": "shell",
            "command": "fakeroot debian/rules clean",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": []
        },
        {
            "label": "Update Changelog with dch",
            "type": "shell",
            "command": "dch --newversion ${input:changelogVersion} $(git log -1 --pretty=format:'* %s')",
            "options": {
                "cwd": "${workspaceFolder}",
                "env": {
                    "DEBEMAIL": "dev@example.com",
                    "DEBFULLNAME": "dev com"
                }
            },
            "problemMatcher": []
        }
    ],
    "inputs": [
        {
            "id": "changelogVersion",
            "type": "promptString",
            "description": "Enter the new version for dch"
        }
    ]
}

the demo use git log -1 --pretty=format:'* %s') as demo to get changes from last commit it's batter to get the commits from last tag using git log v1.2.0..v1.3.0 --pretty=format:"* %s"

setting.json

Replace indentation from space to tab when using sheelscript

  • mark rule as shellscript if fail on autodetect
  • check if associate it with makefile still the indention rule for shellscript working
settings.json
1
2
3
"files.associations": {
    "rules": "makefile"
}
settings.json
1
2
3
4
5
6
7
{
    "[shellscript]": {
        "editor.insertSpaces": false,
        "editor.tabSize": 4,
        "editor.detectIndentation": false
    },
}

using cat to check TAB indentation

cat -T <file>

Git

.gitignore

1
2
3
4
5
6
7
debs/
debian/*
!debian/changelog
!debian/rules
!debian/control
!debian/compat
!debian/my-tool.install

exclude file from ignore folder, for it to work we need to ignore files in folder and not the folder it self debian/*