diff --git a/README.md b/README.md index e99bc2c..7e0344f 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,8 @@ of GNU/Linux distributions. The needed executables in the host OS are: - bash - wget or curl - tar -- id - mkdir +- chown (for root access only) The minimum recommended linux kernel is 2.6.0+ @@ -171,24 +171,20 @@ To quick fix this, you can just install a fonts package: pacman -S gnu-free-fonts ``` -###Missing permissions on removing a package### -- **Q**: Why I cannot remove the package I have installed? +###Differences between filesystem and package ownership### +- **Q**: Why do I get warning when I install a package using root privileges? ``` - pacman -Rsn lsof - checking dependencies... - - Packages (1): lsof-4.88-1 - - Total Removed Size: 0.21 MiB - - error: cannot remove /usr/share/licenses/lsof/LICENSE (Permission denied) - error: could not remove database entry lsof-4.88-1 + pacman -S systat + ... + warning: directory ownership differs on /usr/ + filesystem: 1000:100 package: 0:0 + ... ``` -- **A**: This is probably because you have installed the package with root -permissions. Since JuJu gives the possibility to install packages -either as root or as normal user you need to remember that and remove -the package with the right user! +- **A**: In these cases the package installation went smoothly anyway. +This should happen every time you install package with root privileges +since JuJu will try to preserve the JuJu environment by assigning ownership +of the files to the real user. ###No servers configured for repository### -**Q**: Why I cannot install packages? diff --git a/lib/core.sh b/lib/core.sh index d5d9a27..de17eaf 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -73,8 +73,9 @@ PROOT_LINK=http://static.proot.me/proot-${ARCH} SH=("/bin/sh" "--login") CHROOT=${JUJU_HOME}/usr/bin/arch-chroot -TRUE=${JUJU_HOME}/usr/bin/true -ID="${JUJU_HOME}/usr/bin/id -u" +TRUE=/usr/bin/true +ID="/usr/bin/id -u" +CHOWN="/usr/bin/chown" ################################# MAIN FUNCTIONS ############################## @@ -148,16 +149,23 @@ function setup_from_file_juju(){ } -function _define_chroot_args(){ - local comm=${SH[@]} - [ "$1" != "" ] && comm="$@" - echo $comm -} - - function run_juju_as_root(){ - mkdir -p ${JUJU_HOME}/${HOME} - JUJU_ENV=1 ${CHROOT} $JUJU_HOME /usr/bin/bash -c "mkdir -p /run/lock && $(_define_chroot_args "$@")" + 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} +" + + JUJU_ENV=1 ${CHROOT} $JUJU_HOME /usr/bin/bash -c "${cmd}" + + # The ownership of the files in JuJu is assigned to the real user + [ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME} } function _run_proot(){ @@ -239,7 +247,7 @@ function _check_package(){ function build_image_juju(){ # The function must runs on ArchLinux with non-root privileges. - [ "$(id -u)" == "0" ] && \ + [ "$(${ID})" == "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 6421d09..f84b17d 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -102,14 +102,21 @@ function test_setup_from_file_juju_with_absolute_path(){ function test_run_juju_as_root(){ install_mini_juju CHROOT="sudo $CHROOT" - SH="type -t type" + CHOWN="sudo $CHOWN" + SH=("type" "-t" "type") local output=$(run_juju_as_root) is_equal $output "builtin" || return 1 local output=$(run_juju_as_root pwd) is_equal $output "/" || return 1 run_juju_as_root "[ -e /run/lock ]" is_equal $? 0 || return 1 - [ -e $JUJU_HOME/${HOME} ] || return 1 + run_juju_as_root "[ -e $HOME ]" + is_equal $? 0 || return 1 + + # 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") + is_equal $output "$UID" || return 1 } function test_run_juju_as_user(){