diff options
3 files changed, 32 insertions, 15 deletions
diff --git a/projects/chroot-manager/trunk/bin/chroot-execute b/projects/chroot-manager/trunk/bin/chroot-execute index 00e2249..8abf7c5 100755 --- a/projects/chroot-manager/trunk/bin/chroot-execute +++ b/projects/chroot-manager/trunk/bin/chroot-execute @@ -23,7 +23,7 @@ source "${CHROOT_PREFIX}/etc/chroot-manager.conf" # Initialize the env init_chroot_env ${TARGET_CHROOT} -# Call sudo if we're not root +# Be smart and use sudo for when we aren't root sudo="" if [[ ${UID} != 0 ]]; then sudo="sudo -H" diff --git a/projects/chroot-manager/trunk/etc/chroots/ppc64_testing b/projects/chroot-manager/trunk/etc/chroots/ppc64_testing new file mode 100644 index 0000000..9c487d0 --- /dev/null +++ b/projects/chroot-manager/trunk/etc/chroots/ppc64_testing @@ -0,0 +1,2 @@ +MOUNT_CONFIGS="base" +CHROOT_DEV="/dev/vg/ppc64_testing" diff --git a/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh b/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh index 8abe048..df6e8de 100644 --- a/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh +++ b/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh @@ -1,7 +1,11 @@ source "/sbin/functions.sh" 2>/dev/null || die "Failed to source /sbin/functions.sh" -source "/home/nichoj/checkouts/chroot-manager/trunk/etc/chroot-manager.conf" 2>/dev/null || die "failed to source chroot-manager.conf" +CHROOT_PREFIX=$(dirname ${0})/.. # is there a better way? +source "${CHROOT_PREFIX}/etc/chroot-manager.conf" 2>/dev/null || die "failed to source chroot-manager.conf" +verbose() { + [[ -n ${CHROOT_VERBOSE} ]] +} init_chroot_env() { CHROOT_NAME="${1}" @@ -14,12 +18,14 @@ init_chroot_env() { source "${chroot_config}" CHROOT_HOME="${CHROOTS_HOME}/${CHROOT_NAME}" + # If we're using a device for chroot if [[ -n ${CHROOT_DEV} ]]; then + # attempt to mount if it isn't already if ! is_mounted "${CHROOT_HOME}"; then - ebegin "Mounting ${CHROOT_HOME}" + verbose && ebegin "Mounting ${CHROOT_DEV} to ${CHROOT_HOME}" mount ${CHROOT_DEV} ${CHROOT_HOME} local result=$? - eend ${result} + verbose && eend ${result} if [[ ${result} != 0 ]]; then eerror "Problem mounting ${CHROOT_DEV} to ${CHROOT_HOME}" exit 1 @@ -58,6 +64,12 @@ setup_initial_chroot() { } +# we have a few helper methods, bind_dir and unbind_dir. +# these do the heavy lifting of, uh, binding and unbinding :) +# we pass the names here, because they get eval'd later on. +# basically, we're trying to avoid excessively redudant code + + function bind_chroot_dirs() { chroot_dirs_helper "bind_dir" } @@ -67,9 +79,9 @@ function unbind_chroot_dirs() { } function chroot_dirs_helper() { - local function="$1" + local action="$1" local chroot_config="${CHROOT_ETC}/chroots/${CHROOT_NAME}" - echo "Reading config file for ${CHROOT_NAME} at ${chroot_config}" + verbose && echo "Reading config file for ${CHROOT_NAME} at ${chroot_config}" if [[ ! -f ${chroot_config} ]]; then echo "File does not exist: ${chroot_config}" @@ -79,16 +91,18 @@ function chroot_dirs_helper() { local mount_configs=$(source ${chroot_config} >/dev/null 2>&1; echo ${MOUNT_CONFIGS}) local mount_config for mount_config in ${mount_configs}; do - einfo "Checking '${mount_config}' mounts" + verbose && einfo "Processing '${mount_config}' mounts" local mount_config_path="${CHROOT_ETC}/chroot-mounts/${mount_config}.mounts" - mounts_loop_helper ${function} < ${mount_config_path} + mounts_loop_helper ${action} < ${mount_config_path} done } -function bind_dir() { +# binding helper function. takes a path on the real system, and binds it to +# a path living inside the chroot +bind_dir() { local chroot_path="${1}" - local chrooted_path="${CHROOT_HOME}${chroot_path}" local real_path="${2}" + local chrooted_path="${CHROOT_HOME}${chroot_path}" if ! is_mounted "${chrooted_path}"; then if [[ ! -d "${chrooted_path}" ]]; then @@ -105,21 +119,22 @@ function bind_dir() { mount -o bind ${real_path} ${chrooted_path} eend $? else - ewarn "${chrooted_path} already mounted, skipping." - + verbose && ewarn "${chrooted_path} already mounted, skipping." fi } -function unbind_dir() { +# binding helper function. takes a path on the real system, and binds it to +# a path living inside the chroot +unbind_dir() { local chroot_path="${1}" local chrooted_path="${CHROOT_HOME}${chroot_path}" local real_path="${2}" if is_mounted "${chrooted_path}"; then - ebegin "Unbinding ${real_path} from ${chrooted_path}" + verbose && ebegin "Unbinding ${real_path} from ${chrooted_path}" umount "${chrooted_path}" - eend $? + verbose && eend $? fi } |