bacman: unify package creation with makepkg

Currently bacman always compresses with gzip now matter what PKGEXT is
set to.  Rework the entire package creation process to be similar to
that in makepkg.  This also make the explicit assumption that PKGEXT is
defined in makepkg.conf.

Thanks to Nelson Chan <khcha.n.el@gmail.com> for the original patch to
fix the incorrect package compression.

Signed-off-by: Allan McRae <allan@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Allan McRae 2010-09-15 23:36:57 +10:00 committed by Dan McGee
parent c2993197ea
commit fd38319106
1 changed files with 35 additions and 9 deletions

View File

@ -87,7 +87,6 @@ fi
pkg_arch=${CARCH:-'unknown'}
pkg_dest="${PKGDEST:-$PWD}"
pkg_ext=${PKGEXT:-'.pkg.tar.gz'}
pkg_pkger=${PACKAGER:-'Unknown Packager'}
pkg_name="$1"
@ -164,13 +163,6 @@ fi
pkg_size=$(du -sk | awk '{print $1 * 1024}')
if [ -f "$pkg_dir/install" ] ; then
cp "$pkg_dir/install" "$work_dir/.INSTALL"
fi
if [ -f $pkg_dir/changelog ] ; then
cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
fi
#
# .PKGINFO stuff
#
@ -254,6 +246,17 @@ while read i; do
esac
done
comp_files=".PKGINFO"
if [ -f "$pkg_dir/install" ] ; then
cp "$pkg_dir/install" "$work_dir/.INSTALL"
comp_files+=" .INSTALL"
fi
if [ -f $pkg_dir/changelog ] ; then
cp "$pkg_dir/changelog" "$work_dir/.CHANGELOG"
comp_files+=" .CHANGELOG"
fi
#
# Fixes owner:group and permissions for .PKGINFO, .CHANGELOG, .INSTALL
#
@ -265,8 +268,31 @@ chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
#
echo "Generating the package..."
case "$PKGEXT" in
*tar.gz) EXT=${PKGEXT%.gz} ;;
*tar.bz2) EXT=${PKGEXT%.bz2} ;;
*tar.xz) EXT=${PKGEXT%.xz} ;;
*tar) EXT=${PKGEXT} ;;
*) echo "WARNING: '%s' is not a valid archive extension." \
"$PKGEXT" ; EXT=$PKGEXT ;;
esac
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
bsdtar -czf "$pkg_dest/$pkg_namver-$pkg_arch$pkg_ext" $(ls -A) || ret=$?
# when fileglobbing, we want * in an empty directory to expand to
# the null string rather than itself
shopt -s nullglob
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
bsdtar -cf - $comp_files * |
case "$PKGEXT" in
*tar.gz) gzip -c -f -n ;;
*tar.bz2) bzip2 -c -f ;;
*tar.xz) xz -c -z - ;;
*tar) cat ;;
esac > ${pkg_file} || ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: unable to write package to $pkg_dest"
echo " Maybe the disk is full or you do not have write access"