Sign up ×
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

3 Answers 3

There is a script that’s part of the pacman package called bacman that recreates a package using the pacman database and the files on your system.

Note however that such an approach should only be used as a last resort, as, for one, the package will quite possibly be different due to modifications to the files after installation.

share|improve this answer
up vote 1 down vote accepted

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

set -e


NEWDIR=$(mktemp -dt fakepack.XXX)

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 ;;

# 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 )")
echo "Putting the $1 source to $SRC"

# SRC="src/$PKG/"

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

#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
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
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
There is now a tool called bacman that does this programmatically, and I believe its in the repos – ntzrmtthihu777 Apr 17 at 15:00

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

Your Answer


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.