#!/bin/bash
#
# Script to export cleaned sources from PKGBUILDs with build instructions
# usage clean_source_export
# without acts on curent dir
if [[ $1 ]]; then
cd "$1"
fi
#check there is a PKGBUILD to work on
if [[ ! -f PKGBUILD ]]; then
echo "No PKGBUILD found. Exiting."
exit 1
fi
#Make the clean source
makepkg -Crso --noconfirm
# Get access to the functions
. PKGBUILD
cd src
# Export the build information
echo -e "Depends:\n\n ${depends[*]}\n\nMake Depends:\n\n ${makedepends[*]}\n\nCommand to build:\n" > Parabola_Build.txt
type build | sed '1,3d;$d' \
| sed "s|\$pkgver|$pkgver|g" | sed "s|\$srcdir|$srcdir|g" \
| sed "s|\$pkgrel|$pkgrel|g" | sed "s|\$pkgname|$pkgname|g" \
| sed "s|\$pkgdir|$pkgdir|g" >> Parabola_Build.txt
# roll it up
tar zcvf ../$pkgname-$pkgver-$pkgrel.tar.gz ./
# Clean up - Disabled while testing
#cd ..
#rm -rf src