diff --git a/bin/juju b/bin/juju index 8ff792b..1df1997 100755 --- a/bin/juju +++ b/bin/juju @@ -18,15 +18,6 @@ # along with this program. If not, see . # -NAME='JuJu' -CMD='juju' -VERSION='3.6.9' -CODE_NAME='Snake' -DESCRIPTION='The GNU/Linux distribution container for non-root users' -AUTHOR='Filippo Squillace ' -HOMEPAGE='https://github.com/fsquillace/juju' -COPYRIGHT='2012-2014' - source "$(dirname $0)/../lib/core.sh" ################################### @@ -35,7 +26,7 @@ source "$(dirname $0)/../lib/core.sh" usage() { echo -e "$NAME: $DESCRIPTION" - echo -e "Usage: $CMD [options] [command]" + echo -e "Usage: $CMD [options] [--] [command]" echo -e "Options:" echo -e "-i, --setup-from-file Setup the $NAME image in ${JUJU_HOME}" echo -e "-f, --fakeroot Run $NAME with fakeroot privileges" @@ -162,30 +153,30 @@ function execute_operation(){ $OPT_VERSION && version && return if $OPT_BUILD_IMAGE; then - build_image_juju $OPT_DISABLE_VALIDATION + build_image_env $OPT_DISABLE_VALIDATION return elif $OPT_DELETE; then - delete_juju + delete_env return fi - if ! is_juju_installed + if ! is_env_installed then if $OPT_SETUP_FROM_FILE; then - setup_from_file_juju $IMAGE_FILE + setup_env_from_file $IMAGE_FILE else - setup_juju + setup_env fi elif $OPT_SETUP_FROM_FILE; then die "Error: The image cannot be installed since $JUJU_HOME is not empty." fi if $OPT_FAKEROOT; then - run_juju_as_fakeroot "${PROOT_ARGS}" "${ARGS[@]}" + run_env_as_fakeroot "${PROOT_ARGS}" "${ARGS[@]}" elif $OPT_ROOT; then - run_juju_as_root "${ARGS[@]}" + run_env_as_root "${ARGS[@]}" else - run_juju_as_user "${PROOT_ARGS}" "${ARGS[@]}" + run_env_as_user "${PROOT_ARGS}" "${ARGS[@]}" fi } diff --git a/lib/core.sh b/lib/core.sh index dbe27d6..e98a085 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash # -# This file is part of JuJu (https://github.com/fsquillace/juju). -# # Copyright (c) 2012-2015 # # This program is free software; you can redistribute it and/or modify it @@ -29,20 +27,31 @@ source "$(dirname ${BASH_ARGV[0]})/util.sh" ################################# VARIABLES ############################## +NAME='JuJu' +CMD='juju' +VERSION='3.6.9' +CODE_NAME='Snake' +DESCRIPTION='The Arch Linux based distro that runs upon any Linux distros without root access' +AUTHOR='Filippo Squillace ' +HOMEPAGE="https://github.com/fsquillace/${CMD}" +COPYRIGHT='2012-2015' + + if [ "$JUJU_ENV" == "1" ] then - die "Error: Nested JuJu environments are not allowed" + die "Error: Nested ${NAME} environments are not allowed" elif [ ! -z $JUJU_ENV ] && [ "$JUJU_ENV" != "0" ] then die "The variable JUJU_ENV is not properly set" fi -[ -z ${JUJU_HOME} ] && JUJU_HOME=~/.juju +[ -z ${JUJU_HOME} ] && JUJU_HOME=~/.${CMD} if [ -z ${JUJU_TEMPDIR} ] || [ ! -d ${JUJU_TEMPDIR} ] then JUJU_TEMPDIR=/tmp fi -JUJU_REPO=https://bitbucket.org/fsquillace/juju-repo/raw/master + +ENV_REPO=https://bitbucket.org/fsquillace/${CMD}-repo/raw/master ORIGIN_WD=$(pwd) WGET="wget --no-check-certificate" @@ -88,7 +97,7 @@ function download(){ die "Error: Both wget and curl commands have failed on downloading $1" } -function is_juju_installed(){ +function is_env_installed(){ [ -d "$JUJU_HOME" ] && [ "$(ls -A $JUJU_HOME)" ] && return 0 return 1 } @@ -105,12 +114,12 @@ function _cleanup_build_directory(){ function _prepare_build_directory(){ trap - QUIT EXIT ABRT KILL TERM INT - trap "rm -rf ${maindir}; die \"Error occurred when installing JuJu\"" EXIT QUIT ABRT KILL TERM INT + trap "rm -rf ${maindir}; die \"Error occurred when installing ${NAME}\"" EXIT QUIT ABRT KILL TERM INT } -function _setup_juju(){ - is_juju_installed && die "Error: JuJu has been already installed in $JUJU_HOME" +function _setup_env(){ + is_env_installed && die "Error: ${NAME} has been already installed in $JUJU_HOME" mkdir -p "${JUJU_HOME}" imagepath=$1 $TAR -zxpf ${imagepath} -C ${JUJU_HOME} @@ -120,42 +129,38 @@ function _setup_juju(){ info " nano /etc/pacman.d/mirrorlist" info "Remember to refresh the package databases from the server:" info " pacman -Syy" - info "JuJu installed successfully" + info "${NAME} installed successfully" } -function setup_juju(){ -# Setup the JuJu environment - - local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t juju.XXXXXXXXXX) +function setup_env(){ + local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t ${CMD}.XXXXXXXXXX) _prepare_build_directory - info "Downloading JuJu..." + info "Downloading ${NAME}..." builtin cd ${maindir} - local imagefile=juju-${ARCH}.tar.gz - download ${JUJU_REPO}/${imagefile} + local imagefile=${CMD}-${ARCH}.tar.gz + download ${ENV_REPO}/${imagefile} - info "Installing JuJu..." - _setup_juju ${maindir}/${imagefile} + info "Installing ${NAME}..." + _setup_env ${maindir}/${imagefile} _cleanup_build_directory ${maindir} } -function setup_from_file_juju(){ -# Setup from file the JuJu environment - +function setup_env_from_file(){ local imagefile=$1 - [ ! -e ${imagefile} ] && die "Error: The JuJu image file ${imagefile} does not exist" + [ ! -e ${imagefile} ] && die "Error: The ${NAME} image file ${imagefile} does not exist" - info "Installing JuJu from ${imagefile}..." - _setup_juju ${imagefile} + info "Installing ${NAME} from ${imagefile}..." + _setup_env ${imagefile} builtin cd $ORIGIN_WD } -function run_juju_as_root(){ +function run_env_as_root(){ local uid=$UID [ -z $SUDO_UID ] || uid=$SUDO_UID:$SUDO_GID @@ -181,7 +186,7 @@ function run_juju_as_root(){ die "Error: Chroot does not work" fi - # The ownership of the files in JuJu is assigned to the real user + # The ownership of the files is assigned to the real user [ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME} [ -e ${JUJU_HOME}/etc/mtab ] && rm -r ${JUJU_HOME}/etc/mtab @@ -201,12 +206,12 @@ function _run_proot(){ warn "Proot error: Trying to execute proot with PROOT_NO_SECCOMP=1..." 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\"" + die "Error: Check if the ${CMD} arguments are correct or use the option ${CMD} -p \"-k 3.10\"" fi } -function _run_juju_with_proot(){ +function _run_env_with_proot(){ local proot_args="$1" shift @@ -219,46 +224,46 @@ function _run_juju_with_proot(){ } -function run_juju_as_fakeroot(){ +function run_env_as_fakeroot(){ local proot_args="$1" shift [ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \ die "You cannot access with root privileges. Use --root option instead." [ ! -e ${JUJU_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJU_HOME}/etc/mtab - _run_juju_with_proot "-S ${JUJU_HOME} $proot_args" "${@}" + _run_env_with_proot "-S ${JUJU_HOME} $proot_args" "${@}" } -function run_juju_as_user(){ +function run_env_as_user(){ local proot_args="$1" shift [ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \ die "You cannot access with root privileges. Use --root option instead." [ -e ${JUJU_HOME}/etc/mtab ] && rm -f ${JUJU_HOME}/etc/mtab - _run_juju_with_proot "-R ${JUJU_HOME} $proot_args" "${@}" + _run_env_with_proot "-R ${JUJU_HOME} $proot_args" "${@}" } -function delete_juju(){ - ! ask "Are you sure to delete JuJu located in ${JUJU_HOME}" "N" && return +function delete_env(){ + ! ask "Are you sure to delete ${NAME} located in ${JUJU_HOME}" "N" && return if mountpoint -q ${JUJU_HOME} then info "There are mounted directories inside ${JUJU_HOME}" if ! umount --force ${JUJU_HOME} then error "Cannot umount directories in ${JUJU_HOME}" - die "Try to delete juju using root permissions" + die "Try to delete ${NAME} using root permissions" fi fi # the CA directories are read only and can be deleted only by changing the mod chmod -R +w ${JUJU_HOME}/etc/ca-certificates if rm -rf ${JUJU_HOME}/* then - info "JuJu deleted in ${JUJU_HOME}" + info "${NAME} deleted in ${JUJU_HOME}" else - error "Error: Cannot delete JuJu in ${JUJU_HOME}" + error "Error: Cannot delete ${NAME} in ${JUJU_HOME}" fi } @@ -271,7 +276,7 @@ function _check_package(){ } -function build_image_juju(){ +function build_image_env(){ # The function must runs on ArchLinux with non-root privileges. [ "$(${ID})" == "0" ] && \ die "You cannot build with root privileges." @@ -283,10 +288,10 @@ function build_image_juju(){ local disable_validation=$1 - local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t juju.XXXXXXXXXX) + local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t ${CMD}.XXXXXXXXXX) sudo mkdir -p ${maindir}/root trap - QUIT EXIT ABRT KILL TERM INT - trap "sudo rm -rf ${maindir}; die \"Error occurred when installing JuJu\"" EXIT QUIT ABRT KILL TERM INT + trap "sudo rm -rf ${maindir}; die \"Error occurred when installing ${NAME}\"" EXIT QUIT ABRT KILL TERM INT info "Installing pacman and its dependencies..." # The archlinux-keyring and libunistring are due to missing dependencies declaration in ARM archlinux # yaourt requires sed @@ -326,11 +331,11 @@ function build_image_juju(){ sudo sed -i -e 's/"--asroot"//' ${maindir}/root/opt/yaourt/bin/yaourt sudo cp ${maindir}/root/usr/bin/makepkg ${maindir}/root/opt/yaourt/bin/ sudo sed -i -e 's/EUID\s==\s0/false/' ${maindir}/root/opt/yaourt/bin/makepkg - sudo bash -c "echo 'export PATH=/opt/yaourt/bin:$PATH' > ${maindir}/root/etc/profile.d/juju.sh" - sudo chmod +x ${maindir}/root/etc/profile.d/juju.sh + sudo bash -c "echo 'export PATH=/opt/yaourt/bin:$PATH' > ${maindir}/root/etc/profile.d/${CMD}.sh" + sudo chmod +x ${maindir}/root/etc/profile.d/${CMD}.sh - info "Copying JuJu scripts..." - sudo git clone https://github.com/fsquillace/juju.git ${maindir}/root/opt/juju + info "Copying ${NAME} scripts..." + sudo git clone https://github.com/fsquillace/${CMD}.git ${maindir}/root/opt/${CMD} info "Setting up the pacman keyring (this might take a while!)..." sudo arch-chroot ${maindir}/root bash -c "pacman-key --init; pacman-key --populate archlinux" @@ -339,7 +344,7 @@ function build_image_juju(){ mkdir -p ${maindir}/output builtin cd ${maindir}/output - local imagefile="juju-${ARCH}.tar.gz" + local imagefile="${CMD}-${ARCH}.tar.gz" info "Compressing image to ${imagefile}..." sudo $TAR -zcpf ${imagefile} -C ${maindir}/root . @@ -356,32 +361,32 @@ function build_image_juju(){ function validate_image(){ local testdir=$1 local imagefile=$2 - info "Validating JuJu image..." + info "Validating ${NAME} image..." $TAR -zxpf ${imagefile} -C ${testdir} mkdir -p ${testdir}/run/lock sed -i -e "s/#Server/Server/" ${testdir}/etc/pacman.d/mirrorlist - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju -f pacman --noconfirm -Syy + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -Syy # Check most basic executables work - JUJU_HOME=${testdir} sudo ${testdir}/opt/juju/bin/juju -r pacman -Qi pacman 1> /dev/null - JUJU_HOME=${testdir} sudo ${testdir}/opt/juju/bin/juju -r yaourt -V 1> /dev/null - JUJU_HOME=${testdir} sudo ${testdir}/opt/juju/bin/juju -r /opt/proot/proot-$ARCH --help 1> /dev/null - JUJU_HOME=${testdir} sudo ${testdir}/opt/juju/bin/juju -r arch-chroot --help 1> /dev/null + JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r pacman -Qi pacman 1> /dev/null + JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r yaourt -V 1> /dev/null + JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r /opt/proot/proot-$ARCH --help 1> /dev/null + JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r arch-chroot --help 1> /dev/null - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju -f pacman --noconfirm -S base-devel + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S base-devel local yaourt_package=tcptraceroute info "Installing ${yaourt_package} package from AUR repo using proot..." - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju -f sh --login -c "yaourt --noconfirm -S ${yaourt_package}" - JUJU_HOME=${testdir} sudo ${testdir}/opt/juju/bin/juju -r tcptraceroute localhost + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f sh --login -c "yaourt --noconfirm -S ${yaourt_package}" + JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r tcptraceroute localhost local repo_package=sysstat info "Installing ${repo_package} package from official repo using proot..." - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju -f pacman --noconfirm -S ${repo_package} - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju iostat - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju -f iostat + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package} + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} iostat + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f iostat local repo_package=iftop info "Installing ${repo_package} package from official repo using root..." - JUJU_HOME=${testdir} ${testdir}/opt/juju/bin/juju -f pacman --noconfirm -S ${repo_package} - JUJU_HOME=${testdir} sudo ${testdir}/opt/juju/bin/juju -r iftop -t -s 5 + JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package} + JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r iftop -t -s 5 } diff --git a/tests/test_core.sh b/tests/test_core.sh index 1444445..ef144a2 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -4,22 +4,22 @@ function oneTimeSetUp(){ [ -z "$SKIP_ROOT_TESTS" ] && SKIP_ROOT_TESTS=0 CURRPWD=$PWD - JUJU_MAIN_HOME=/tmp/jujutesthome - [ -e $JUJU_MAIN_HOME ] || JUJU_HOME=$JUJU_MAIN_HOME bash --rcfile "$(dirname $0)/../lib/core.sh" -ic "setup_juju" + ENV_MAIN_HOME=/tmp/envtesthome + [ -e $ENV_MAIN_HOME ] || JUJU_HOME=$ENV_MAIN_HOME bash --rcfile "$(dirname $0)/../lib/core.sh" -ic "setup_env" JUJU_HOME="" } -function install_mini_juju(){ - cp -rfa $JUJU_MAIN_HOME/* $JUJU_HOME +function install_mini_env(){ + cp -rfa $ENV_MAIN_HOME/* $JUJU_HOME } function setUp(){ cd $CURRPWD - JUJU_HOME=$(TMPDIR=/tmp mktemp -d -t jujuhome.XXXXXXXXXX) + JUJU_HOME=$(TMPDIR=/tmp mktemp -d -t envhome.XXXXXXXXXX) source "$(dirname $0)/../lib/core.sh" - ORIGIN_WD=$(TMPDIR=/tmp mktemp -d -t jujuowd.XXXXXXXXXX) + ORIGIN_WD=$(TMPDIR=/tmp mktemp -d -t envowd.XXXXXXXXXX) cd $ORIGIN_WD - JUJU_TEMPDIR=$(TMPDIR=/tmp mktemp -d -t jujutemp.XXXXXXXXXX) + JUJU_TEMPDIR=$(TMPDIR=/tmp mktemp -d -t envtemp.XXXXXXXXXX) set +e @@ -38,11 +38,11 @@ function tearDown(){ } -function test_is_juju_installed(){ - is_juju_installed +function test_is_env_installed(){ + is_env_installed assertEquals $? 1 touch $JUJU_HOME/just_file - is_juju_installed + is_env_installed assertEquals $? 0 } @@ -63,7 +63,7 @@ function test_download(){ } -function test_setup_juju(){ +function test_setup_env(){ wget_mock(){ # Proof that the setup is happening # inside $JUJU_TEMPDIR @@ -71,148 +71,148 @@ function test_setup_juju(){ local parent_dir=${PWD%${cwd}} assertEquals "$JUJU_TEMPDIR" "${parent_dir}" touch file - tar -czvf juju-${ARCH}.tar.gz file + tar -czvf ${CMD}-${ARCH}.tar.gz file } WGET=wget_mock - setup_juju &> /dev/null + setup_env &> /dev/null assertTrue "[ -e $JUJU_HOME/file ]" assertTrue "[ -e $JUJU_HOME/run/lock ]" } -function test_setup_from_file_juju(){ +function test_setup_env_from_file(){ touch file - tar -czvf juju-${ARCH}.tar.gz file 1> /dev/null - setup_from_file_juju juju-${ARCH}.tar.gz &> /dev/null + tar -czvf ${CMD}-${ARCH}.tar.gz file 1> /dev/null + setup_env_from_file ${CMD}-${ARCH}.tar.gz &> /dev/null assertTrue "[ -e $JUJU_HOME/file ]" assertTrue "[ -e $JUJU_HOME/run/lock ]" - $(setup_from_file_juju noexist.tar.gz 2> /dev/null) + $(setup_env_from_file noexist.tar.gz 2> /dev/null) assertEquals $? 1 } -function test_setup_from_file_juju_with_absolute_path(){ +function test_setup_env_from_file_with_absolute_path(){ touch file - tar -czvf juju-${ARCH}.tar.gz file 1> /dev/null - setup_from_file_juju ${ORIGIN_WD}/juju-${ARCH}.tar.gz &> /dev/null + tar -czvf ${CMD}-${ARCH}.tar.gz file 1> /dev/null + setup_env_from_file ${ORIGIN_WD}/${CMD}-${ARCH}.tar.gz &> /dev/null assertTrue "[ -e $JUJU_HOME/file ]" assertTrue "[ -e $JUJU_HOME/run/lock ]" } -function test_run_juju_as_root(){ +function test_run_env_as_root(){ [ $SKIP_ROOT_TESTS -eq 1 ] && return - install_mini_juju + install_mini_env CHROOT="sudo $CHROOT" CLASSIC_CHROOT="sudo $CLASSIC_CHROOT" CHOWN="sudo $CHOWN" - local output=$(run_juju_as_root pwd) + local output=$(run_env_as_root pwd) assertEquals "/" "$output" - run_juju_as_root [ -e /run/lock ] + run_env_as_root [ -e /run/lock ] assertEquals 0 $? - run_juju_as_root [ -e $HOME ] + run_env_as_root [ -e $HOME ] assertEquals 0 $? # test that normal user has ownership of the files created by root - run_juju_as_root touch /a_root_file - local output=$(run_juju_as_root stat -c '%u' /a_root_file) + run_env_as_root touch /a_root_file + local output=$(run_env_as_root stat -c '%u' /a_root_file) assertEquals "$UID" "$output" SH=("sh" "--login" "-c" "type -t type") - local output=$(run_juju_as_root) + local output=$(run_env_as_root) assertEquals "builtin" "$output" SH=("sh" "--login" "-c" "[ -e /run/lock ]") - run_juju_as_root + run_env_as_root assertEquals 0 $? SH=("sh" "--login" "-c" "[ -e $HOME ]") - run_juju_as_root + run_env_as_root assertEquals 0 $? } -function test_run_juju_as_classic_root(){ +function test_run_env_as_classic_root(){ [ $SKIP_ROOT_TESTS -eq 1 ] && return - install_mini_juju + install_mini_env CHROOT="sudo unknowncommand" CLASSIC_CHROOT="sudo $CLASSIC_CHROOT" CHOWN="sudo $CHOWN" - local output=$(run_juju_as_root pwd 2> /dev/null) + local output=$(run_env_as_root pwd 2> /dev/null) assertEquals "/" "$output" - run_juju_as_root [ -e /run/lock ] 2> /dev/null + run_env_as_root [ -e /run/lock ] 2> /dev/null assertEquals 0 $? - run_juju_as_root [ -e $HOME ] 2> /dev/null + run_env_as_root [ -e $HOME ] 2> /dev/null assertEquals 0 $? } -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}') +function test_run_env_as_user(){ + install_mini_env + local output=$(run_env_as_user "-k 3.10" "/usr/bin/mkdir" "-v" "/newdir2" | awk -F: '{print $1}') assertEquals "$output" "/usr/bin/mkdir" assertTrue "[ -e $JUJU_HOME/newdir2 ]" SH=("/usr/bin/mkdir" "-v" "/newdir") - local output=$(run_juju_as_user "-k 3.10" | awk -F: '{print $1}') + local output=$(run_env_as_user "-k 3.10" | awk -F: '{print $1}') assertEquals "$output" "/usr/bin/mkdir" assertTrue "[ -e $JUJU_HOME/newdir ]" } -function test_run_juju_as_proot_mtab(){ - install_mini_juju - $(run_juju_as_fakeroot "-k 3.10" "echo") +function test_run_env_as_proot_mtab(){ + install_mini_env + $(run_env_as_fakeroot "-k 3.10" "echo") assertTrue "[ -e $JUJU_HOME/etc/mtab ]" - $(run_juju_as_user "-k 3.10" "echo") + $(run_env_as_user "-k 3.10" "echo") assertTrue "[ ! -e $JUJU_HOME/etc/mtab ]" } -function test_run_juju_as_root_mtab(){ +function test_run_env_as_root_mtab(){ [ $SKIP_ROOT_TESTS -eq 1 ] && return - install_mini_juju + install_mini_env CHROOT="sudo $CHROOT" CLASSIC_CHROOT="sudo $CLASSIC_CHROOT" CHOWN="sudo $CHOWN" - $(run_juju_as_root "echo") + $(run_env_as_root "echo") assertTrue "[ ! -e $JUJU_HOME/etc/mtab ]" } -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}') +function test_run_env_with_quotes(){ + install_mini_env + local output=$(run_env_as_user "-k 3.10" "bash" "-c" "/usr/bin/mkdir -v /newdir2" | awk -F: '{print $1}') assertEquals "$output" "/usr/bin/mkdir" assertTrue "[ -e $JUJU_HOME/newdir2 ]" } -function test_run_juju_as_user_proot_args(){ - install_mini_juju - run_juju_as_user "--help" "" &> /dev/null +function test_run_env_as_user_proot_args(){ + install_mini_env + run_env_as_user "--help" "" &> /dev/null assertEquals $? 0 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_env_as_user "-b $JUJU_TEMPDIR/newdir:/newdir -k 3.10" "ls" "-l" "/newdir/newfile" &> /dev/null assertEquals $? 0 - $(_run_juju_with_proot --helps 2> /dev/null) + $(_run_env_with_proot --helps 2> /dev/null) assertEquals $? 1 } -function test_run_juju_with_proot_compat(){ +function test_run_env_with_proot_compat(){ PROOT_COMPAT="/bin/true" - _run_juju_with_proot "" "" &> /dev/null + _run_env_with_proot "" "" &> /dev/null assertEquals $? 0 - $(PROOT_COMPAT="/bin/false" _run_juju_with_proot --helps 2> /dev/null) + $(PROOT_COMPAT="/bin/false" _run_env_with_proot --helps 2> /dev/null) assertEquals $? 1 } -function test_run_juju_with_proot_as_root(){ - install_mini_juju +function test_run_env_with_proot_as_root(){ + install_mini_env - $(ID="/bin/echo 0" run_juju_as_user 2> /dev/null) + $(ID="/bin/echo 0" run_env_as_user 2> /dev/null) assertEquals $? 1 - $(ID="/bin/echo 0" run_juju_as_fakeroot 2> /dev/null) + $(ID="/bin/echo 0" run_env_as_fakeroot 2> /dev/null) assertEquals $? 1 } @@ -230,24 +230,24 @@ function test_run_proot_seccomp(){ assertEquals "$output" "PROOT_NO_SECCOMP=1" } -function test_run_juju_as_fakeroot(){ - install_mini_juju - local output=$(run_juju_as_fakeroot "-k 3.10" "id" | awk '{print $1}') +function test_run_env_as_fakeroot(){ + install_mini_env + local output=$(run_env_as_fakeroot "-k 3.10" "id" | awk '{print $1}') assertEquals "$output" "uid=0(root)" } -function test_delete_juju(){ - install_mini_juju - echo "N" | delete_juju 1> /dev/null - is_juju_installed +function test_delete_env(){ + install_mini_env + echo "N" | delete_env 1> /dev/null + is_env_installed assertEquals $? 0 - echo "Y" | delete_juju 1> /dev/null - is_juju_installed + echo "Y" | delete_env 1> /dev/null + is_env_installed assertEquals $? 1 } -function test_nested_juju(){ - install_mini_juju +function test_nested_env(){ + install_mini_env JUJU_ENV=1 bash -ic "source $CURRPWD/$(dirname $0)/../lib/core.sh" &> /dev/null assertEquals $? 1 } diff --git a/tests/test_juju.sh b/tests/test_juju.sh deleted file mode 100755 index e16a648..0000000 --- a/tests/test_juju.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash -source $(dirname $0)/../bin/juju -h &> /dev/null - -# Disable the exiterr -set +e - -## Mock functions ## -function usage(){ - echo "usage" -} -function version(){ - echo "version" -} -function build_image_juju(){ - echo "build_image_juju" -} -function delete_juju(){ - echo "delete_juju" -} -function is_juju_installed(){ - return 0 -} -function setup_from_file_juju(){ - echo "setup_from_file_juju $@" -} -function setup_juju(){ - echo "setup_juju" -} -function run_juju_as_fakeroot(){ - local proot_args="$1" - shift - echo "run_juju_as_fakeroot($proot_args,$@)" -} -function run_juju_as_root(){ - echo "run_juju_as_root $@" -} -function run_juju_as_user(){ - local proot_args="$1" - shift - echo "run_juju_as_user($proot_args,$@)" -} - -function wrap_juju(){ - parse_arguments "$@" - check_cli - execute_operation -} - -function test_help(){ - local output=$(wrap_juju -h) - assertEquals $output "usage" - local output=$(wrap_juju --help) - assertEquals $output "usage" -} -function test_version(){ - local output=$(wrap_juju -v) - assertEquals $output "version" - local output=$(wrap_juju --version) - assertEquals $output "version" -} -function test_build_image_juju(){ - local output=$(wrap_juju -b) - assertEquals $output "build_image_juju" - local output=$(wrap_juju --build-image) - assertEquals $output "build_image_juju" -} -function test_delete_juju(){ - local output=$(wrap_juju -d) - assertEquals $output "delete_juju" - local output=$(wrap_juju --delete) - assertEquals $output "delete_juju" -} -function test_run_juju_as_fakeroot(){ - local output=$(wrap_juju -f) - assertEquals $output "run_juju_as_fakeroot(,)" - local output=$(wrap_juju --fakeroot) - assertEquals $output "run_juju_as_fakeroot(,)" - - local output=$(wrap_juju -f -p "-b arg") - assertEquals "${output[@]}" "run_juju_as_fakeroot(-b arg,)" - local output=$(wrap_juju -f -p "-b arg" -- command -kv) - assertEquals "${output[@]}" "run_juju_as_fakeroot(-b arg,command -kv)" - local output=$(wrap_juju -f command --as) - assertEquals "${output[@]}" "run_juju_as_fakeroot(,command --as)" -} -function test_run_juju_as_user(){ - local output=$(wrap_juju) - assertEquals $output "run_juju_as_user(,)" - - local output=$(wrap_juju -p "-b arg") - assertEquals "$output" "run_juju_as_user(-b arg,)" - local output=$(wrap_juju -p "-b arg" -- command -ll) - assertEquals "$output" "run_juju_as_user(-b arg,command -ll)" - local output=$(wrap_juju command -ls) - assertEquals "$output" "run_juju_as_user(,command -ls)" -} -function test_run_juju_as_root(){ - local output=$(wrap_juju -r) - assertEquals $output "run_juju_as_root" - - local output=$(wrap_juju -r command) - assertEquals "${output[@]}" "run_juju_as_root command" -} - -function test_check_cli(){ - $(wrap_juju -b -h 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -n -v 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -d -r 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -h -f 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -v -i fsd 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -f -r 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -p args -v 2> /dev/null) - assertEquals $? 1 - $(wrap_juju -d args 2> /dev/null) - assertEquals $? 1 -} - -source $(dirname $0)/shunit2