Merge pull request #9 from fsquillace/proot_cli

Allow to specify specific command and Expose the Proot args to JuJu cli
This commit is contained in:
Filippo Squillace 2014-11-17 21:00:56 +00:00
commit f1297478e8
3 changed files with 59 additions and 15 deletions

View file

@ -52,10 +52,11 @@ JuJu can only works on GNU/Linux OS with kernel version greater or equal
Advanced usage
--------------
### Build image ###
You can build a new JuJu image from scratch by running the following command:
```
# juju -b
```
In this way the script will create a directory containing all the essentials
files in order to make JuJu working properly (such as pacman, yaourt, arch-chroot and proot).
Remember that the script to build the image must run in an ArchLinux OS with
@ -66,6 +67,17 @@ After creating the image juju-x86\_64.tar.gz you can install it by running:
# juju -i juju-x86_64.tar.gz
### Bind directories ###
To bind and host directory to a guest location, you can use proot arguments:
```
$ juju -p "-b /mnt/mydata:/home/user/mydata"
```
Check out the proot options with:
```
$ juju -p "--help"
```
Dependencies
------------
JuJu comes with a very short list of dependencies in order to be installed in most

View file

@ -29,11 +29,12 @@ source "$(dirname $0)/../lib/core.sh"
usage() {
echo -e "JuJu: The portable GNU/Linux distribution"
echo -e "Usage: $NAME [options]"
echo -e "Usage: $NAME [options] [command]"
echo -e "Options:"
echo -e "-i, --setup-from-file <image> Setup the JuJu image in ${JUJU_HOME}"
echo -e "-f, --fakeroot Run JuJu with fakeroot privileges"
echo -e "-r, --root Run JuJu with root privileges"
echo -e "-p, --proot-args Proot arguments"
echo -e "-b, --build-image Build a JuJu image (must run in ArchLinux)"
echo -e "-d, --delete Delete JuJu from ${JUJU_HOME}"
echo -e "-h, --help Show this help message"
@ -79,13 +80,26 @@ check_cli(){
die "The JuJu version option must be used exclusively"
fi
fi
if $OPT_FAKEROOT && $OPT_ROOT
then
die "You must access to JuJu with either fakeroot or root permissions"
fi
[ "$ARGS" != "" ] && die "No arguments are needed. For the CLI syntax run: $NAME --help"
if $OPT_PROOT_ARGS
then
if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \
$OPT_ROOT || $OPT_VERSION
then
die "Invalid syntax: Proot args are not allowed with the other options"
fi
fi
if [ "$ARGS" != "" ]
then
if $OPT_BUILD_IMAGE || $OPT_DELETE || $OPT_HELP || $OPT_SETUP_FROM_FILE || \
$OPT_VERSION
then
die "No arguments are needed. For the CLI syntax run: $NAME --help"
fi
fi
return 0
}
@ -95,7 +109,7 @@ check_cli(){
### MAIN PROGRAM ###
###################################
TEMP=`getopt -o drfbi:hv --long delete,root,fakeroot,build-image,setup-from-file:,help,version -n 'juju' -- "$@"`
TEMP=`getopt -o drp:fbi:hv --long delete,root,proot-args:,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
@ -106,6 +120,8 @@ OPT_SETUP_FROM_FILE=false
IMAGE_FILE=""
OPT_FAKEROOT=false
OPT_ROOT=false
OPT_PROOT_ARGS=false
PROOT_ARGS=""
OPT_BUILD_IMAGE=false
OPT_DELETE=false
OPT_HELP=false
@ -115,6 +131,7 @@ while true ; do
-i|--setup-from-file) OPT_SETUP_FROM_FILE=true ; shift ; IMAGE_FILE=$1 ; shift ;;
-f|--fakeroot) OPT_FAKEROOT=true ; shift ;;
-r|--root) OPT_ROOT=true ; shift ;;
-p|--proot-args) OPT_PROOT_ARGS=true ; shift ; PROOT_ARGS=$1; shift ;;
-b|--build-image) OPT_BUILD_IMAGE=true ; shift ;;
-d|--delete) OPT_DELETE=true ; shift ;;
-h|--help) OPT_HELP=true ; shift ;;
@ -156,11 +173,11 @@ elif $OPT_SETUP_FROM_FILE; then
fi
if $OPT_FAKEROOT; then
run_juju_as_fakeroot
run_juju_as_fakeroot "${PROOT_ARGS}" ${ARGS[@]}
elif $OPT_ROOT; then
run_juju_as_root
run_juju_as_root ${ARGS[@]}
else
run_juju_as_user
run_juju_as_user "${PROOT_ARGS}" ${ARGS[@]}
fi
# vim: set ts=4 sw=4 noet:

View file

@ -141,31 +141,46 @@ function setup_from_file_juju(){
}
function _define_command(){
local proot_args="$1"
local comm=${SH}
if [ "$2" != "" ]
then
shift
comm="$@"
fi
echo "$proot_args" "${comm[@]}"
}
function run_juju_as_root(){
[ "$JUJU_ENV" == "1" ] && die "Error: The operation is not allowed inside JuJu environment"
local comm=$(_define_command "$@")
mkdir -p ${JUJU_HOME}/${HOME}
${JUJU_HOME}/usr/bin/arch-chroot $JUJU_HOME /usr/bin/bash -c 'mkdir -p /run/lock && /bin/sh'
${JUJU_HOME}/usr/bin/arch-chroot $JUJU_HOME /usr/bin/bash -c "mkdir -p /run/lock && ${comm}"
}
function _run_juju_with_proot(){
if ${PROOT} ${JUJU_HOME}/usr/bin/true &> /dev/null
then
JUJU_ENV=1 ${PROOT} $@ ${JUJU_HOME} ${SH}
JUJU_ENV=1 ${PROOT} $@
else
JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT} $@ ${JUJU_HOME} ${SH}
JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT} $@
fi
}
function run_juju_as_fakeroot(){
_run_juju_with_proot "-S"
local comm=$(_define_command "$@")
_run_juju_with_proot "-S" ${JUJU_HOME} ${comm}
}
function run_juju_as_user(){
_run_juju_with_proot "-R"
local comm=$(_define_command "$@")
_run_juju_with_proot "-R" ${JUJU_HOME} ${comm}
}