Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I used yaourt to successfully build and install an AUR package, unfortunately missing the fact that in its default configuration the built package is removed after installation. Since the build took around 24 hours and having the package available for later might be useful, is there any way to reconstruct the package from the installed binaries instead of having to makepkg it again? Or more generally, since this is not necessarily yaourt-tied:

How to retrieve a makepkg generated package from the installation and source without having to recompile?

share|improve this question
add comment

2 Answers 2

I doubt it, but here's few hints that works for you,

Dependencies and files are stored in /var/lib/pacman/local/XX-Version/{desc, files}, so it's not hard to compress them.

The hierarchy in the xz package should be like this:

enter image description here

The .PKGINFO and .INSTALL (post install script) can be converted from the PKGBUILD (which is retrievable through abs or yaourt).

share|improve this answer
    
Thanks for the hints, I wrote a script based on this –  Tobias Kienzler Dec 21 '12 at 16:34
add comment
up vote 1 down vote accepted

Thanks to the hints in warl0ck's answer I wrote this script fakepkg:

#!/bin/bash
set -e

OLDDIR=$PWD

NEWDIR=$(mktemp -dt fakepack.XXX)
cd $NEWDIR

yaourt -G $1
cd $1

#TODO this can probably be retrieved from the pacman desc file
while true; do
  read -p "Edit PKGBUILD? [yn]" -n1 yn
  case $yn in
    [Yy]* ) $EDITOR PKGBUILD; break;;
    [Nn]* ) echo; break;;
    * ) echo ;;
  esac
done

. PKGBUILD
srcdir=$NEWDIR/$1/src
# In case you are wondering: this tries to compensate for packages not using
# a simple src/packagename-pkgver/ structure. It will probably still break...
PKSUB=$(eval "echo $(grep -o '\${\?srcdir.*pkgver}\?' PKGBUILD | head -n1 )")
SRC=${PKSUB##$NEWDIR/$1/}
echo "Putting the $1 source to $SRC"

PKG=$pkgname-$pkgver
# SRC="src/$PKG/"
FILES="/var/lib/pacman/local/$PKG-$pkgrel/files"

if [ ! -f $FILES ]; then
  echo "$FILES not found, is $1 actually installed?"
  exit 1
fi

#TODO use existing sources or skip this entirely
#     but it's the easiest way to later use makepkg -R
echo "Reloading source"
makepkg -o

echo "Collecting $1 files"
mkdir -p $SRC/files/
while IFS= read -r line; do
  if [ -f "/$line" ]; then
    mkdir -p $SRC/files/$(dirname $line)
    rsync -a /$line $SRC/files/$line
  fi
done < $FILES

echo "Creating fake Makefile"
echo 'install:' > $SRC/Makefile
echo '  mv files/* $(DESTDIR)' >> $SRC/Makefile
rm -f $SRC/GNUmakefile

echo "Creating package"
makepkg -R
mv *.xz $OLDDIR
cd $OLDDIR
rm -rf $NEWDIR

Run fakepkg packagename, adapt PKGBUILD if necessary and hope for a package---.pak.tar.xz in your current directory.

There's plenty of room for improvements of course, e.g. automatically modifying PKGBUILD according to the installation's desc and not downloading the entire source. But for now it works ok enough.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.