Indice

Creare pacchetti di installazione per sistemi GNU/Linux

Autore: Fabio Di Matteo
Ultima revisione: 30/01/2024 - 22:10

Di seguito alcuni concisi appunti sulla creazione di pacchetti per alcune distribuzioni GNU/Linux. Il tutto direttamente dalla mia distro Arch Linux.

Arch

Nelle distribuzioni basate su Arch Linux si usa il sistema del PKGBUILD, ovvero un file di testo contenente le direttive per scaricare i sorgenti, e da questi creare il pacchetto binario. Ecco come si presenta un PKGBUILD di una nostra applicazione:

PKGBUILD

# Maintainer: Fabio Di Matteo <pobfdm@gmail.com>
pkgname=pobshare-git
pkgver=0.1
pkgrel=1
pkgdesc="A simple gui for share files. "
arch=('any')
url="https://github.com/pobfdm/pobshare.git"
license=('GPL')
depends=('python-wxpython' 'python-pyftpdlib')
conflicts=('pobshare')
source=(https://github.com/pobfdm/pobshare/archive/master.zip)
md5sums=('SKIP') #generate with 'makepkg -g'



package() {
  mkdir -p "$pkgdir/usr/bin/"
  mkdir -p "$pkgdir/usr/lib/pobshare/"
  mkdir -p "$pkgdir/usr/share/applications"
  cp "$srcdir/pobshare-master/pobshare" "$pkgdir/usr/bin/"
  cp -R "$srcdir/pobshare-master/icons/" "$pkgdir/usr/lib/pobshare/"
  cp -R "$srcdir/pobshare-master/locale/" "$pkgdir/usr/lib/pobshare/"
  cp -R "$srcdir/pobshare-master/gui/" "$pkgdir/usr/lib/pobshare/"
  cp "$srcdir/pobshare-master/"*.py "$pkgdir/usr/lib/pobshare/"
  cp "$srcdir/pobshare-master/"*.desktop "$pkgdir/usr/share/applications/"
}

L'archivio compresso del sorgente viene spacchettato nel path $srcdir e il pacchetto viene assemblato in chroot nel path $pkgdir .

Altro esempio:

PKGBUILD di una app che fa uso di CMake

# Maintainer: Fabio Di Matteo <pobfdm@gmail.com>
pkgname=pobvnc
pkgver=0.1
pkgrel=1
epoch=
pkgdesc="Pobvnc is an application that enables you to help other people behind a firewall."
arch=('i686' 'x86_64')
url="https://www.freemedialab.org/pobvnc/"
license=('GPL')
groups=('Network')
depends=('gtk2' 'x11vnc' 'tigervnc')
makedepends=('cmake')
checkdepends=()
optdepends=('curl')
provides=('pobvnc')
conflicts=('pobvnc')
replaces=()
backup=()
options=( 'strip')
install=
changelog=
#source=($pkgname-$pkgver.tar.gz)
noextract=()
source=(https://github.com/pobfdm/pobvnc/archive/master.zip)
md5sums=('SKIP') #generate with 'makepkg -g'


build() {
  cd "$srcdir/pobvnc-master"
  cmake .
  make
}


package() {
  cd "$srcdir/pobvnc-master"
  make DESTDIR="$pkgdir/" install
}

Prestare particolare attenzione alle direttive source (da dove scaricare il sorgente), build le procedure necessarie alla compilazione e package() pacchettizza il pacchetto. Per avviare la compilazione basta lanciare makepkg o makepkg -s se vogliamo che risolva le dipendenze. Arch User Repository

Debian

Viene creata la cartella “Piso” al suo interno la cartella “DEBIAN” col file control e a fianco di DEBIAN le cartelle del pacchetto.

makedeb.sh

#!/usr/bin/bash
 
mkdir -p Piso/DEBIAN
echo "Package: Piso
Version: 0.1
Maintainer: Fabio Di Matteo <myemail@domain.com>
Section: x11
Source: https://www.freemedialab.org/code/tmp/piso.zip
Homepage: https://www.freemedialab.org/code/piso
Architecture: all
Priority: optional
Depends: libwxgtk3.0-gtk3-0v5 (>=3.0.0),libminiupnpc17 (>=2.2.3), curl
Description: Piso allows you to share files across the network without the use of external servers. 
" >Piso/DEBIAN/control
 
mkdir -p Piso/opt/piso
mkdir -p Piso/usr/share/applications
 
cp  ../../build/piso Piso/opt/piso/
cp  ../../icon.png Piso/opt/piso/
cp  ../../piso.desktop Piso/usr/share/applications/
 
dpkg-deb --root-owner-group --build Piso

Successivamente basta avviare lo script makedeb.sh

Fedora

make_rpm.sh

#!/usr/bin/env bash

mkdir -p $HOME/rpmbuild/SOURCES/
mkdir -p $HOME/rpmbuild/SOURCES/usr/{bin,lib/pobhelp,share/applications}

cp ../pobhelp $HOME/rpmbuild/SOURCES/usr/bin
cp ../*.py $HOME/rpmbuild/SOURCES/usr/lib/pobhelp
cp ../*.ovpn $HOME/rpmbuild/SOURCES/usr/lib/pobhelp
cp ../*.key $HOME/rpmbuild/SOURCES/usr/lib/pobhelp
cp -R ../locale $HOME/rpmbuild/SOURCES/usr/lib/pobhelp
cp ../*.png $HOME/rpmbuild/SOURCES/usr/lib/pobhelp
cp ../*.ico $HOME/rpmbuild/SOURCES/usr/lib/pobhelp
cp ../pobhelp.desktop $HOME/rpmbuild/SOURCES/usr/share/applications

chmod +x $HOME/rpmbuild/SOURCES/usr/bin/pobhelp
chmod +x $HOME/rpmbuild/SOURCES/usr/lib/pobhelp/pobhelp.py



tar czf $HOME/rpmbuild/SOURCES/pobhelp-0.1.tar.gz $HOME/rpmbuild/SOURCES/usr


rpmbuild -ba --clean  pobhelp.spec

pobhelp.spec

Name:		pobhelp
Version:	0.1
Release:	1_all
Summary:	Pobhelp is an application that enables you to help other people behind a firewall.
Group:		Network
License:	GPL
URL:		https://www.freemedialab.org/code/project.php?p=PobHelp
Source0:	pobhelp-0.1.tar.gz
BuildArch: noarch

Requires:	python3-wxpython4 python3-pyftpdlib x11vnc tigervnc

%description
Pobhelp is a simple gui that allows you to establish a reverse vnc connection between two PCs. On Windows use TightVnc and on GnuLinux tigervnc and x11vnc. 





%install

echo "Directory corrente: $PWD"
cp -R %_sourcedir/usr/ %{buildroot}/

chmod +x %{buildroot}/usr/bin/pobhelp
chmod +x %{buildroot}/usr/lib/pobhelp/pobhelp.py


%files
/usr/bin/pobhelp
/usr/lib/pobhelp/client.ovpn
/usr/lib/pobhelp/ftpd.py
/usr/lib/pobhelp/gui.py
/usr/lib/pobhelp/guiUtils.py
/usr/lib/pobhelp/icon.png
/usr/lib/pobhelp/lifesaver.ico
/usr/lib/pobhelp/lifesaver.png
/usr/lib/pobhelp/locale/it_IT/LC_MESSAGES/it.mo
/usr/lib/pobhelp/locale/it_IT/LC_MESSAGES/it.po
/usr/lib/pobhelp/locale/it_IT/LC_MESSAGES/pobhelp.mo
/usr/lib/pobhelp/pobhelp.py
/usr/lib/pobhelp/server.ovpn
/usr/lib/pobhelp/static.key
/usr/lib/pobhelp/vncd.py
/usr/share/applications/pobhelp.desktop

Una volta lanciato lo script ,se tutto è andato bene troveremo il pacchetto in $HOME/rpmbuild/RPMS/