# Build deb package

##### Tutorials

Create a deb package

- [How to create a .deb file (tutorial)](https://medium.com/deplink/how-to-create-a-deb-file-tutorial-b56388fc35fd)
- [如何製作「deb檔(Debian Package)」](https://samwhelp.github.io/book-ubuntu-basic-skill/book/content/package/how-to-build-package.html)
- [How to Create DEB Packages for Debian/Ubuntu](https://www.makeuseof.com/create-deb-packages-debian-ubuntu/)
- [How to Create a Simple Debian Package](https://www.baeldung.com/linux/create-debian-package)
- [How to Create a Simple (.deb) Debian Package](https://www.linuxshelltips.com/create-debian-package/)
- [On Building a Debian Package of a Ruby Program](https://openpreservation.org/blogs/building-debian-package-ruby-program/)
- Samples 
    - [minecraft-installer](https://github.com/grahamedgecombe/minecraft-installer/tree/master/debian)

Rebuild a deb package from source

- [How To Build Debian Packages From Source](https://ostechnix.com/how-to-build-debian-packages-from-source/)

##### Extract a DEB package

```bash
dpkg -x coin-manager.22.11.15.deb source

tree --dirsfirst --filelimit 10 --sort=name source/
```

```
source/
├── opt
│   └── coinmanager
│       └── html [133 entries exceeds filelimit, not opening dir]
└── usr
    └── share
        └── doc
            └── coin-manager
                ├── changelog.Debian.gz
                ├── copyright
                └── README.Debian

7 directories, 3 files

```

For control file

```bash
dpkg -e coin-manager.22.11.15.deb source/DEBIAN

tree source/DEBIAN
```

```
source/DEBIAN
├── control
└── md5sums

0 directories, 2 files
```

##### Build a DEB package

```bash
tree --dirsfirst --filelimit 10 --sort=name coin-manager/
```

```
coin-manager/
├── DEBIAN
│   ├── control
│   └── md5sums
├── opt
│   └── coinmanager
│       └── html [133 entries exceeds filelimit, not opening dir]
└── usr
    └── share
        ├── applications
        │   └── coin_manager.desktop
        ├── doc
        │   └── coin-manager
        │       ├── changelog.Debian.gz
        │       ├── copyright
        │       └── README.Debian
        └── icons
            └── hicolor
                ├── 128x128
                │   └── apps
                │       └── coin-manager.png
                ├── 16x16
                │   └── apps
                ├── 22x22
                │   └── apps
                ├── 24x24
                │   └── apps
                ├── 32x32
                │   └── apps
                │       └── coin-manager.png
                ├── 48x48
                │   └── apps
                │       └── coin-manager.png
                ├── 64x64
                │   └── apps
                │       └── coin-manager.png
                └── scalable
                    └── apps
                        └── coin-manager.svg

27 directories, 11 files

```

```bash
cat coin-manager/DEBIAN/control
```

```
Package: coin-manager
Version: 22.11.15build2
Architecture: all
Maintainer: CoinManager Dev <support@cloudcoin.global>
Installed-Size: 52224
Depends: libc6 (>= 2.14), libgcc-s1 (>= 3.0), libgdk-pixbuf2.0-0 (>= 2.22.0), libglib2.0-0 (>= 2.12.0), libgtk-3-0 (>= 3.0.0), libjavascriptcoregtk-4.0-18, libstdc++6 (>= 5.2), libwebkit2gtk-4.0-37 (>= 2.21.1)
Section: contrib/admin
Priority: optional
Homepage: https://cloudcoinconsortium.com
Description: CloudCoin 2.0 manager
 Coini-Manager is the program for managing  CloudCoins 2.0
```

```bash
cat coin-manager/usr/share/applications/coin_manager.desktop
```

```
[Desktop Entry]
Comment=Coin Manager - CloudCoin 2.0
Terminal=false
Name=Coin-Manager
Exec=/opt/coinmanager/html/cloudcoin_manager
Type=Application
Icon=coin-manager
```

```bash
dpkg -b coin-manager
# Alternatively
mkdir build
dpkg -b coin-manager build
```

##### Build Appimage with deb package

Download: [https://github.com/AppImageCommunity/pkg2appimage](https://github.com/AppImageCommunity/pkg2appimage)

```
tree
```

```
.
├── coin-manager_22.11.15build3_amd64.deb
├── coin-manager.yml
└── pkg2appimage-1807-x86_64.AppImage

0 directories, 3 files
```

coin-manager.yml

```yaml
app: coin_manager
binpatch: true

ingredients:
  dist: focal
  sources:
    - deb http://free.nchc.org.tw/ubuntu focal main universe
  debs:
    - /home/alang/worktmp/AppImage_App/Using_pkg2appimage/coin-manager_22.11.15build3_amd64.deb

script:
  - VERSION="22.11.15build3"
  - cp ./usr/share/applications/coin_manager.desktop .
  - cp ./usr/share/icons/hicolor/256x256/apps/coin-manager.png coin_manager.png
  - sed -i -e 's|Exec=.*|Exec=coin_manager|g' coin_manager.desktop
  - sed -i -e 's|Icon=.*|Icon=coin_manager|g' coin_manager.desktop
  - ( cd usr/bin ; ln -s ../../opt/coinmanager/html/cloudcoin_manager coin_manager )
  - echo $VERSION > ../VERSION
```

- app: 專案名稱
- debs: 來源檔 Deb package 路徑
- VERSION: Appimage 檔案版號
- \*.desktop: 需包含有 `Categories` 的參數
- 執行檔需在 /usr/bin/ 或 /bin 有連結，因為 \*.desktop 的 `Exec` 不能使用絕對路徑

Build Appimage

```bash
./pkg2appimage-1807-x86_64.AppImage coin-manager.yml

tree --dirsfirst -L 3 --filelimit 10 --sort=name
```

```
.
├── coin_manager
│   ├── coin_manager.AppDir
│   │   ├── opt
│   │   ├── usr
│   │   ├── AppRun
│   │   ├── coin_manager.desktop
│   │   └── coin_manager.png
│   ├── tmp
│   │   ├── archives
│   │   ├── lists
│   │   ├── pkgcache.bin
│   │   └── srcpkgcache.bin
│   ├── cache.txt
│   ├── coin-manager_22.11.15build3_amd64.deb
│   ├── Packages.gz
│   ├── sources.list
│   ├── status
│   ├── teste_123
│   └── VERSION
├── out
│   └── Coin-Manager-22.11.15build3.glibc2.14-x86_64.AppImage
├── coin-manager_22.11.15build3_amd64.deb
├── coin-manager.yml
└── pkg2appimage-1807-x86_64.AppImage

8 directories, 16 files
```