Pacur Tutorial

Zach
5 min readAug 19, 2015

Getting started with Pacur

Simple Packaging

Pacur is a open source tool for creating Linux packages across several Linux distributions. Packages are created using a consistent spec and build system that uses docker containers to build the packages. Pacur can be used on any platform without needing virtual machines or remote build platforms. Pacur will also create a repository for each distribution with signed packages. Pacur will only build 64 bit packages due to the architecture limitations of Docker but with some effort Pacur could be modified to build for other architectures if needed.

Creating a Project

Projects are a set of packages that include a spec file for each package. The Pacur cli tool can then be used to build all the packages in the project and create a repository for the project. The cli tool isn’t necessary for building packages more information on building single packages with just the docker containers is available on the GitHub repository. Before creating a project the cli tool will need to be installed which can be done using the Go command below.

go get github.com/pacur/pacur

After installing the cli tool download the example project in the the GitHub repository. Extract the “example” directory from the archive and open a terminal in the directory. The example includes an example “httpserver” package and a signing key for the repository. Inside the “httpserver” is a spec file for each Linux distribution below is the contents of the spec file.

targets=(
"archlinux"
"centos"
"debian"
"ubuntu"
)
pkgname="httpserver"
pkgver="1.0"
pkgrel="1"
pkgdesc="Http file server written with Go"
pkgdesc:centos="Http file server written with Go for CentOS"
pkgdesc:debian="Http file server written with Go for Debian"
pkgdesc:ubuntu="Http file server written with Go for Ubuntu"
pkgdesclong=(
"Quick http file server written with Go"
"using directory listing similar to apache"
)
maintainer="Example <example@pacur.org>"
arch="all"
license=("GPLv3")
section="utils"
priority="optional"
url="https://github.com/pacur/${pkgname}"
sources=(
"${url}/archive/${pkgver}.tar.gz"
)
hashsums=(
"3548e1263a931b27970e190f04b74623"
)

build() {
mkdir -p "go/src"
export GOPATH="${srcdir}/go"
mv "${pkgname}-${pkgver}" "go/src"
cd "go/src/${pkgname}-${pkgver}"
go get
go build -a
}

package() {
cd "${srcdir}/go/src/${pkgname}-${pkgver}"
mkdir -p "${pkgdir}/usr/bin"
cp ${pkgname}-${pkgver} ${pkgdir}/usr/bin/${pkgname}
}

More information on the options in the spec file is available on the GitHub repository. Before building the packages the Docker containers will need to be to built. This should always be done locally as the Docker Hub images will no longer be maintained. The clean script will remove any existing pacur images.

cd ~/go/src/github.com/pacur/pacur/docker
sh clean.sh
sh build.sh

Building the Project

Next build the example package for each distribution using the project build command. This will build the packages and store them in the same directory as the spec files.

pacur project build

Create Project Repository

Once the packages have been built a repository can be created with the project repo command. This will create a “mirror” directory that has a repository for each of the distributions. This directory will then need to be transferred to a web server. The name of the repository can be changed by editing the “pacur.json” file in the project directory.

pacur project repo

Signing Key

When creating a production project a signing key should always be used. This section is optional for the example which already includes a signing key that can be used for testing. A signing key can be used by exporting your secret key to the project directory in the “sign.key” file. The key must be exported without a passphrase. Pacur also includes a genkey docker container for generating a 4096 bit signing key. This can be done by first pulling the genkey container and running the container in the project directory. Include the name and email separated by a space in the command.

docker pull pacur/genkey
docker run --rm -v `pwd`:/pacur First Last email@domain.com

The public key in the “sign.pub” file will then need to be uploaded to the MIT PGP Key Server. After uploading the public key search for the email address and get the key ID which will be similar to “6BBD5FFA”.

Using the Repository

Once the project repository has been created the mirror directory must be transferred to a web server for hosting. The example repository is available for testing on the Pritunl mirror servers. Below are the commands that a user would use to add and install the packages in the repository. When using the commands below for a production project the urls and pgp key id’s should be updated to your signing key and mirror server. For the ArchLinux package the “[pacur]” name must match the name in the “pacur.json” conf file.

ArchLinux

$ nano /etc/pacman.conf
[pacur]
Server = http://mirror.pritunl.com/example/arch
$ pacman-key --keyserver hkp://pgp.mit.edu -r 6BBD5FFA
$ pacman-key --lsign-key 6BBD5FFA
$ pacman -Sy
$ pacman -S httpserver

Fedora 22

$ nano /etc/yum.repos.d/pacur.repo
[pacur]
name=Pacur Example Repository
baseurl=http://mirror.pritunl.com/example/yum/fedora/22/
gpgcheck=1
enabled=1
$ gpg --keyserver hkp://pgp.mit.edu --recv-keys 6BBD5FFA
$ gpg --armor --export CF8E292A > key.tmp; rpm --import key.tmp; rm -f key.tmp
$ yum install httpserver

CentOS 7

$ nano /etc/yum.repos.d/pacur.repo
[pacur]
name=Pacur Example Repository
baseurl=http://mirror.pritunl.com/example/yum/centos/7/
gpgcheck=1
enabled=1
$ gpg --keyserver hkp://pgp.mit.edu --recv-keys 6BBD5FFA
$ gpg --armor --export CF8E292A > key.tmp; rpm --import key.tmp; rm -f key.tmp
$ yum install httpserver

Debian Wheezy

$ nano /etc/apt/sources.list.d/pacur.list
deb http://mirror.pritunl.com/example/apt wheezy main
$ apt-key adv --keyserver hkp://pgp.mit.edu --recv 6BBD5FFA
$ apt-get update
$ apt-get install httpserver

Debian Jessie

$ nano /etc/apt/sources.list.d/pacur.list
deb http://mirror.pritunl.com/example/apt jessie main
$ apt-key adv --keyserver hkp://pgp.mit.edu --recv 6BBD5FFA
$ apt-get update
$ apt-get install httpserver

Ubuntu Precise

$ nano /etc/apt/sources.list.d/pacur.list
deb http://mirror.pritunl.com/example/apt precise main
$ apt-key adv --keyserver hkp://pgp.mit.edu --recv 6BBD5FFA
$ apt-get update
$ apt-get install httpserver

Ubuntu Trusty

$ nano /etc/apt/sources.list.d/pacur.list
deb http://mirror.pritunl.com/example/apt trusty main
$ apt-key adv --keyserver hkp://pgp.mit.edu --recv 6BBD5FFA
$ apt-get update
$ apt-get install httpserver

Ubuntu Vivid

$ nano /etc/apt/sources.list.d/pacur.list
deb http://mirror.pritunl.com/example/apt vivid main
$ apt-key adv --keyserver hkp://pgp.mit.edu --recv 6BBD5FFA
$ apt-get update
$ apt-get install httpserver

Ubuntu Wily

$ nano /etc/apt/sources.list.d/pacur.list
deb http://mirror.pritunl.com/example/apt wily main
$ apt-key adv --keyserver hkp://pgp.mit.edu --recv 6BBD5FFA
$ apt-get update
$ apt-get install httpserver

@zachhuff386

Twitter Handle | GitHub Profile

--

--