Skip to content

Instantly share code, notes, and snippets.

@sudheerit11
Last active April 10, 2020 02:46
Show Gist options
  • Save sudheerit11/341d78e2a416756b374e93d44a9afdc1 to your computer and use it in GitHub Desktop.
Save sudheerit11/341d78e2a416756b374e93d44a9afdc1 to your computer and use it in GitHub Desktop.
Build deb package
## Build deb package
These steps include basic minimum requirement to build a deb package.
Before we start building a package lets make few assumption which will make these steps more easily understandable.
Assumptions:
```bash
APP_NAME: foo
BUILD_VERSION: 0.1
ARCH: amd64
```
With above assumption lets start building deb package.
1. Create a directory `mkdir ${APPNAME}_${BUILD_VERSION}_${ARCH}` i.e `mkdir foo_0.1_amd64`
2. Go inside above dir `cd foo_0.1_amd64`
3. Create DEBIAN dir `mkdir DEBIAN`
Inside DEBIAN dir you can have post install, preinstall scripts etc. For more details refer [Files Inside Debian dir
](https://www.debian.org/doc/manuals/maint-guide/dother.en.html)
For this tutorial I'm adding only control file and postinst file.
```bash
├── DEBIAN
│   ├── control
│   └── postinst
```
control file contains package details which is interpreted package management system. Refer [DEBIAN/CONTROL](https://www.debian.org/doc/debian-policy/ch-controlfields.html)
For this article `control` contains following
```bash
Package: foo
Version: 0.1
Section: base
Priority: optional
Architecture: amd64
Maintainer: Sudheer <[email protected]>
Description: Foo example
```
`postinst` is bash script files which contains instruction what to do once install is successful.
## Adding files in deb package
Suppose you've a bin file `fooserv` which you want to put in /usr/bin when your deb package is installed.
So for any such scenario you should created same dir structure in deb package folder.
Final dir structure
```bash
foo_0.1_amd64/
├── DEBIAN
│   ├── control
│   └── postinst
├── etc
│   └── foo
│   └── foo.conf
└── usr
└── bin
└── fooserv
```
when package foo will installed it will copy `usr/bin/fooserv` to `/usr/bin/fooserv`
and similarly `etc/foo/foo.conf` to `/etc/foo/foo.conf` these files will be copied as part of installation process
. you can write custom install steps in `DEBIAN/install` script.
Once everything is inplace.
do `dpkg-deb --build ${APP_DIR}` i.e `dpkg-deb --build foo_0.1_amd64`
you should have basic version of deb package. For more details refer this doc [Writing Deb package](https://www.debian.org/doc/manuals/maint-guide/start.en.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment