# stored into the pacman database and system files
#
# Copyright (c) 2008 locci <carlocci_at_gmail_dot_com>
-# Copyright (c) 2008-2012 Pacman Development Team <pacman-dev@archlinux.org>
+# Copyright (c) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
declare -r myname='bacman'
declare -r myver='@PACKAGE_VERSION@'
+USE_COLOR='y'
+# Required for fakeroot because options are shifted off the array.
+ARGS=("$@")
+
+m4_include(../scripts/library/output_format.sh)
#
# User Friendliness
#
usage() {
echo "This program recreates a package using pacman's db and system files"
- echo "Usage: $myname <installed package name>"
+ echo "Usage: $myname [--nocolor] <installed package name>"
echo "Example: $myname kernel26"
}
version() {
printf "%s %s\n" "$myname" "$myver"
echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>'
+ echo 'Copyright (C) 2008-2013 Pacman Development Team <pacman-dev@archlinux.org>'
}
+if [[ $1 == "--nocolor" ]]; then
+ USE_COLOR='n'
+ shift
+fi
+
+m4_include(../scripts/library/term_colors.sh)
+
if (( $# != 1 )); then
usage
exit 1
#
if (( EUID )); then
if [[ -f /usr/bin/fakeroot ]]; then
- echo "Entering fakeroot environment"
+ msg "Entering fakeroot environment"
export INFAKEROOT="1"
- /usr/bin/fakeroot -u -- "$0" "$@"
+ /usr/bin/fakeroot -u -- "$0" "${ARGS[@]}"
exit $?
else
- echo "WARNING: installing fakeroot or running $myname as root is required to"
- echo " preserve the ownership permissions of files in some packages"
- echo ""
+ warning "installing fakeroot or running $myname as root is required to"
+ plain " preserve the ownership permissions of files in some packages\n"
fi
fi
# Setting environmental variables
#
if [[ ! -r @sysconfdir@/pacman.conf ]]; then
- echo "ERROR: unable to read @sysconfdir@/pacman.conf"
+ error "unable to read @sysconfdir@/pacman.conf"
exit 1
fi
pac_db="${DBPath:-@localstatedir@/lib/pacman/}/local"
if [[ ! -r @sysconfdir@/makepkg.conf ]]; then
- echo "ERROR: unable to read @sysconfdir@/makepkg.conf"
+ error "unable to read @sysconfdir@/makepkg.conf"
exit 1
fi
# Checks everything is in place
#
if [[ ! -d $pac_db ]]; then
- echo "ERROR: pacman database directory ${pac_db} not found"
+ error "pacman database directory ${pac_db} not found"
exit 1
fi
if (( ${#pkg_dir[@]} != 1 )); then
- printf "ERROR: %d entries for package %s found in pacman database\n" \
+ error "%d entries for package %s found in pacman database" \
${#pkg_dir[@]} "${pkg_name}"
- printf "%s\n" "${pkg_dir[@]}"
+ msg2 "%s" "${pkg_dir[@]}"
exit 1
fi
if [[ ! -d $pkg_dir ]]; then
- printf "ERROR: package %s is found in pacman database,\n" "${pkg_name}"
- printf " but \`%s' is not a directory\n" "${pkg_dir}"
+ error "package %s is found in pacman database," "${pkg_name}"
+ plain " but '%s' is not a directory" "${pkg_dir}"
exit 1
fi
#
# Begin
#
-echo "Package: ${pkg_namver}"
+msg "Package: ${pkg_namver}"
work_dir=$(mktemp -d --tmpdir bacman.XXXXXXXXXX)
cd "$work_dir" || exit 1
#
# File copying
#
-echo "Copying package files..."
+msg2 "Copying package files..."
cat "$pkg_dir"/files |
while read i; do
# Workaround to bsdtar not reporting a missing file as an error
if ! [[ -e $work_dir/$i || -L $work_dir/$i ]]; then
- echo ""
- echo "ERROR: unable to add /$i to the package"
- echo " If your user does not have permssion to read this file then"
- echo " you will need to run $myname as root"
+ error "unable to add /$i to the package"
+ plain " If your user does not have permssion to read this file then"
+ plain " you will need to run $myname as root"
rm -rf "$work_dir"
exit 1
fi
else
- echo ""
- echo "WARNING: package file /$i is missing"
- echo ""
+ warning "package file /$i is missing"
fi
;;
esac
# .PKGINFO stuff
# TODO adopt makepkg's write_pkginfo() into this or scripts/library
#
-echo Generating .PKGINFO metadata...
+msg2 "Generating .PKGINFO metadata..."
echo "# Generated by $myname $myver" > .PKGINFO
if [[ $INFAKEROOT == "1" ]]; then
echo "# Using $(fakeroot -v)" >> .PKGINFO
#
# Generate the package
#
-echo "Generating the package..."
+msg2 "Generating the package..."
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
*tar.xz) xz -c -z - ;;
*tar.Z) compress -c -f ;;
*tar) cat ;;
- *) echo "WARNING: '%s' is not a valid archive extension." \
- "$PKGEXT" >&2; cat ;;
+ *) warning "'%s' is not a valid archive extension." \
+ "$PKGEXT"; cat ;;
esac > "${pkg_file}"; ret=$?
if (( ret )); then
- echo "ERROR: unable to write package to $pkg_dest"
- echo " Maybe the disk is full or you do not have write access"
+ error "Unable to write package to $pkg_dest"
+ plain " Maybe the disk is full or you do not have write access"
rm -rf "$work_dir"
exit 1
fi
rm -rf "$work_dir"
-echo Done
+msg "Done."
exit 0