From 67dc59299a72d8165c4fef3a5cad213bcf34f78b Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 11 Oct 2007 07:36:04 -0500 Subject: mkarchroot: clean up/unify output messages Also remove an extra EUID check, we do this at the beginning. Signed-off-by: Dan McGee --- mkarchroot | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'mkarchroot') diff --git a/mkarchroot b/mkarchroot index 0ff2b80..be93209 100755 --- a/mkarchroot +++ b/mkarchroot @@ -16,19 +16,20 @@ working_dir="" APPNAME=$(basename "${0}") if [ "$EUID" != "0" ]; then - echo "This script must be run as root." + echo "error: this script must be run as root." exit 1 fi +# usage: usage usage () { echo "usage ${APPNAME} [options] working-dir [package-list | app]" echo " options:" - echo " -r run 'app' within the context of the chroot" - echo " -u update the chroot via pacman" - echo " -f force overwrite of files in the working-dir" - echo " -h this message." - exit 1 + echo " -r Run 'app' within the context of the chroot" + echo " -u Update the chroot via pacman" + echo " -f Force overwrite of files in the working-dir" + echo " -h This message" + exit $1 } while getopts 'r:ufh' arg; do @@ -36,24 +37,24 @@ while getopts 'r:ufh' arg; do r) RUN="$OPTARG" ;; u) RUN="pacman -Syu" ;; f) FORCE="y" ;; - h|?) usage ;; - *) echo "invalid argument '${arg}'"; usage ;; + h|?) usage 0 ;; + *) echo "invalid argument '${arg}'"; usage 1 ;; esac done shift $(($OPTIND - 1)) if [ "$RUN" == "" -a $# -lt 2 ]; then echo "you must specify a directory and one or more packages" - usage + usage 1 elif [ $# -lt 1 ]; then echo "you must specify a directory" - usage + usage 1 fi working_dir="$(readlink -f ${1})" shift 1 -[ "${working_dir}" = "" ] && echo "error: please specify a working directory" && usage +[ "${working_dir}" = "" ] && echo "error: please specify a working directory" && usage 1 # {{{ functions @@ -90,14 +91,9 @@ function chroot_umount () if [ "$RUN" != "" ]; then # run chroot {{{ - if [ "$EUID" != "0" ]; then - echo "Running a chroot requires root privileges, aborting" - exit 1 - fi - #Sanity check if [ ! -f "${working_dir}/.arch-chroot" ]; then - echo "'${working_dir}' does not appear to be a Arch chroot" + echo "error: '${working_dir}' does not appear to be a Arch chroot" echo " please build the image using mkarchchroot" exit 1 fi @@ -111,7 +107,7 @@ if [ "$RUN" != "" ]; then else # {{{ build chroot if [ -e "${working_dir}" -a "${FORCE}" = "n" ]; then - echo "Working dir '${working_dir}' already exists - try using -f" + echo "error: working dir '${working_dir}' already exists - try using -f" exit 1 fi -- cgit v1.2.3-24-g4f1b