From e4b6bbb97426b4133d556c099cd56a58701fadde Mon Sep 17 00:00:00 2001 From: Filippo Squillace Date: Mon, 22 Jun 2015 19:00:37 +0000 Subject: [PATCH] Issue #74: Substitute arch-chroot to jchroot --- bin/jchroot | 9 ++++++--- bin/junest | 4 +++- lib/core.sh | 9 +++++++-- tests/test_cli.sh | 2 +- tests/test_core.sh | 3 ++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bin/jchroot b/bin/jchroot index 37f5d3d..83dc10f 100755 --- a/bin/jchroot +++ b/bin/jchroot @@ -16,6 +16,9 @@ # along with this program. If not, see . # +# This script is the simplified and portable version of arch-chroot +# (https://wiki.archlinux.org/index.php/Change_root#Using_arch-chroot) + set -e ################################ IMPORTS ################################## @@ -39,14 +42,14 @@ chroot_setup() { [[ $(trap -p EXIT) ]] && die '(BUG): attempting to overwrite existing EXIT trap' trap 'chroot_teardown' EXIT - #chroot_maybe_add_mount "! mountpoint -q '$1'" "$1" "$1" --bind && + chroot_maybe_add_mount "! mountpoint -q '$1'" "$1" "$1" --bind && chroot_add_mount proc "$1/proc" -t proc -o nosuid,noexec,nodev && chroot_add_mount sys "$1/sys" -t sysfs -o nosuid,noexec,nodev,ro && chroot_add_mount udev "$1/dev" -t devtmpfs -o mode=0755,nosuid && chroot_add_mount devpts "$1/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec && chroot_add_mount shm "$1/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev && chroot_add_mount run "$1/run" -t tmpfs -o nosuid,nodev,mode=0755 && - chroot_add_mount tmp "$1/tmp" -t tmpfs -o mode=1777,strictatime,nodev,nosuid && + chroot_add_mount tmp "$1/tmp" -t tmpfs -o mode=1777,atime,nodev,nosuid && mkdir -p "$1/$HOME" && chroot_add_mount $HOME "$1/$HOME" --bind } @@ -90,7 +93,7 @@ chroot_add_resolv_conf() { chroot_add_mount /etc/resolv.conf "$resolv_conf" --bind } -if [[ -z $1 || $1 = @(-h|--help) ]]; then +if [[ -z $1 || $1 == -h || $1 == --help ]]; then usage exit $(( $# ? 0 : 1 )) fi diff --git a/bin/junest b/bin/junest index abc69bf..28c480f 100755 --- a/bin/junest +++ b/bin/junest @@ -18,7 +18,9 @@ # along with this program. If not, see . # -source "$(dirname $0)/../lib/core.sh" +JUNEST_BASE="$(dirname $0)/.." + +source "${JUNEST_BASE}/lib/core.sh" ################################### ### General functions ### diff --git a/lib/core.sh b/lib/core.sh index 3d2428f..af2989b 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -46,6 +46,7 @@ then fi [ -z ${JUNEST_HOME} ] && JUNEST_HOME=~/.${CMD} +[ -z ${JUNEST_BASE} ] && JUNEST_BASE=${JUNEST_HOME}/opt/junest if [ -z ${JUNEST_TEMPDIR} ] || [ ! -d ${JUNEST_TEMPDIR} ] then JUNEST_TEMPDIR=/tmp @@ -86,14 +87,14 @@ ID="id -u" # List of executables that are run in the host OS: PROOT_COMPAT="${JUNEST_HOME}/opt/proot/proot-${ARCH}" -CHROOT=${JUNEST_HOME}/usr/bin/arch-chroot +CHROOT=${JUNEST_BASE}/bin/jchroot CLASSIC_CHROOT=${JUNEST_HOME}/usr/bin/chroot WGET="wget --no-check-certificate" CURL="curl -L -J -O -k" TAR=tar CHOWN="chown" -PATH=/usr/bin:/bin:/sbin:$PATH +PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH LD_EXEC="$LD_LIB --library-path ${JUNEST_HOME}/usr/lib:${JUNEST_HOME}/lib" # The following functions attempt first to run the executable in the host OS. @@ -120,6 +121,10 @@ function download_cmd(){ $WGET $@ || $CURL $@ } +function chroot_cmd(){ + $CHROOT $@ || chroot $@ || $LD_EXEC ${JUNEST_HOME}/usr/bin/chroot $@ +} + ################################# MAIN FUNCTIONS ############################## function is_env_installed(){ diff --git a/tests/test_cli.sh b/tests/test_cli.sh index a9e0a13..bcf2f0c 100755 --- a/tests/test_cli.sh +++ b/tests/test_cli.sh @@ -1,5 +1,5 @@ #!/bin/bash -source $(dirname $0)/../bin/* -h &> /dev/null +source $(dirname $0)/../bin/junest -h &> /dev/null # Disable the exiterr set +e diff --git a/tests/test_core.sh b/tests/test_core.sh index a9759d9..84ed818 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -16,7 +16,8 @@ function install_mini_env(){ function setUp(){ cd $CURRPWD JUNEST_HOME=$(TMPDIR=/tmp mktemp -d -t envhome.XXXXXXXXXX) - source "$(dirname $0)/../lib/core.sh" + JUNEST_BASE="$CURRPWD/$(dirname $0)/.." + source "${JUNEST_BASE}/lib/core.sh" ORIGIN_WD=$(TMPDIR=/tmp mktemp -d -t envowd.XXXXXXXXXX) cd $ORIGIN_WD JUNEST_TEMPDIR=$(TMPDIR=/tmp mktemp -d -t envtemp.XXXXXXXXXX)