Work in progress

Patching the ArchLinux AIF installer

I recently found out an error trying to install ArchLinux from a custom live image I built using Archiso.

Aif (ArchLinux Installation Framework) fails when selecting the first option (Select sources) and throws the following message:

ERROR: ask_checklist makes only sense if you specify at least 1 thing (tag,item and ON/OFF switch)

Well, I needed to fix this bug and include the patched Aif package in the ISO I built, so, after some minutes of researching, I found out the problem was that Aif couldn't retrieve the repos configured on pacman.conf

The bug was easily fixed, but the real leason learned for me was how to create a patch and apply that patch to an ArchLinux package, here you are the steps I followed.

The first thing to do is to download the sources and create the patch.

$ git clone git://projects.archlinux.org/aif.git aif
$ cp -r aif aif.new

Now you can make all the changes you need in the aif.new copy and create the patch:

$ diff -aur aif/ aif.new/ > aif-git.patch

This is the resulting patch for me, as you can see the bug was really easy to fix ;)

diff -aur aif/src/core/libs/lib-pacman.sh aif.new/src/core/libs/lib-pacman.sh
--- aif/src/core/libs/lib-pacman.sh    2012-07-15 21:22:37.293264424 +0200
+++ aif.new/src/core/libs/lib-pacman.sh    2012-07-15 22:46:42.642245000 +0200
@@ -64,7 +64,7 @@
 # returns all repositories you could possibly use (core, extra, testing, community, ...)
 list_possible_repos ()
 {
-   grep -B 1 'Include = /etc/' /etc/pacman.conf | grep '\[' | sed 's/#*\[\(.*\)\]/\1/'
+   grep '\[.*\]' /etc/pacman.conf | grep -v options | grep -v '^#' | sed 's/\[//g' | sed 's/\]//g'
 }

The next step is to include this patch in the aif package. I downloaded the PKGBUILD file from the AUR repository:

$ mkdir aif-git
$ cd aif-git
$ wget http://aur.archlinux.org/packages/ai/aif-git/PKGBUILD

Becouse this PKGBUILD is old and outdated the first thing is to update the git repository it points to, so it gets the same sources we patch previously. Change the _gitroot variable to point to the official repo, something like this:

_gitroot="git://projects.archlinux.org/aif.git"

Now we can include our patch, remember it has to live in the same directory the PKGBUILD file does. Edit the source variable to look like this:

source=(aif-git.patch)

As we include a new source file we must include also the md5sum for that source. Type makepkg -g, this command will print out the value of the md5sums variable, copy the output and update the PKGBUILD file again.

One last thing to do is to change the build() function in the PKGBUILD file so it applies our patch correctly. The resulting PKGBUILD file for me, after all the changes made, is the following:

...

source=(aif-git.patch)
md5sums=('666118d9fd018c6469c9df44e40f2e11')

_gitroot="git://projects.archlinux.org/aif.git aif"

build() {
  msg "Connecting to GIT server..."
  if [[ -d $srcdir/$pkgname-$pkgver ]]; then
    cd $srcdir/$pkgname-$pkgver && git pull origin || return 1
  else
    git clone $_gitroot $srcdir/$pkgname-$pkgver || return 1
    cd $srcdir/$pkgname-$pkgver
  fi

  patch -p1 -i $srcdir/pkgname.patch

  msg "GIT checkout done or server timeout"

  make DESTDIR="$pkgdir/" install
}

...

The last step, create the new patched package, all you have to do is to run the following command from within the same directory the PKGBUILD file lives. Note the use of the -d argument, I don't really wanted to install all the dependencies, only to build the package.

$ makepkg -d

Well, thats all. After patching the aif package I include it in my ISO image and everything went well ;)

References: