mirror of
https://github.com/fsquillace/junest.git
synced 2026-07-21 10:18:35 +00:00
Merge pull request #57 from fsquillace/issue_65_arguments
Issue 65 arguments
This commit is contained in:
commit
fa1379b406
3 changed files with 51 additions and 26 deletions
13
bin/juju
13
bin/juju
|
|
@ -122,7 +122,7 @@ function parse_arguments(){
|
|||
OPT_DELETE=false
|
||||
OPT_HELP=false
|
||||
OPT_VERSION=false
|
||||
for opt in $@
|
||||
for opt in "$@"
|
||||
do
|
||||
case "$1" in
|
||||
-i|--setup-from-file) OPT_SETUP_FROM_FILE=true ; shift ; IMAGE_FILE=$1 ; shift ;;
|
||||
|
|
@ -140,8 +140,9 @@ function parse_arguments(){
|
|||
done
|
||||
|
||||
ARGS=()
|
||||
for arg do
|
||||
ARGS+=($arg)
|
||||
for arg in "$@"
|
||||
do
|
||||
ARGS+=("$arg")
|
||||
done
|
||||
}
|
||||
|
||||
|
|
@ -169,11 +170,11 @@ function execute_operation(){
|
|||
fi
|
||||
|
||||
if $OPT_FAKEROOT; then
|
||||
run_juju_as_fakeroot "${PROOT_ARGS}" ${ARGS[@]}
|
||||
run_juju_as_fakeroot "${PROOT_ARGS}" "${ARGS[@]}"
|
||||
elif $OPT_ROOT; then
|
||||
run_juju_as_root ${ARGS[@]}
|
||||
run_juju_as_root "${ARGS[@]}"
|
||||
else
|
||||
run_juju_as_user "${PROOT_ARGS}" ${ARGS[@]}
|
||||
run_juju_as_user "${PROOT_ARGS}" "${ARGS[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
30
lib/core.sh
30
lib/core.sh
|
|
@ -71,7 +71,7 @@ fi
|
|||
PROOT_COMPAT="${JUJU_HOME}/opt/proot/proot-${ARCH}"
|
||||
PROOT_LINK=http://static.proot.me/proot-${ARCH}
|
||||
|
||||
SH="/bin/sh --login"
|
||||
SH=("/bin/sh" "--login")
|
||||
CHROOT=${JUJU_HOME}/usr/bin/arch-chroot
|
||||
TRUE=${JUJU_HOME}/usr/bin/true
|
||||
ID="${JUJU_HOME}/usr/bin/id -u"
|
||||
|
|
@ -149,7 +149,7 @@ function setup_from_file_juju(){
|
|||
|
||||
|
||||
function _define_chroot_args(){
|
||||
local comm=${SH}
|
||||
local comm=${SH[@]}
|
||||
[ "$1" != "" ] && comm="$@"
|
||||
echo $comm
|
||||
}
|
||||
|
|
@ -162,13 +162,14 @@ function run_juju_as_root(){
|
|||
|
||||
function _run_proot(){
|
||||
local proot_args="$1"
|
||||
shift
|
||||
if ${PROOT_COMPAT} $proot_args ${TRUE} &> /dev/null
|
||||
then
|
||||
JUJU_ENV=1 ${PROOT_COMPAT} ${@}
|
||||
JUJU_ENV=1 ${PROOT_COMPAT} $proot_args "${@}"
|
||||
elif PROOT_NO_SECCOMP=1 ${PROOT_COMPAT} $proot_args ${TRUE} &> /dev/null
|
||||
then
|
||||
warn "Proot error: Trying to execute proot with PROOT_NO_SECCOMP=1..."
|
||||
JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT_COMPAT} ${@}
|
||||
JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT_COMPAT} $proot_args "${@}"
|
||||
else
|
||||
die "Error: Check if the juju arguments are correct or use the option juju -p \"-k 3.10\""
|
||||
fi
|
||||
|
|
@ -176,26 +177,33 @@ function _run_proot(){
|
|||
|
||||
|
||||
function _run_juju_with_proot(){
|
||||
[ "$(_run_proot "" ${ID} 2> /dev/null )" == "0" ] && \
|
||||
die "You cannot access with root privileges. Use --root option instead."
|
||||
local proot_args="$1"
|
||||
shift
|
||||
|
||||
_run_proot "${@}"
|
||||
if [ "$1" != "" ]
|
||||
then
|
||||
_run_proot "${proot_args}" "${@}"
|
||||
else
|
||||
_run_proot "${proot_args}" "${SH[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function run_juju_as_fakeroot(){
|
||||
local proot_args="$1"
|
||||
shift
|
||||
local comm=$(_define_chroot_args "$@")
|
||||
_run_juju_with_proot "-S ${JUJU_HOME} ${proot_args}" ${comm}
|
||||
[ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
|
||||
die "You cannot access with root privileges. Use --root option instead."
|
||||
_run_juju_with_proot "-S ${JUJU_HOME} $proot_args" "${@}"
|
||||
}
|
||||
|
||||
|
||||
function run_juju_as_user(){
|
||||
local proot_args="$1"
|
||||
shift
|
||||
local comm=$(_define_chroot_args "$@")
|
||||
_run_juju_with_proot "-R ${JUJU_HOME} $proot_args" ${comm}
|
||||
[ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
|
||||
die "You cannot access with root privileges. Use --root option instead."
|
||||
_run_juju_with_proot "-R ${JUJU_HOME} $proot_args" "${@}"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -114,18 +114,26 @@ function test_run_juju_as_root(){
|
|||
|
||||
function test_run_juju_as_user(){
|
||||
install_mini_juju
|
||||
local output=$(run_juju_as_user "-k 3.10" "/usr/bin/mkdir -v /newdir2" | awk -F: '{print $1}')
|
||||
local output=$(run_juju_as_user "-k 3.10" "/usr/bin/mkdir" "-v" "/newdir2" | awk -F: '{print $1}')
|
||||
is_equal "$output" "/usr/bin/mkdir" || return 1
|
||||
[ -e $JUJU_HOME/newdir2 ]
|
||||
is_equal $? 0 || return 1
|
||||
|
||||
SH="/usr/bin/mkdir -v /newdir"
|
||||
SH=("/usr/bin/mkdir" "-v" "/newdir")
|
||||
local output=$(run_juju_as_user "-k 3.10" | awk -F: '{print $1}')
|
||||
is_equal "$output" "/usr/bin/mkdir" || return 1
|
||||
[ -e $JUJU_HOME/newdir ]
|
||||
is_equal $? 0 || return 1
|
||||
}
|
||||
|
||||
function test_run_juju_with_quotes(){
|
||||
install_mini_juju
|
||||
local output=$(run_juju_as_user "-k 3.10" "bash" "-c" "/usr/bin/mkdir -v /newdir2" | awk -F: '{print $1}')
|
||||
is_equal "$output" "/usr/bin/mkdir" || return 1
|
||||
[ -e $JUJU_HOME/newdir2 ]
|
||||
is_equal $? 0 || return 1
|
||||
}
|
||||
|
||||
function test_run_juju_as_user_proot_args(){
|
||||
install_mini_juju
|
||||
run_juju_as_user "--help" "" &> /dev/null
|
||||
|
|
@ -133,7 +141,7 @@ function test_run_juju_as_user_proot_args(){
|
|||
|
||||
mkdir $JUJU_TEMPDIR/newdir
|
||||
touch $JUJU_TEMPDIR/newdir/newfile
|
||||
run_juju_as_user "-b $JUJU_TEMPDIR/newdir:/newdir -k 3.10" "ls -l /newdir/newfile" &> /dev/null
|
||||
run_juju_as_user "-b $JUJU_TEMPDIR/newdir:/newdir -k 3.10" "ls" "-l" "/newdir/newfile" &> /dev/null
|
||||
is_equal $? 0 || return 1
|
||||
|
||||
export -f _run_juju_with_proot
|
||||
|
|
@ -141,7 +149,7 @@ function test_run_juju_as_user_proot_args(){
|
|||
export -f warn
|
||||
export -f die
|
||||
export PROOT_COMPAT
|
||||
ID="/bin/echo 1" bash -ic "_run_juju_with_proot --helps" &> /dev/null
|
||||
bash -ic "_run_juju_with_proot --helps" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
export -n _run_juju_with_proot
|
||||
export -n _run_proot
|
||||
|
|
@ -159,7 +167,7 @@ function test_run_juju_with_proot_compat(){
|
|||
export -f _run_proot
|
||||
export -f warn
|
||||
export -f die
|
||||
PROOT_COMPAT="/bin/false" ID="/bin/echo 1" bash -ic "_run_juju_with_proot --helps" &> /dev/null
|
||||
PROOT_COMPAT="/bin/false" bash -ic "_run_juju_with_proot --helps" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
export -n _run_juju_with_proot
|
||||
export -n _run_proot
|
||||
|
|
@ -169,15 +177,23 @@ function test_run_juju_with_proot_compat(){
|
|||
|
||||
function test_run_juju_with_proot_as_root(){
|
||||
install_mini_juju
|
||||
export -f _run_juju_with_proot
|
||||
export -f _run_proot
|
||||
export -f run_juju_as_user
|
||||
export -f run_juju_as_fakeroot
|
||||
export TRUE
|
||||
export PROOT_COMPAT
|
||||
ID="/bin/echo 0" bash -ic "_run_juju_with_proot" &> /dev/null
|
||||
ID="/bin/echo 0" bash -ic "run_juju_as_user" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
ID="/bin/echo 0" bash -ic "run_juju_as_fakeroot" &> /dev/null
|
||||
is_equal $? 1 || return 1
|
||||
export -n TRUE
|
||||
export -n PROOT_COMPAT
|
||||
export -n _run_juju_with_proot
|
||||
unset _run_juju_with_proot
|
||||
export -n _run_proot
|
||||
export -n run_juju_as_user
|
||||
export -n run_juju_as_fakeroot
|
||||
unset _run_proot
|
||||
unset run_juju_as_user
|
||||
unset run_juju_as_fakeroot
|
||||
}
|
||||
|
||||
function test_run_proot_seccomp(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue