--- category: en type: paper layout: paper tags: archlinux, configuration, linux title: Creating own repository short: creating-custom-repo description: It is a short paper devoted to creation own ArchLinux repository. ---

Prepare

First find a server and desire to have sex with it. It is recommended to use Archlinux on it, but it is not necessarily - because you may create special root for Archlinux. Also you need two packages, devtools and pacman:

{% highlight bash %} pacman -Sy devtools {% endhighlight %}

devtools is script set for building automation in the clean chroot. I think most of Arch maintainers use it.

Let's create working directories:

{% highlight bash %} mkdir -p ~/arch/repo/{i686,x86_64} mkdir -p ~/arch/{prepare,root,staging} {% endhighlight %}

~/arch/repo/{i686,x86_64} are directories for repository, ~/arch/prepare is directory where compiled packages will be stored, ~/arch/root is one where clean chroot will be created, ~/arch/staging is one where packages will be built.

A bit of theory

Create directory, share it (using ftp, for example). It has two subdirectories - i686 and x86_64 - for each architecture respectively. And fill them with a set of packages.

Updating repository may be split into the following steps:

  1. Creating PKGBUILDs (or updating them from AUR).
  2. Packages building for each architecture in clean chroot.
  3. Packages signing.
  4. Creating the list of packages.
  5. Repository update:
    1. Removal old packages from database and repository.
    2. Copying new packages
    3. Repository update.
  6. Cleaning.

Creating PKGBUILDs

Download source tarballs from AUR:

{% highlight bash %} cd ~/arch/staging yaourt -G package-name {% endhighlight %}

Packages building

Build each package automatically:

{% highlight bash %} func_build() { PREPARE="$1" ROOT="$2" if grep "arch=('any')" PKGBUILD -q; then /usr/bin/sudo /usr/bin/staging-i686-build -r "${ROOT}" else /usr/bin/sudo /usr/bin/staging-i686-build -r "${ROOT}" /usr/bin/sudo /usr/bin/staging-x86_64-build -r "${ROOT}" fi /usr/bin/cp *.pkg.tar.xz "${PREPARE}" } export -f func_build # building cd "${STAGINGDIR}" /usr/bin/find -name 'PKGBUILD' -type f -execdir /usr/bin/bash -c "func_build "${PREPAREDIR}" "${ROOTDIR}"" \; {% endhighlight %}

It is recommended to add the following lines to /etc/sudoers:

{% highlight bash %} username ALL=NOPASSWD: /usr/bin/staging-i686-build username ALL=NOPASSWD: /usr/bin/staging-x86_64-build {% endhighlight %}

Packages signing

{% highlight bash %} # signing cd "${PREPAREDIR}" for PACKAGE in $(/usr/bin/ls *.pkg.tar.xz); do /usr/bin/gpg -b ${PACKAGE} done {% endhighlight %}

It is recommended to configure gpg-agent.

Creating the list of packages

{% highlight bash %} # creating packages list i686_PACKAGES=$(/usr/bin/ls *.pkg.tar.xz | /usr/bin/grep "i686\|any") x86_64_PACKAGES=$(/usr/bin/ls *.pkg.tar.xz | /usr/bin/grep "x86_64\|any") echo "i686 packages: ${i686_PACKAGES}" echo "x86_64 packages: ${x86_64_PACKAGES}" {% endhighlight %}

Repository update

Here is a function for removal packages from database and repository:

{% highlight bash %} func_remove() { DBPATH="$1" PKGNAME="$2" /usr/bin/repo-remove ${DBNAME}.db.tar.gz ${PKGNAME} /usr/bin/repo-remove ${DBNAME}.files.tar.gz ${PKGNAME} /usr/bin/rm -f ${PKGNAME}* } export -f func_remove {% endhighlight %}

i686 repository update:

{% highlight bash %} # updating i686 repo cd "${REPODIR}/i686" for PACKAGE in ${i686_PACKAGES}; do PKGNAME=$(echo ${PACKAGE} | /usr/bin/awk -F '-' '{for(i=1; i<=NF-3;i++) {printf("%s-", $i);}}' | /usr/bin/sed 's/.$//') /usr/bin/find -name '${PKGNAME}*' -type f -exec /usr/bin/bash -c "func_remove "${DBNAME}" "${PKGNAME}"" \; /usr/bin/cp "${PREPAREDIR}/${PACKAGE}"{,.sig} . done /usr/bin/repo-add --new ${DBNAME}.db.tar.gz *.pkg.tar.xz /usr/bin/repo-add --new --files ${DBNAME}.files.tar.gz *.pkg.tar.xz {% endhighlight %}

x86_64 repository update:

{% highlight bash %} # updating x86_64 repo cd "${REPODIR}/x86_64" for PACKAGE in ${x86_64_PACKAGES}; do PKGNAME=$(echo ${PACKAGE} | /usr/bin/awk -F '-' '{for(i=1; i<=NF-3;i++) {printf("%s-", $i);}}' | /usr/bin/sed 's/.$//') /usr/bin/find -name '${PKGNAME}*' -type f -exec /usr/bin/bash -c "func_remove "${DBNAME}" "${PKGNAME}"" \; /usr/bin/cp "${PREPAREDIR}/${PACKAGE}"{,.sig} . done /usr/bin/repo-add --new ${DBNAME}.db.tar.gz *.pkg.tar.xz /usr/bin/repo-add --new --files ${DBNAME}.files.tar.gz *.pkg.tar.xz {% endhighlight %}

Cleaning

{% highlight bash %} # clear cd "${PREPAREDIR}" /usr/bin/rm -rf * cd "${STAGINGDIR}" /usr/bin/rm -rf * {% endhighlight %}

File

Here is the script. Download source tarballs and run script (editing variables if it is necessary).

Repository usage

Just add following lines to /etc/pacman.conf:

{% highlight bash %} [$REPONAME] Server = ftp://$REPOADDRESS/repo/$arch {% endhighlight %}