From f52d0fa8b285d310ec883c03c3be924dc7fb71af Mon Sep 17 00:00:00 2001 From: Filippo Squillace Date: Tue, 21 Oct 2014 00:32:40 +0100 Subject: [PATCH] Define three type of users: normal, fakeroot and root --- README.md | 27 +++++++++++++++++++-------- bin/juju | 25 ++++++++++++++++++------- lib/core.sh | 45 ++++++++++++++++++--------------------------- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 78f6536..8155d49 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ JuJu ==== -**JuJu**: the portable GNU/Linux distribution. +**JuJu**: the portable GNU/Linux distribution Description ----------- @@ -19,17 +19,24 @@ The main advantage of using JuJu are: Quickstart ---------- -After installing JuJu (see next section) you can run juju either as root or as normal user. -To run as root: +There are three different ways you can run JuJu: - # juju - -To run as normal user: - - $ juju -n +- As normal user - Allow to make basic operations using [proot](https://wiki.archlinux.org/index.php/Proot): +``` +$ juju +``` +- As fakeroot - Allow to install/remove packages using [proot](https://wiki.archlinux.org/index.php/Proot): +``` +$ juju -f +``` +- As root - Allow to have fully root privileges inside JuJu environment using [arch-chroot](https://wiki.archlinux.org/index.php/Chroot) (you need to be root for executing this): +``` +# juju -r +``` The first time you execute it, the script will download the JuJu image and place it to the default directory ~/.juju. +You can change this behavior by changing the environment variable *JUJU\_HOME*. Installation ------------ @@ -63,7 +70,9 @@ Troubleshooting In order to install packages using yaourt you may need to install the package groups *base-devel* that contains all the essential packages for compiling source code (such as gcc, make, patch, etc): +``` pacman -S base-devel +``` - **Q**: Why do I get the error: "FATAL: kernel too old"? - **A**: This is because the executable from the precompiled package cannot @@ -71,8 +80,10 @@ always run if the kernel is old. In order to check if the executable can be compatible with the kernel of the host OS just use file command, for instance: +``` file ~/.juju/usr/bin/bash ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ec37e49e7188ff4030052783e61b859113e18ca6, stripped +``` From the output you can see what is the minimum recommended Linux kernel version. diff --git a/bin/juju b/bin/juju index 4258005..5cbacda 100755 --- a/bin/juju +++ b/bin/juju @@ -32,7 +32,8 @@ usage() { echo -e "Usage: $NAME [options]" echo -e "Options:" echo -e "-i, --setup-from-file Setup the JuJu image in ${JUJU_HOME}" - echo -e "-n, --no-root Run JuJu without root privileges" + echo -e "-f, --fakeroot Run JuJu with fakeroot privileges" + echo -e "-r, --root Run JuJu with root privileges" echo -e "-b, --build-image Build a JuJu image (must run in ArchLinux only)" echo -e "-h, --help Show this help message" echo -e "-v, --version Show the $NAME version" @@ -49,7 +50,7 @@ version() { ### MAIN PROGRAM ### ################################### -TEMP=`getopt -o nbihv --long no-root,build-image,setup-from-file,help,version -n 'juju' -- "$@"` +TEMP=`getopt -o rfbihv --long root,fakeroot,build-image,setup-from-file,help,version -n 'juju' -- "$@"` if [ $? != 0 ] ; then error "Error on parsing the command line. Try juju -h." ; exit ; fi @@ -57,14 +58,16 @@ if [ $? != 0 ] ; then error "Error on parsing the command line. Try juju -h." ; eval set -- "$TEMP" OPT_SETUP_FROM_FILE=false -OPT_NO_ROOT=false +OPT_FAKEROOT=false +OPT_ROOT=false OPT_BUILD_IMAGE=false OPT_HELP=false OPT_VERSION=false while true ; do case "$1" in -i|--setup-from-file) OPT_SETUP_FROM_FILE=true ; shift ;; - -n|--no-root) OPT_NO_ROOT=true ; shift ;; + -f|--fakeroot) OPT_FAKEROOT=true ; shift ;; + -r|--root) OPT_ROOT=true ; shift ;; -b|--build-image) OPT_BUILD_IMAGE=true ; shift ;; -h|--help) OPT_HELP=true ; shift ;; -v|--version) OPT_VERSION=true ; shift ;; @@ -92,12 +95,20 @@ fi ################ DEFINE ACTION ######################## if $OPT_SETUP_FROM_FILE; then setup_from_file_juju ${ARGS[@]} -elif $OPT_NO_ROOT; then - setup_and_run_no_root_juju + exit elif $OPT_BUILD_IMAGE; then build_image_juju + exit +fi + +[ ! "$(ls -A $JUJU_HOME)" ] && setup_juju + +if $OPT_FAKEROOT; then + run_juju_as_fakeroot +elif $OPT_ROOT; then + run_juju_as_root else - setup_and_run_juju + run_juju_as_user fi # vim: set ts=4 sw=4 noet: diff --git a/lib/core.sh b/lib/core.sh index 30d8857..2d15d7d 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -53,6 +53,15 @@ function prepare_build_directory(){ } +function _setup_juju(){ + imagepath=$1 + mkdir -p ${JUJU_HOME} + tar -zxpf ${imagepath} -C ${JUJU_HOME} + mkdir -p ${JUJU_HOME}/run/lock + info "JuJu installed successfully" +} + + function setup_juju(){ # Setup the JuJu environment local maindir=$(TMPDIR=/tmp mktemp -d -t juju.XXXXXXXXXX) @@ -88,47 +97,29 @@ function setup_from_file_juju(){ } -function _setup_juju(){ - imagepath=$1 - mkdir -p ${JUJU_HOME} - tar -zxpf ${imagepath} -C ${JUJU_HOME} - mkdir -p ${JUJU_HOME}/run/lock - info "JuJu installed successfully" -} - - -function run_juju(){ +function run_juju_as_root(){ + mkdir -p ${JUJU_HOME}/${HOME} ${JUJU_HOME}/usr/bin/arch-chroot $JUJU_HOME /usr/bin/bash -c 'mkdir -p /run/lock && /bin/sh' } -function run_no_root_juju(){ +function _run_juju_with_proot(){ if ${JUJU_HOME}/usr/bin/proot ${JUJU_HOME}/usr/bin/true &> /dev/null then - ${JUJU_HOME}/usr/bin/proot -S ${JUJU_HOME} + ${JUJU_HOME}/usr/bin/proot $@ ${JUJU_HOME} else - PROOT_NO_SECCOMP=1 ${JUJU_HOME}/usr/bin/proot -S ${JUJU_HOME} + PROOT_NO_SECCOMP=1 ${JUJU_HOME}/usr/bin/proot $@ ${JUJU_HOME} fi } -function setup_and_run_juju(){ -# Setup and run the JuJu environment -# The setup function will be executed only if the -# JuJu envinronment in $JUJU_HOME is not present. - - [ ! "$(ls -A $JUJU_HOME)" ] && setup_juju - run_juju +function run_juju_as_fakeroot(){ + _run_juju_with_proot "-S" } -function setup_and_run_no_root_juju(){ -# Setup and run the JuJu environment -# The setup function will be executed only if the -# JuJu envinronment in $JUJU_HOME is not present. - - [ ! "$(ls -A $JUJU_HOME)" ] && setup_juju - run_no_root_juju +function run_juju_as_user(){ + _run_juju_with_proot "-R" }