From 21f3b6ebdad0f203a8f80489cf983e62b4a1dbeb Mon Sep 17 00:00:00 2001 From: Filippo Squillace Date: Tue, 23 Jun 2015 21:44:49 +0000 Subject: [PATCH] Issue #89: Remove id executable --- lib/core.sh | 13 +++++++------ tests/test_core.sh | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/core.sh b/lib/core.sh index 8097941..ee713b3 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -82,7 +82,6 @@ ORIGIN_WD=$(pwd) # List of executables that are run inside JuNest: SH=("/bin/sh" "--login") -ID="id -u" # List of executables that are run in the host OS: PROOT_COMPAT="${JUNEST_HOME}/opt/proot/proot-${ARCH}" @@ -230,10 +229,11 @@ function _run_env_with_proot(){ function run_env_as_fakeroot(){ + (( EUID == 0 )) && \ + die "You cannot access with root privileges. Use --root option instead." + local proot_args="$1" shift - [ "$(proot_cmd -R ${JUNEST_HOME} $proot_args ${ID} 2> /dev/null )" == "0" ] && \ - die "You cannot access with root privileges. Use --root option instead." [ ! -e ${JUNEST_HOME}/etc/mtab ] && ln_cmd -s /proc/self/mounts ${JUNEST_HOME}/etc/mtab _run_env_with_proot "-S ${JUNEST_HOME} $proot_args" "${@}" @@ -241,10 +241,11 @@ function run_env_as_fakeroot(){ function run_env_as_user(){ + (( EUID == 0 )) && \ + die "You cannot access with root privileges. Use --root option instead." + local proot_args="$1" shift - [ "$(proot_cmd -R ${JUNEST_HOME} $proot_args ${ID} 2> /dev/null )" == "0" ] && \ - die "You cannot access with root privileges. Use --root option instead." [ -e ${JUNEST_HOME}/etc/mtab ] && rm_cmd -f ${JUNEST_HOME}/etc/mtab _run_env_with_proot "-R ${JUNEST_HOME} $proot_args" "${@}" @@ -283,7 +284,7 @@ function _check_package(){ function build_image_env(){ # The function must runs on ArchLinux with non-root privileges. - [ "$(${ID})" == "0" ] && \ + (( EUID == 0 )) && \ die "You cannot build with root privileges." _check_package arch-install-scripts diff --git a/tests/test_core.sh b/tests/test_core.sh index 1d0984c..1f40693 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -297,11 +297,13 @@ function test_run_env_with_proot_compat(){ } function test_run_env_with_proot_as_root(){ + [ $SKIP_ROOT_TESTS -eq 1 ] && return + install_mini_env - $(ID="/bin/echo 0" run_env_as_user 2> /dev/null) + $(sudo run_env_as_user 2> /dev/null) assertEquals $? 1 - $(ID="/bin/echo 0" run_env_as_fakeroot 2> /dev/null) + $(sudo run_env_as_fakeroot 2> /dev/null) assertEquals $? 1 }