Issue #63: Change name to JuJube!

This commit is contained in:
Filippo Squillace 2015-05-16 13:13:36 +00:00
parent 1e3f25d5cb
commit 39b0e941b8
7 changed files with 311 additions and 166 deletions

View file

@ -4,20 +4,20 @@ sudo: required
install:
- PATH=$PWD/bin:$PATH
- 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
- jujube -f echo 'Installing jujube'
- sed -i -e "s/#Server/Server/" ~/.jujube/etc/pacman.d/mirrorlist
- jujube -f pacman --noconfirm -Syy
- jujube -f pacman --noconfirm -S base-devel
script:
- ./tests/test_all.sh
# Test on installing package from AUR
- juju -f yaourt --noconfirm -S tcptraceroute
- sudo $PWD/bin/juju -r tcptraceroute localhost
- jujube -f yaourt --noconfirm -S tcptraceroute
- sudo $PWD/bin/jujube -r tcptraceroute localhost
# Test on installing package from official repo
- juju -f pacman --noconfirm -S tree
- juju -f tree
- jujube -f pacman --noconfirm -S tree
- jujube -f tree
# Test on installing package from official repo with root access
- juju -f pacman --noconfirm -S iftop
- sudo bin/juju -r iftop -t -s 5
- yes | juju -d
- jujube -f pacman --noconfirm -S iftop
- sudo bin/jujube -r iftop -t -s 5
- yes | jujube -d

135
README.md
View file

@ -1,123 +1,119 @@
JuJu
JuJube
====
**JuJu**: the Arch Linux based distro that runs upon any Linux distros without root access
**JuJube**: the Arch Linux based distro that runs upon any Linux distros without root access
[![Build status](https://api.travis-ci.org/fsquillace/juju.png?branch=master)](https://travis-ci.org/fsquillace/juju)
[![Build status](https://api.travis-ci.org/fsquillace/jujube.png?branch=master)](https://travis-ci.org/fsquillace/jujube)
Description
-----------
**JuJu** is a lightweight Arch Linux based distribution that allows to have
**JuJube** is a lightweight Arch Linux based distribution that allows to have
an isolated GNU/Linux environment inside any generic host GNU/Linux OS
and without the need to have root privileges for installing packages.
JuJu contains mainly the package managers (called pacman and yaourt) that allows to access
JuJube contains mainly the package managers (called pacman and yaourt) that allows to access
to a wide range of packages from the Arch Linux repositories.
The main advantages on using JuJu are:
The main advantages on using JuJube are:
- Install packages without root privileges.
- Isolated environment in which you can install packages without affecting a production system.
- Access to a wide range of packages in particular on GNU/Linux distros that may contain limited repositories (such as CentOS and RedHat).
- Available for x86\_64, x86 and ARM architectures but you can build your own image from scratch too!
- All Arch Linux lovers can have their favourite distro everywhere!
JuJube follows the [Arch Linux philosophy](https://wiki.archlinux.org/index.php/The_Arch_Way).
Quickstart
----------
There are three different ways you can run JuJu:
There are three different ways you can run JuJube:
- As normal user - Allow to make basic operations using [proot](https://wiki.archlinux.org/index.php/Proot):
```sh
juju
```
jujube
- As fakeroot - Allow to install/remove packages using [proot](https://wiki.archlinux.org/index.php/Proot):
```sh
juju -f
```
jujube -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):
- As root - Allow to have fully root privileges inside JuJube environment using [arch-chroot](https://wiki.archlinux.org/index.php/Chroot) (you need to be root for executing this):
```sh
juju -r
```
jujube -r
If the JuJu image has not been downloaded yet, the script will download
the JuJu image and will place it to the default directory ~/.juju.
You can change the default directory by changing the environment variable *JUJU\_HOME*.
If the JuJube image has not been downloaded yet, the script will download
the JuJube image and will place it to the default directory ~/.jujube.
You can change the default directory by changing the environment variable *JUJUBE\_HOME*.
If you are new on Archlinux and you are not familiar with *pacman* package manager
visit the [pacman rosetta page](https://wiki.archlinux.org/index.php/Pacman_Rosetta).
Installation
------------
Just clone the JuJu repo somewhere (for example in ~/juju):
Just clone the JuJube repo somewhere (for example in ~/jujube):
git clone git://github.com/fsquillace/juju ~/juju
export PATH=~/juju/bin:$PATH
git clone git://github.com/fsquillace/jujube ~/jujube
export PATH=~/jujube/bin:$PATH
Alternatively, another installation method would be to directly download the JuJu image and place it to the default directory ~/.juju:
Alternatively, another installation method would be to directly download the JuJube image and place it to the default directory ~/.jujube:
ARCH=<one of "x86_64", "x86", "arm">
mkdir ~/.juju
curl https://bitbucket.org/fsquillace/juju-repo/raw/master/juju-${ARCH}.tar.gz | tar -xz -C ~/.juju
export PATH=~/.juju/opt/juju/bin:$PATH
mkdir ~/.jujube
curl https://dl.dropboxusercontent.com/u/42449030/jujube/jujube-${ARCH}.tar.gz | tar -xz -C ~/.jujube
export PATH=~/.jujube/opt/jujube/bin:$PATH
JuJu can works on GNU/Linux OS with kernel version greater or equal
2.6.0 (JuJu was not tested on kernel versions older than this) on 64 bit, 32 bit and ARM architectures.
JuJube can works on GNU/Linux OS with kernel version greater or equal
2.6.0 (JuJube was not tested on kernel versions older than this) on 64 bit, 32 bit and ARM architectures.
Advanced usage
--------------
### Build image ###
You can build a new JuJu image from scratch by running the following command:
You can build a new JuJube image from scratch by running the following command:
juju -b [-n]
jujube -b [-n]
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).
files in order to make JuJube working properly (such as pacman, yaourt, arch-chroot and proot).
The option `-n` will skip the final validation tests if they are not needed.
Remember that the script to build the image must run in an Arch Linux OS with
arch-install-scripts, package-query, git and the base-devel packages installed.
To change the build directory just use the *JUJU_TEMPDIR* (by default /tmp).
To change the build directory just use the *JUJUBE_TEMPDIR* (by default /tmp).
After creating the image juju-x86\_64.tar.gz you can install it by running:
After creating the image jujube-x86\_64.tar.gz you can install it by running:
juju -i juju-x86_64.tar.gz
jujube -i jujube-x86_64.tar.gz
Related wiki page:
- [How to build a JuJu image using QEMU](https://github.com/fsquillace/juju/wiki/How-to-build-a-JuJu-image-using-QEMU)
- [How to build a JuJube image using QEMU](https://github.com/fsquillace/jujube/wiki/How-to-build-a-JuJube-image-using-QEMU)
### Bind directories ###
To bind a host directory to a guest location, you can use proot arguments:
juju -p "-b /mnt/mydata:/home/user/mydata"
jujube -p "-b /mnt/mydata:/home/user/mydata"
Check out the proot options with:
juju -p "--help"
jujube -p "--help"
###Automatic fallback to classic chroot###
Since the [arch-chroot](https://wiki.archlinux.org/index.php/Chroot) may not work
on some distros, JuJu automatically tries to fallback to the classic chroot.
on some distros, JuJube automatically tries to fallback to the classic chroot.
### JuJu as a container ###
Although JuJu has not been designed to be a complete container, it is even possible to
### JuJube as a container ###
Although JuJube has not been designed to be a complete container, it is even possible to
virtualize the process tree thanks to the [systemd container](https://wiki.archlinux.org/index.php/Systemd-nspawn).
The JuJu containter allows to run services inside the container that can be
The JuJube containter allows to run services inside the container that can be
visible from the host OS through the network.
The drawbacks of this are that the host OS must use systemd as a service manager,
and the container can only be executed using root privileges.
To boot a JuJu container:
To boot a JuJube container:
sudo systemd-nspawn -bD ~/.juju
sudo systemd-nspawn -bD ~/.jujube
Related wiki page:
- [How to run juju as a container](https://github.com/fsquillace/juju/wiki/How-to-run-JuJu-as-a-container)
- [How to run jujube as a container](https://github.com/fsquillace/jujube/wiki/How-to-run-JuJube-as-a-container)
Dependencies
------------
JuJu comes with a very short list of dependencies in order to be installed in most
JuJube comes with a very short list of dependencies in order to be installed in most
of GNU/Linux distributions. The needed executables in the host OS are:
- bash
- wget or curl
@ -136,7 +132,7 @@ Troubleshooting
```
Cannot find the gzip binary required for compressing man and info pages.
```
- **A**: JuJu comes with a very basic number of packages.
- **A**: JuJube comes with a very basic number of packages.
In order to install packages using yaourt you may need to install the package group *base-devel*
that contains all the essential packages for compiling source code (such as gcc, make, patch, etc):
@ -148,19 +144,19 @@ that contains all the essential packages for compiling source code (such as gcc,
- **Q**: Why do I get the error: "FATAL: kernel too old"?
- **A**: This is because the executable from the precompiled package cannot
properly run if the kernel is old.
JuJu contains two different PRoot binaries, and one of them is highly compatible
with old linux kernel versions. JuJu will detect which PRoot binary need to be
JuJube contains two different PRoot binaries, and one of them is highly compatible
with old linux kernel versions. JuJube will detect which PRoot binary need to be
executed but you may need to specify the PRoot *-k* option if the guest rootfs
requires a newer kernel version:
```
juju -p "-k 3.10"
jujube -p "-k 3.10"
```
In order to check if an executable inside JuJu environment can be compatible
In order to check if an executable inside JuJube environment can be compatible
with the kernel of the host OS just use the *file* command, for instance:
```
file ~/.juju/usr/bin/bash
file ~/.jujube/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
@ -178,7 +174,7 @@ From the output you can see what is the minimum recommended Linux kernel version
- **A**: The ping command uses *suid* permissions that allow to execute the command using
root privileges. The fakeroot mode is not able to execute a command set with suid,
and you may need to use root privileges. There are other few commands that
have *suid* permission, you can list the commands from your JuJu environment
have *suid* permission, you can list the commands from your JuJube environment
with the following command:
```
find /usr/bin -perm +4000
@ -208,7 +204,7 @@ To quick fix this, you can just install a fonts package:
- **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
since JuJube will try to preserve the JuJube environment by assigning ownership
of the files to the real user.
###No servers configured for repository###
@ -250,8 +246,33 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
## Author
Author
------
Filippo Squillace <feel.squally@gmail.com>
## WWW
https://github.com/fsquillace/juju
WWW
---
https://github.com/fsquillace/jujube
Last words
---------
Quote of the [lotus](http://en.wikipedia.org/wiki/Ziziphus_lotus) (a selvatic jujube plant)
> Per nove infausti dì sul mar pescoso
> i venti rei mi trasportaro. Al fine
> nel decimo sbarcammo in su le rive
> de Lotofági, un popolo, a cui cibo
> È duna pianta il florido germoglio.
> ...
> ...
> Partiro e saffrontaro a quella gente,
> che, lunge dal voler la vita loro,
> il dolce loto a savorar lor porse.
> chiunque lesca dilettosa, e nuova
> gustato avea, con le novelle indietro
> non bramava tornar: colà bramava
> starsi, e, mangiando del soave loto,
> la contrada natia sbandir dal petto.
verse 105-123, Homer, from [Odyssey Book IX](http://it.wikisource.org/wiki/Odissea/Libro_IX)
([en](http://en.wikisource.org/wiki/The_Odyssey_(Butler)/Book_IX))

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# This file is part of JuJu (https://github.com/fsquillace/juju).
# This file is part of JuJube (https://github.com/fsquillace/jujube).
#
# Copyright (c) 2012-2015
#
@ -28,13 +28,13 @@ usage() {
echo -e "$NAME: $DESCRIPTION"
echo -e "Usage: $CMD [options] [--] [command]"
echo -e "Options:"
echo -e "-i, --setup-from-file <image> Setup the $NAME image in ${JUJU_HOME}"
echo -e "-i, --setup-from-file <image> Setup the $NAME image in ${JUJUBE_HOME}"
echo -e "-f, --fakeroot Run $NAME with fakeroot privileges"
echo -e "-r, --root Run $NAME with root privileges"
echo -e "-p, --proot-args Proot arguments"
echo -e "-b, --build-image Build a $NAME image (must run in ArchLinux)"
echo -e "-n, --disable-validation Disable the $NAME image validation"
echo -e "-d, --delete Delete $NAME from ${JUJU_HOME}"
echo -e "-d, --delete Delete $NAME from ${JUJUBE_HOME}"
echo -e "-h, --help Show this help message"
echo -e "-v, --version Show the $NAME version"
}
@ -168,7 +168,7 @@ function execute_operation(){
setup_env
fi
elif $OPT_SETUP_FROM_FILE; then
die "Error: The image cannot be installed since $JUJU_HOME is not empty."
die "Error: The image cannot be installed since $JUJUBE_HOME is not empty."
fi
if $OPT_FAKEROOT; then

View file

@ -27,31 +27,31 @@ source "$(dirname ${BASH_ARGV[0]})/util.sh"
################################# VARIABLES ##############################
NAME='JuJu'
CMD='juju'
VERSION='3.6.9'
CODE_NAME='Snake'
NAME='JuJube'
CMD='jujube'
VERSION='4.7.4'
CODE_NAME='Mairei'
DESCRIPTION='The Arch Linux based distro that runs upon any Linux distros without root access'
AUTHOR='Filippo Squillace <feel dot squally at gmail.com>'
HOMEPAGE="https://github.com/fsquillace/${CMD}"
COPYRIGHT='2012-2015'
if [ "$JUJU_ENV" == "1" ]
if [ "$JUJUBE_ENV" == "1" ]
then
die "Error: Nested ${NAME} environments are not allowed"
elif [ ! -z $JUJU_ENV ] && [ "$JUJU_ENV" != "0" ]
elif [ ! -z $JUJUBE_ENV ] && [ "$JUJUBE_ENV" != "0" ]
then
die "The variable JUJU_ENV is not properly set"
die "The variable JUJUBE_ENV is not properly set"
fi
[ -z ${JUJU_HOME} ] && JUJU_HOME=~/.${CMD}
if [ -z ${JUJU_TEMPDIR} ] || [ ! -d ${JUJU_TEMPDIR} ]
[ -z ${JUJUBE_HOME} ] && JUJUBE_HOME=~/.${CMD}
if [ -z ${JUJUBE_TEMPDIR} ] || [ ! -d ${JUJUBE_TEMPDIR} ]
then
JUJU_TEMPDIR=/tmp
JUJUBE_TEMPDIR=/tmp
fi
ENV_REPO=https://bitbucket.org/fsquillace/${CMD}-repo/raw/master
ENV_REPO=https://dl.dropboxusercontent.com/u/42449030/${CMD}
ORIGIN_WD=$(pwd)
WGET="wget --no-check-certificate"
@ -66,28 +66,28 @@ HOST_ARCH=$(uname -m)
if [ $HOST_ARCH == "i686" ] || [ $HOST_ARCH == "i386" ]
then
ARCH="x86"
LD_LIB="${JUJU_HOME}/lib/ld-linux.so.2"
LD_LIB="${JUJUBE_HOME}/lib/ld-linux.so.2"
elif [ $HOST_ARCH == "x86_64" ]
then
ARCH="x86_64"
LD_LIB="${JUJU_HOME}/lib64/ld-linux-x86-64.so.2"
LD_LIB="${JUJUBE_HOME}/lib64/ld-linux-x86-64.so.2"
elif [[ $HOST_ARCH =~ .*(arm).* ]]
then
ARCH="arm"
LD_LIB="${JUJU_HOME}/lib/ld-linux-armhf.so.3"
LD_LIB="${JUJUBE_HOME}/lib/ld-linux-armhf.so.3"
else
die "Unknown architecture ${ARCH}"
fi
PROOT_COMPAT="${JUJU_HOME}/opt/proot/proot-${ARCH}"
PROOT_COMPAT="${JUJUBE_HOME}/opt/proot/proot-${ARCH}"
PROOT_LINK=http://static.proot.me/proot-${ARCH}
SH=("/bin/sh" "--login")
CHROOT=${JUJU_HOME}/usr/bin/arch-chroot
CLASSIC_CHROOT=${JUJU_HOME}/usr/bin/chroot
CHROOT=${JUJUBE_HOME}/usr/bin/arch-chroot
CLASSIC_CHROOT=${JUJUBE_HOME}/usr/bin/chroot
TRUE=/usr/bin/true
ID="/usr/bin/id -u"
CHOWN="${JUJU_HOME}/usr/bin/chown"
CHOWN="${JUJUBE_HOME}/usr/bin/chown"
LN="ln"
################################# MAIN FUNCTIONS ##############################
@ -98,7 +98,7 @@ function download(){
}
function is_env_installed(){
[ -d "$JUJU_HOME" ] && [ "$(ls -A $JUJU_HOME)" ] && return 0
[ -d "$JUJUBE_HOME" ] && [ "$(ls -A $JUJUBE_HOME)" ] && return 0
return 1
}
@ -119,11 +119,11 @@ function _prepare_build_directory(){
function _setup_env(){
is_env_installed && die "Error: ${NAME} has been already installed in $JUJU_HOME"
mkdir -p "${JUJU_HOME}"
is_env_installed && die "Error: ${NAME} has been already installed in $JUJUBE_HOME"
mkdir -p "${JUJUBE_HOME}"
imagepath=$1
$TAR -zxpf ${imagepath} -C ${JUJU_HOME}
mkdir -p ${JUJU_HOME}/run/lock
$TAR -zxpf ${imagepath} -C ${JUJUBE_HOME}
mkdir -p ${JUJUBE_HOME}/run/lock
warn "Warn: The default mirror URL is ${DEFAULT_MIRROR}."
warn "To change it:"
info " nano /etc/pacman.d/mirrorlist"
@ -134,7 +134,7 @@ function _setup_env(){
function setup_env(){
local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t ${CMD}.XXXXXXXXXX)
local maindir=$(TMPDIR=$JUJUBE_TEMPDIR mktemp -d -t ${CMD}.XXXXXXXXXX)
_prepare_build_directory
info "Downloading ${NAME}..."
@ -166,30 +166,30 @@ function run_env_as_root(){
local main_cmd="${SH[@]}"
[ "$1" != "" ] && main_cmd="$(insert_quotes_on_spaces "$@")"
local cmd="mkdir -p ${JUJU_HOME}/${HOME} && mkdir -p /run/lock && ${main_cmd}"
local cmd="mkdir -p ${JUJUBE_HOME}/${HOME} && mkdir -p /run/lock && ${main_cmd}"
trap - QUIT EXIT ABRT KILL TERM INT
trap "[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}; rm -r ${JUJU_HOME}/etc/mtab" EXIT QUIT ABRT KILL TERM INT
trap "[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJUBE_HOME}; rm -r ${JUJUBE_HOME}/etc/mtab" EXIT QUIT ABRT KILL TERM INT
[ ! -e ${JUJU_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJU_HOME}/etc/mtab
[ ! -e ${JUJUBE_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJUBE_HOME}/etc/mtab
if ${CHROOT} $JUJU_HOME ${TRUE} 1> /dev/null
if ${CHROOT} $JUJUBE_HOME ${TRUE} 1> /dev/null
then
JUJU_ENV=1 ${CHROOT} $JUJU_HOME "${SH[@]}" "-c" "${cmd}"
JUJUBE_ENV=1 ${CHROOT} $JUJUBE_HOME "${SH[@]}" "-c" "${cmd}"
local ret=$?
elif ${CLASSIC_CHROOT} $JUJU_HOME ${TRUE} 1> /dev/null
elif ${CLASSIC_CHROOT} $JUJUBE_HOME ${TRUE} 1> /dev/null
then
warn "Warning: The executable arch-chroot does not work, falling back to classic chroot"
JUJU_ENV=1 ${CLASSIC_CHROOT} $JUJU_HOME "${SH[@]}" "-c" "${cmd}"
JUJUBE_ENV=1 ${CLASSIC_CHROOT} $JUJUBE_HOME "${SH[@]}" "-c" "${cmd}"
local ret=$?
else
die "Error: Chroot does not work"
fi
# The ownership of the files is assigned to the real user
[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJU_HOME}
[ -z $uid ] || ${CHOWN} -R ${uid} ${JUJUBE_HOME}
[ -e ${JUJU_HOME}/etc/mtab ] && rm -r ${JUJU_HOME}/etc/mtab
[ -e ${JUJUBE_HOME}/etc/mtab ] && rm -r ${JUJUBE_HOME}/etc/mtab
trap - QUIT EXIT ABRT KILL TERM INT
return $?
@ -200,11 +200,11 @@ function _run_proot(){
shift
if ${PROOT_COMPAT} $proot_args ${TRUE} 1> /dev/null
then
JUJU_ENV=1 ${PROOT_COMPAT} $proot_args "${@}"
JUJUBE_ENV=1 ${PROOT_COMPAT} $proot_args "${@}"
elif PROOT_NO_SECCOMP=1 ${PROOT_COMPAT} $proot_args ${TRUE} 1> /dev/null
then
warn "Proot error: Trying to execute proot with PROOT_NO_SECCOMP=1..."
JUJU_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT_COMPAT} $proot_args "${@}"
JUJUBE_ENV=1 PROOT_NO_SECCOMP=1 ${PROOT_COMPAT} $proot_args "${@}"
else
die "Error: Check if the ${CMD} arguments are correct or use the option ${CMD} -p \"-k 3.10\""
fi
@ -227,43 +227,43 @@ function _run_env_with_proot(){
function run_env_as_fakeroot(){
local proot_args="$1"
shift
[ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
[ "$(_run_proot "-R ${JUJUBE_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
die "You cannot access with root privileges. Use --root option instead."
[ ! -e ${JUJU_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJU_HOME}/etc/mtab
_run_env_with_proot "-S ${JUJU_HOME} $proot_args" "${@}"
[ ! -e ${JUJUBE_HOME}/etc/mtab ] && $LN -s /proc/self/mounts ${JUJUBE_HOME}/etc/mtab
_run_env_with_proot "-S ${JUJUBE_HOME} $proot_args" "${@}"
}
function run_env_as_user(){
local proot_args="$1"
shift
[ "$(_run_proot "-R ${JUJU_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
[ "$(_run_proot "-R ${JUJUBE_HOME} $proot_args" ${ID} 2> /dev/null )" == "0" ] && \
die "You cannot access with root privileges. Use --root option instead."
[ -e ${JUJU_HOME}/etc/mtab ] && rm -f ${JUJU_HOME}/etc/mtab
_run_env_with_proot "-R ${JUJU_HOME} $proot_args" "${@}"
[ -e ${JUJUBE_HOME}/etc/mtab ] && rm -f ${JUJUBE_HOME}/etc/mtab
_run_env_with_proot "-R ${JUJUBE_HOME} $proot_args" "${@}"
}
function delete_env(){
! ask "Are you sure to delete ${NAME} located in ${JUJU_HOME}" "N" && return
if mountpoint -q ${JUJU_HOME}
! ask "Are you sure to delete ${NAME} located in ${JUJUBE_HOME}" "N" && return
if mountpoint -q ${JUJUBE_HOME}
then
info "There are mounted directories inside ${JUJU_HOME}"
if ! umount --force ${JUJU_HOME}
info "There are mounted directories inside ${JUJUBE_HOME}"
if ! umount --force ${JUJUBE_HOME}
then
error "Cannot umount directories in ${JUJU_HOME}"
error "Cannot umount directories in ${JUJUBE_HOME}"
die "Try to delete ${NAME} using root permissions"
fi
fi
# the CA directories are read only and can be deleted only by changing the mod
chmod -R +w ${JUJU_HOME}/etc/ca-certificates
if rm -rf ${JUJU_HOME}/*
chmod -R +w ${JUJUBE_HOME}/etc/ca-certificates
if rm -rf ${JUJUBE_HOME}/*
then
info "${NAME} deleted in ${JUJU_HOME}"
info "${NAME} deleted in ${JUJUBE_HOME}"
else
error "Error: Cannot delete ${NAME} in ${JUJU_HOME}"
error "Error: Cannot delete ${NAME} in ${JUJUBE_HOME}"
fi
}
@ -288,7 +288,7 @@ function build_image_env(){
local disable_validation=$1
local maindir=$(TMPDIR=$JUJU_TEMPDIR mktemp -d -t ${CMD}.XXXXXXXXXX)
local maindir=$(TMPDIR=$JUJUBE_TEMPDIR mktemp -d -t ${CMD}.XXXXXXXXXX)
sudo mkdir -p ${maindir}/root
trap - QUIT EXIT ABRT KILL TERM INT
trap "sudo rm -rf ${maindir}; die \"Error occurred when installing ${NAME}\"" EXIT QUIT ABRT KILL TERM INT
@ -365,28 +365,28 @@ function validate_image(){
$TAR -zxpf ${imagefile} -C ${testdir}
mkdir -p ${testdir}/run/lock
sed -i -e "s/#Server/Server/" ${testdir}/etc/pacman.d/mirrorlist
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -Syy
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -Syy
# Check most basic executables work
JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r pacman -Qi pacman 1> /dev/null
JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r yaourt -V 1> /dev/null
JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r /opt/proot/proot-$ARCH --help 1> /dev/null
JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r arch-chroot --help 1> /dev/null
JUJUBE_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r pacman -Qi pacman 1> /dev/null
JUJUBE_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r yaourt -V 1> /dev/null
JUJUBE_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r /opt/proot/proot-$ARCH --help 1> /dev/null
JUJUBE_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r arch-chroot --help 1> /dev/null
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S base-devel
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S base-devel
local yaourt_package=tcptraceroute
info "Installing ${yaourt_package} package from AUR repo using proot..."
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f sh --login -c "yaourt --noconfirm -S ${yaourt_package}"
JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r tcptraceroute localhost
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f sh --login -c "yaourt --noconfirm -S ${yaourt_package}"
JUJUBE_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r tcptraceroute localhost
local repo_package=sysstat
info "Installing ${repo_package} package from official repo using proot..."
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package}
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} iostat
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f iostat
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package}
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} iostat
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f iostat
local repo_package=iftop
info "Installing ${repo_package} package from official repo using root..."
JUJU_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package}
JUJU_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r iftop -t -s 5
JUJUBE_HOME=${testdir} ${testdir}/opt/${CMD}/bin/${CMD} -f pacman --noconfirm -S ${repo_package}
JUJUBE_HOME=${testdir} sudo ${testdir}/opt/${CMD}/bin/${CMD} -r iftop -t -s 5
}

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# This file is part of JuJu (https://github.com/fsquillace/juju)
# This file is part of JuJube (https://github.com/fsquillace/jujube)
#
# Copyright (c) 2012-2015
#

124
tests/test_cli.sh Executable file
View file

@ -0,0 +1,124 @@
#!/bin/bash
source $(dirname $0)/../bin/* -h &> /dev/null
# Disable the exiterr
set +e
## Mock functions ##
function usage(){
echo "usage"
}
function version(){
echo "version"
}
function build_image_env(){
echo "build_image_env"
}
function delete_env(){
echo "delete_env"
}
function is_env_installed(){
return 0
}
function setup_env_from_file(){
echo "setup_env_from_file $@"
}
function setup_env(){
echo "setup_env"
}
function run_env_as_fakeroot(){
local proot_args="$1"
shift
echo "run_env_as_fakeroot($proot_args,$@)"
}
function run_env_as_root(){
echo "run_env_as_root $@"
}
function run_env_as_user(){
local proot_args="$1"
shift
echo "run_env_as_user($proot_args,$@)"
}
function wrap_env(){
parse_arguments "$@"
check_cli
execute_operation
}
function test_help(){
local output=$(wrap_env -h)
assertEquals $output "usage"
local output=$(wrap_env --help)
assertEquals $output "usage"
}
function test_version(){
local output=$(wrap_env -v)
assertEquals $output "version"
local output=$(wrap_env --version)
assertEquals $output "version"
}
function test_build_image_env(){
local output=$(wrap_env -b)
assertEquals $output "build_image_env"
local output=$(wrap_env --build-image)
assertEquals $output "build_image_env"
}
function test_delete_env(){
local output=$(wrap_env -d)
assertEquals $output "delete_env"
local output=$(wrap_env --delete)
assertEquals $output "delete_env"
}
function test_run_env_as_fakeroot(){
local output=$(wrap_env -f)
assertEquals $output "run_env_as_fakeroot(,)"
local output=$(wrap_env --fakeroot)
assertEquals $output "run_env_as_fakeroot(,)"
local output=$(wrap_env -f -p "-b arg")
assertEquals "${output[@]}" "run_env_as_fakeroot(-b arg,)"
local output=$(wrap_env -f -p "-b arg" -- command -kv)
assertEquals "${output[@]}" "run_env_as_fakeroot(-b arg,command -kv)"
local output=$(wrap_env -f command --as)
assertEquals "${output[@]}" "run_env_as_fakeroot(,command --as)"
}
function test_run_env_as_user(){
local output=$(wrap_env)
assertEquals $output "run_env_as_user(,)"
local output=$(wrap_env -p "-b arg")
assertEquals "$output" "run_env_as_user(-b arg,)"
local output=$(wrap_env -p "-b arg" -- command -ll)
assertEquals "$output" "run_env_as_user(-b arg,command -ll)"
local output=$(wrap_env command -ls)
assertEquals "$output" "run_env_as_user(,command -ls)"
}
function test_run_env_as_root(){
local output=$(wrap_env -r)
assertEquals $output "run_env_as_root"
local output=$(wrap_env -r command)
assertEquals "${output[@]}" "run_env_as_root command"
}
function test_check_cli(){
$(wrap_env -b -h 2> /dev/null)
assertEquals $? 1
$(wrap_env -n -v 2> /dev/null)
assertEquals $? 1
$(wrap_env -d -r 2> /dev/null)
assertEquals $? 1
$(wrap_env -h -f 2> /dev/null)
assertEquals $? 1
$(wrap_env -v -i fsd 2> /dev/null)
assertEquals $? 1
$(wrap_env -f -r 2> /dev/null)
assertEquals $? 1
$(wrap_env -p args -v 2> /dev/null)
assertEquals $? 1
$(wrap_env -d args 2> /dev/null)
assertEquals $? 1
}
source $(dirname $0)/shunit2

View file

@ -5,35 +5,35 @@ function oneTimeSetUp(){
CURRPWD=$PWD
ENV_MAIN_HOME=/tmp/envtesthome
[ -e $ENV_MAIN_HOME ] || JUJU_HOME=$ENV_MAIN_HOME bash --rcfile "$(dirname $0)/../lib/core.sh" -ic "setup_env"
JUJU_HOME=""
[ -e $ENV_MAIN_HOME ] || JUJUBE_HOME=$ENV_MAIN_HOME bash --rcfile "$(dirname $0)/../lib/core.sh" -ic "setup_env"
JUJUBE_HOME=""
}
function install_mini_env(){
cp -rfa $ENV_MAIN_HOME/* $JUJU_HOME
cp -rfa $ENV_MAIN_HOME/* $JUJUBE_HOME
}
function setUp(){
cd $CURRPWD
JUJU_HOME=$(TMPDIR=/tmp mktemp -d -t envhome.XXXXXXXXXX)
JUJUBE_HOME=$(TMPDIR=/tmp mktemp -d -t envhome.XXXXXXXXXX)
source "$(dirname $0)/../lib/core.sh"
ORIGIN_WD=$(TMPDIR=/tmp mktemp -d -t envowd.XXXXXXXXXX)
cd $ORIGIN_WD
JUJU_TEMPDIR=$(TMPDIR=/tmp mktemp -d -t envtemp.XXXXXXXXXX)
JUJUBE_TEMPDIR=$(TMPDIR=/tmp mktemp -d -t envtemp.XXXXXXXXXX)
set +e
trap - QUIT EXIT ABRT KILL TERM INT
trap "rm -rf ${JUJU_HOME}; rm -rf ${ORIGIN_WD}; rm -rf ${JUJU_TEMPDIR}" EXIT QUIT ABRT KILL TERM INT
trap "rm -rf ${JUJUBE_HOME}; rm -rf ${ORIGIN_WD}; rm -rf ${JUJUBE_TEMPDIR}" EXIT QUIT ABRT KILL TERM INT
}
function tearDown(){
# the CA directories are read only and can be deleted only by changing the mod
[ -d ${JUJU_HOME}/etc/ca-certificates ] && chmod -R +w ${JUJU_HOME}/etc/ca-certificates
rm -rf $JUJU_HOME
[ -d ${JUJUBE_HOME}/etc/ca-certificates ] && chmod -R +w ${JUJUBE_HOME}/etc/ca-certificates
rm -rf $JUJUBE_HOME
rm -rf $ORIGIN_WD
rm -rf $JUJU_TEMPDIR
rm -rf $JUJUBE_TEMPDIR
trap - QUIT EXIT ABRT KILL TERM INT
}
@ -41,7 +41,7 @@ function tearDown(){
function test_is_env_installed(){
is_env_installed
assertEquals $? 1
touch $JUJU_HOME/just_file
touch $JUJUBE_HOME/just_file
is_env_installed
assertEquals $? 0
}
@ -66,17 +66,17 @@ function test_download(){
function test_setup_env(){
wget_mock(){
# Proof that the setup is happening
# inside $JUJU_TEMPDIR
local cwd=${PWD#${JUJU_TEMPDIR}}
# inside $JUJUBE_TEMPDIR
local cwd=${PWD#${JUJUBE_TEMPDIR}}
local parent_dir=${PWD%${cwd}}
assertEquals "$JUJU_TEMPDIR" "${parent_dir}"
assertEquals "$JUJUBE_TEMPDIR" "${parent_dir}"
touch file
tar -czvf ${CMD}-${ARCH}.tar.gz file
}
WGET=wget_mock
setup_env &> /dev/null
assertTrue "[ -e $JUJU_HOME/file ]"
assertTrue "[ -e $JUJU_HOME/run/lock ]"
assertTrue "[ -e $JUJUBE_HOME/file ]"
assertTrue "[ -e $JUJUBE_HOME/run/lock ]"
}
@ -84,8 +84,8 @@ function test_setup_env_from_file(){
touch file
tar -czvf ${CMD}-${ARCH}.tar.gz file 1> /dev/null
setup_env_from_file ${CMD}-${ARCH}.tar.gz &> /dev/null
assertTrue "[ -e $JUJU_HOME/file ]"
assertTrue "[ -e $JUJU_HOME/run/lock ]"
assertTrue "[ -e $JUJUBE_HOME/file ]"
assertTrue "[ -e $JUJUBE_HOME/run/lock ]"
$(setup_env_from_file noexist.tar.gz 2> /dev/null)
assertEquals $? 1
@ -95,8 +95,8 @@ function test_setup_env_from_file_with_absolute_path(){
touch file
tar -czvf ${CMD}-${ARCH}.tar.gz file 1> /dev/null
setup_env_from_file ${ORIGIN_WD}/${CMD}-${ARCH}.tar.gz &> /dev/null
assertTrue "[ -e $JUJU_HOME/file ]"
assertTrue "[ -e $JUJU_HOME/run/lock ]"
assertTrue "[ -e $JUJUBE_HOME/file ]"
assertTrue "[ -e $JUJUBE_HOME/run/lock ]"
}
function test_run_env_as_root(){
@ -150,20 +150,20 @@ function test_run_env_as_user(){
install_mini_env
local output=$(run_env_as_user "-k 3.10" "/usr/bin/mkdir" "-v" "/newdir2" | awk -F: '{print $1}')
assertEquals "$output" "/usr/bin/mkdir"
assertTrue "[ -e $JUJU_HOME/newdir2 ]"
assertTrue "[ -e $JUJUBE_HOME/newdir2 ]"
SH=("/usr/bin/mkdir" "-v" "/newdir")
local output=$(run_env_as_user "-k 3.10" | awk -F: '{print $1}')
assertEquals "$output" "/usr/bin/mkdir"
assertTrue "[ -e $JUJU_HOME/newdir ]"
assertTrue "[ -e $JUJUBE_HOME/newdir ]"
}
function test_run_env_as_proot_mtab(){
install_mini_env
$(run_env_as_fakeroot "-k 3.10" "echo")
assertTrue "[ -e $JUJU_HOME/etc/mtab ]"
assertTrue "[ -e $JUJUBE_HOME/etc/mtab ]"
$(run_env_as_user "-k 3.10" "echo")
assertTrue "[ ! -e $JUJU_HOME/etc/mtab ]"
assertTrue "[ ! -e $JUJUBE_HOME/etc/mtab ]"
}
function test_run_env_as_root_mtab(){
@ -174,14 +174,14 @@ function test_run_env_as_root_mtab(){
CLASSIC_CHROOT="sudo $CLASSIC_CHROOT"
CHOWN="sudo $CHOWN"
$(run_env_as_root "echo")
assertTrue "[ ! -e $JUJU_HOME/etc/mtab ]"
assertTrue "[ ! -e $JUJUBE_HOME/etc/mtab ]"
}
function test_run_env_with_quotes(){
install_mini_env
local output=$(run_env_as_user "-k 3.10" "bash" "-c" "/usr/bin/mkdir -v /newdir2" | awk -F: '{print $1}')
assertEquals "$output" "/usr/bin/mkdir"
assertTrue "[ -e $JUJU_HOME/newdir2 ]"
assertTrue "[ -e $JUJUBE_HOME/newdir2 ]"
}
function test_run_env_as_user_proot_args(){
@ -189,9 +189,9 @@ function test_run_env_as_user_proot_args(){
run_env_as_user "--help" "" &> /dev/null
assertEquals $? 0
mkdir $JUJU_TEMPDIR/newdir
touch $JUJU_TEMPDIR/newdir/newfile
run_env_as_user "-b $JUJU_TEMPDIR/newdir:/newdir -k 3.10" "ls" "-l" "/newdir/newfile" &> /dev/null
mkdir $JUJUBE_TEMPDIR/newdir
touch $JUJUBE_TEMPDIR/newdir/newfile
run_env_as_user "-b $JUJUBE_TEMPDIR/newdir:/newdir -k 3.10" "ls" "-l" "/newdir/newfile" &> /dev/null
assertEquals $? 0
$(_run_env_with_proot --helps 2> /dev/null)
@ -248,7 +248,7 @@ function test_delete_env(){
function test_nested_env(){
install_mini_env
JUJU_ENV=1 bash -ic "source $CURRPWD/$(dirname $0)/../lib/core.sh" &> /dev/null
JUJUBE_ENV=1 bash -ic "source $CURRPWD/$(dirname $0)/../lib/core.sh" &> /dev/null
assertEquals $? 1
}