diff --git a/bin/juju b/bin/juju index 6f5e68c..d1bce75 100755 --- a/bin/juju +++ b/bin/juju @@ -29,7 +29,7 @@ source "$(dirname $0)/../lib/core.sh" usage() { echo -e "JuJu: The portable GNU/Linux distribution" - echo -e "Usage: $NAME [options]" + echo -e "Usage: $NAME [options] [command]" echo -e "Options:" echo -e "-i, --setup-from-file Setup the JuJu image in ${JUJU_HOME}" echo -e "-f, --fakeroot Run JuJu with fakeroot privileges" @@ -79,13 +79,19 @@ check_cli(){ die "The JuJu version option must be used exclusively" fi fi - if $OPT_FAKEROOT && $OPT_ROOT then die "You must access to JuJu with either fakeroot or root permissions" fi - [ "$ARGS" != "" ] && die "No arguments are needed. For the CLI syntax run: $NAME --help" + if [ "$ARGS" != "" ] + then + if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \ + $OPT_VERSION + then + die "No arguments are needed. For the CLI syntax run: $NAME --help" + fi + fi return 0 } @@ -156,11 +162,11 @@ elif $OPT_SETUP_FROM_FILE; then fi if $OPT_FAKEROOT; then - run_juju_as_fakeroot + run_juju_as_fakeroot ${ARGS[@]} elif $OPT_ROOT; then - run_juju_as_root + run_juju_as_root ${ARGS[@]} else - run_juju_as_user + run_juju_as_user ${ARGS[@]} fi # vim: set ts=4 sw=4 noet: diff --git a/lib/core.sh b/lib/core.sh index 925696d..42d4838 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -141,31 +141,41 @@ function setup_from_file_juju(){ } +function _define_command(){ + local comm=$@ + [ "$comm" == "" ] && comm=${SH} + echo "$comm" +} + + function run_juju_as_root(){ [ "$JUJU_ENV" == "1" ] && die "Error: The operation is not allowed inside JuJu environment" + local comm=$(_define_command $@) mkdir -p ${JUJU_HOME}/${HOME} - ${JUJU_HOME}/usr/bin/arch-chroot $JUJU_HOME /usr/bin/bash -c 'mkdir -p /run/lock && /bin/sh' + ${JUJU_HOME}/usr/bin/arch-chroot $JUJU_HOME /usr/bin/bash -c "mkdir -p /run/lock && ${comm}" } function _run_juju_with_proot(){ if ${PROOT} ${JUJU_HOME}/usr/bin/true &> /dev/null then - JUJU_ENV=1 ${PROOT} $@ ${JUJU_HOME} ${SH} + JUJU_ENV=1 ${PROOT} $@ else - JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT} $@ ${JUJU_HOME} ${SH} + JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT} $@ fi } function run_juju_as_fakeroot(){ - _run_juju_with_proot "-S" + local comm=$(_define_command $@) + _run_juju_with_proot "-S" ${JUJU_HOME} ${comm} } function run_juju_as_user(){ - _run_juju_with_proot "-R" + local comm=$(_define_command $@) + _run_juju_with_proot "-R" ${JUJU_HOME} ${comm} }