Merge pull request #70 from fsquillace/issue_58

Issue 58
This commit is contained in:
Filippo Squillace 2015-04-09 00:24:57 +01:00
commit 47c017f1a4
6 changed files with 62 additions and 25 deletions

View file

@ -5,13 +5,12 @@ install:
- juju -f echo 'Installing juju'
- sed -i -e "s/#Server/Server/" ~/.juju/etc/pacman.d/mirrorlist
- juju -f pacman --noconfirm -Syy
- juju -f pacman --noconfirm -S base-devel
script:
- SKIP_ROOT_TESTS=1 ./tests/test_all.sh
# Test on installing package from AUR (issue #58)
#- juju -f pacman --noconfirm -S base-devel
#- juju -f yaourt --noconfirm -S tcptraceroute
#- juju -f tcptraceroute localhost
# Test on installing package from AUR
- juju -f yaourt --noconfirm -S tcptraceroute
# Test on installing package from official repo
- juju -f pacman --noconfirm -S sysstat
- juju -f iostat

View file

@ -150,22 +150,24 @@ function setup_from_file_juju(){
function run_juju_as_root(){
local main_cmd="${SH[@]}"
[ "$1" != "" ] && main_cmd="$@"
local uid=$UID
[ -z $SUDO_UID ] || uid=$SUDO_UID:$SUDO_GID
local cmd="
mkdir -p ${JUJU_HOME}/${HOME}
mkdir -p /run/lock
${main_cmd}
"
local main_cmd="${SH[@]}"
[ "$1" != "" ] && main_cmd="$(insert_quotes_on_spaces "$@")"
local cmd="mkdir -p ${JUJU_HOME}/${HOME} && mkdir -p /run/lock && ${main_cmd}"
JUJU_ENV=1 ${CHROOT} $JUJU_HOME /usr/bin/bash -c "${cmd}"
trap - QUIT EXIT ABRT KILL TERM INT
trap "[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}" EXIT QUIT ABRT KILL TERM INT
JUJU_ENV=1 ${CHROOT} $JUJU_HOME "${SH[@]}" "-c" "${cmd}"
local ret=$?
# The ownership of the files in JuJu is assigned to the real user
[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}
trap - QUIT EXIT ABRT KILL TERM INT
return $?
}
function _run_proot(){
@ -190,7 +192,7 @@ function _run_juju_with_proot(){
if [ "$1" != "" ]
then
_run_proot "${proot_args}" "${@}"
_run_proot "${proot_args}" "${SH[@]}" "-c" "$(insert_quotes_on_spaces "${@}")"
else
_run_proot "${proot_args}" "${SH[@]}"
fi

View file

@ -67,3 +67,21 @@ function ask(){
fi
}
function insert_quotes_on_spaces(){
# It inserts quotes between arguments.
# Useful to preserve quotes on command
# to be used inside sh -c/bash -c
C=''
whitespace="[[:space:]]"
for i in "$@"
do
if [[ $i =~ $whitespace ]]
then
C="$C \"$i\""
else
C="$C $i"
fi
done
echo $C
}

View file

@ -1,5 +1,7 @@
tests_succeded=true
for tst in $(ls $(dirname $0)/test_* | grep -v $(basename $0))
do
$tst
$tst || tests_succeded=false
done
$tests_succeded

View file

@ -105,20 +105,28 @@ function test_run_juju_as_root(){
install_mini_juju
CHROOT="sudo $CHROOT"
CHOWN="sudo $CHOWN"
SH=("type" "-t" "type")
local output=$(run_juju_as_root)
assertEquals $output "builtin"
local output=$(run_juju_as_root pwd)
assertEquals $output "/"
run_juju_as_root "[ -e /run/lock ]"
assertEquals "$output" "/"
run_juju_as_root [ -e /run/lock ]
assertEquals $? 0
run_juju_as_root "[ -e $HOME ]"
run_juju_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")
assertEquals $output "$UID"
run_juju_as_root touch /a_root_file
local output=$(run_juju_as_root stat -c '%u' /a_root_file)
assertEquals "$output" "$UID"
SH=("sh" "--login" "-c" "type -t type")
local output=$(run_juju_as_root)
assertEquals "$output" "builtin"
SH=("sh" "--login" "-c" "[ -e /run/lock ]")
run_juju_as_root
assertEquals $? 0
SH=("sh" "--login" "-c" "[ -e $HOME ]")
run_juju_as_root
assertEquals $? 0
}
function test_run_juju_as_user(){

View file

@ -52,4 +52,12 @@ function test_ask(){
assertEquals $? 1
}
function test_insert_quotes_on_spaces(){
local actual=$(insert_quotes_on_spaces this is "a test")
assertEquals "this is \"a test\"" "$actual"
local actual=$(insert_quotes_on_spaces this is 'a test')
assertEquals "this is \"a test\"" "$actual"
}
source $(dirname $0)/shunit2