Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/contrib/bacman.sh.in
diff options
context:
space:
mode:
authorWilliam Giokas <1007380@gmail.com>2013-03-05 17:01:53 -0600
committerAllan McRae <allan@archlinux.org>2013-03-08 17:04:40 +1000
commit6e0c47d22f44693d6c1fb1c54d5b5beb637d5ebf (patch)
treeeb709f15a13803d26749038f449b0108d27431d0 /contrib/bacman.sh.in
parentf8ed8620d03e7e6fc58815bbee5b65c786fbc423 (diff)
contrib: Add color to bacman
Signed-off-by: William Giokas <1007380@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'contrib/bacman.sh.in')
-rw-r--r--contrib/bacman.sh.in62
1 files changed, 34 insertions, 28 deletions
diff --git a/contrib/bacman.sh.in b/contrib/bacman.sh.in
index 512de637..5435e405 100644
--- a/contrib/bacman.sh.in
+++ b/contrib/bacman.sh.in
@@ -26,13 +26,16 @@ shopt -s nullglob
declare -r myname='bacman'
declare -r myver='@PACKAGE_VERSION@'
+USE_COLOR='y'
+
+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"
}
@@ -41,6 +44,13 @@ version() {
echo 'Copyright (C) 2008 locci <carlocci_at_gmail_dot_com>'
}
+if [[ $1 == "--nocolor" ]]; then
+ USE_COLOR='n'
+ shift
+fi
+
+m4_include(../scripts/library/term_colors.sh)
+
if (( $# != 1 )); then
usage
exit 1
@@ -59,14 +69,13 @@ fi
#
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" "$@"
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
@@ -74,7 +83,7 @@ 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
@@ -82,7 +91,7 @@ eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
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
@@ -102,34 +111,34 @@ pkg_namver=("${pkg_dir[@]##*/}")
# 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
@@ -150,17 +159,14 @@ 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
@@ -178,7 +184,7 @@ pkg_size=$(du -sk | awk '{print $1 * 1024}')
# .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
@@ -273,7 +279,7 @@ chmod 644 "$work_dir"/{.PKGINFO,.CHANGELOG,.INSTALL} 2> /dev/null
#
# Generate the package
#
-echo "Generating the package..."
+msg2 "Generating the package..."
pkg_file="$pkg_dest/$pkg_namver-$pkg_arch${PKGEXT}"
ret=0
@@ -287,20 +293,20 @@ case "$PKGEXT" in
*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