From 57f35a77f82b90158cfc96be9ae6281bc12d5ea3 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Tue, 6 Mar 2012 11:04:27 -0600 Subject: [PATCH] j: move root dir to /root so other things can be stored out of band --- j | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/j b/j index 9b7fa26..067cbba 100755 --- a/j +++ b/j @@ -120,7 +120,8 @@ j_params() { # Given a chroot name, find and set up the chroot dir jdir="${jbase}/${jname}" - if [ ! -d "${jdir}" ] + jroot="${jdir}/root" + if [ ! -d "${jdir}" -o ! -d "${jroot}" ] then printf "jerror='%s'\n" "not a directory" return 1 @@ -130,7 +131,7 @@ j_params() { jshell="" for shell in /bin/bash /usr/bin/bash /usr/local/bin/bash /bin/sh do - if [ -f "${jdir}/${shell}" ] + if [ -f "${jroot}/${shell}" ] then jshell=${shell} break @@ -142,7 +143,7 @@ j_params() { return 1 fi - printf "jerror='' jname='%s' jdir='%s' jshell='%s'\n" "${jname}" "${jdir}" "${jshell}" + printf "jerror='' jname='%s' jdir='%s' jroot='%s' jshell='%s'\n" "${jname}" "${jdir}" "${jroot}" "${jshell}" ) } @@ -165,14 +166,14 @@ j_up() { jname="${1:-${jname}}" eval "$(j_params "${jname}")" [ "${jerror}" ] && wtf "${jerror}" - grep -q "^devpts ${jdir}/dev/pts devpts" /proc/mounts || return 1 - grep -q "^proc ${jdir}/proc proc" /proc/mounts || return 1 + grep -q "^devpts ${jroot}/dev/pts devpts" /proc/mounts || return 1 + grep -q "^proc ${jroot}/proc proc" /proc/mounts || return 1 return 0 } # Poll chroot status (j_up) j_status() { - [ -z "${1}" ] && set - $(l_ls) + [ -z "${1}" ] && set - $(j_ls) while [ "${1}" ] do j_up "${1}" && meh "$(printf '\033[1;32mup\033[0m')" || meh "$(printf '\033[1;31mdown\033[0m')" @@ -186,8 +187,8 @@ j_start() { j_up "${jname}" && return 0 eval "$(j_params "${jname}")" meh "starting ${jname} ..." - mount -t devpts devpts "${jdir}/dev/pts" - mount -t proc proc "${jdir}/proc" + mount -t devpts devpts "${jroot}/dev/pts" + mount -t proc proc "${jroot}/proc" # Start all services in /etc/rcJ.d j_root_eval "${jname}" '[ -d /etc/rcJ.d ] && ( ls -1 /etc/rcJ.d/* 2>&- | grep /S | sort | sed -e "s/$/ start/" | sh )' @@ -199,7 +200,7 @@ j_root_eval() { j_up "${jname}" || wtf "chroot not running" eval "$(j_params "${jname}")" shift - env -i ${jenv} /usr/bin/chroot "${jdir}" /bin/sh -c "${*}" + env -i ${jenv} /usr/bin/chroot "${jroot}" /bin/sh -c "${*}" } # Execute command in chroot @@ -208,7 +209,7 @@ j_eval() { j_up "${jname}" || wtf "chroot not running" eval "$(j_params "${jname}")" shift - env -i ${jenv} /usr/bin/chroot "${jdir}" /bin/su "${juser:-${USER}}" -c "${*}" + env -i ${jenv} /usr/bin/chroot "${jroot}" /bin/su "${juser:-${USER}}" -c "${*}" } j_shell() { @@ -227,8 +228,8 @@ j_stop() { # Stop all services in /etc/rcJ.d j_root_eval "${jname}" '[ -d /etc/rcJ.d ] && ( ls -1 /etc/rcJ.d/* 2>&- | grep /S | sort -r | sed -e "s/$/ stop/" | sh )' - umount "${jdir}/proc" - umount "${jdir}/dev/pts" + umount "${jroot}/proc" + umount "${jroot}/dev/pts" } case "${cmd}" in -- 2.45.0