summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-11-28 14:40:36 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-11-28 14:40:36 -0500
commit92a87bf9e4e0a5a2bfbe1072c61f2a2cb2bdd233 (patch)
tree292082b9eabb62c5173e595de6ad974c7446a57f
parent74b8f7216842d748b564dff34a37fb930bce00ce (diff)
make the mkarchroot option parsing make sense (mostly compatible)
-rw-r--r--mkarchroot.in57
1 files changed, 37 insertions, 20 deletions
diff --git a/mkarchroot.in b/mkarchroot.in
index 7b6adf7..c050503 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -14,6 +14,7 @@ CHROOT_VERSION='v2'
FORCE='n'
RUN=''
+PKGS=''
NOCOPY='n'
NONETWORK='n'
@@ -23,52 +24,68 @@ APPNAME=$(basename "${0}")
# usage: usage <exitvalue>
usage() {
- echo "Usage: ${APPNAME} [options] working-dir [package-list | app]"
+ echo "Usage: ${APPNAME} [options] working-dir [action]"
echo ' options:'
- echo ' -r <app> 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 ' -C <file> Location of a pacman config file'
echo ' -M <file> Location of a makepkg config file'
echo ' -n Do not copy config files into the chroot'
echo ' -c <dir> Set pacman cache'
echo ' -N Disable networking in the chroot'
- echo ' -h This message'
- exit 1
+ echo ' actions:'
+ echo ' -i <pkg-list> Install "pkg-list" in the chroot.'
+ echo ' Creates the chroot if necessary, workding-dir must exist'
+ echo ' -r <cmd> Run "cmd" within the context of the chroot'
+ echo ' -u Update the chroot via pacman'
+ echo ' -h Print this message'
+
+ exit ${1-1}
}
-while getopts 'r:ufnhC:M:c:' arg; do
+################################################################################
+
+while getopts 'fnC:M:c:' arg; do
case "${arg}" in
- r) RUN="$OPTARG" ;;
- u) RUN='/bin/sh -c "pacman -Syu --noconfirm && (pacman -Qqu >/dev/null && pacman -Su --noconfirm || exit 0)"' ;;
f) FORCE='y' ;;
C) pac_conf="$OPTARG" ;;
M) makepkg_conf="$OPTARG" ;;
n) NOCOPY='y' ;;
c) cache_dir="$OPTARG" ;;
N) NONETWORK='y' ;;
- h|?) usage ;;
+ h|?) usage 0 ;;
*) error "invalid argument '${arg}'"; usage ;;
esac
done
-if (( $EUID != 0 )); then
- die 'This script must be run as root.'
-fi
-
shift $(($OPTIND - 1))
-if [[ -z $RUN ]] && (( $# < 2 )); then
- die 'You must specify a directory and one or more packages.'
-elif (( $# < 1 )); then
- die 'You must specify a directory.'
+if (( $# < 2 )); then
+ error 'You must specify a directory and an action.'
+ usage
fi
-working_dir="$(readlink -f ${1})"
+working_dir="$(readlink -f "${1}")"
shift 1
-
[[ -z $working_dir ]] && die 'Please specify a working directory.'
+action=$1
+shift 1
+case "$action" in
+ -i) PKGS=("$@") ;;
+ -r) RUN="$*" ;;
+ -u) RUN='/bin/sh -c "pacman -Syu --noconfirm && (pacman -Qqu >/dev/null && pacman -Su --noconfirm || exit 0)"' ;;
+ -h) usage 0 ;;
+ -*) usage 1 ;;
+ *) PKGS=("$action" "$@") ;; # for compatability with mkarchroot
+esac
+unset action
+
+################################################################################
+
+if (( $EUID != 0 )); then
+ die 'This script must be run as root.'
+fi
+
if [[ -z $cache_dir ]]; then
cache_dirs=($(pacman -v $cache_conf 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
else
@@ -253,7 +270,7 @@ else
if [[ $FORCE = 'y' ]]; then
pacargs="$pacargs --force"
fi
- if ! pacstrap -GMcd "${working_dir}" ${pacargs} $@; then
+ if ! pacstrap -GMcd "${working_dir}" ${pacargs} "$PKGS"; then
die 'Failed to install all packages'
fi
fi