Issue #74: Substitute arch-chroot to jchroot

This commit is contained in:
Filippo Squillace 2015-06-22 19:00:37 +00:00
parent 3dc3a830a2
commit e4b6bbb974
5 changed files with 19 additions and 8 deletions

View file

@ -16,6 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# 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

View file

@ -18,7 +18,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
source "$(dirname $0)/../lib/core.sh"
JUNEST_BASE="$(dirname $0)/.."
source "${JUNEST_BASE}/lib/core.sh"
###################################
### General functions ###

View file

@ -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(){

View file

@ -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

View file

@ -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)