summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Nichols <nichoj@gentoo.org>2006-08-30 23:21:26 +0000
committerJoshua Nichols <nichoj@gentoo.org>2006-08-30 23:21:26 +0000
commitabcba13afad4ad6ee39d94c33f760f6783b12978 (patch)
treea0b12a37615d25647dc8cd7e60aa1c80eb7e3585
parentAdded projectparser. Updated developer and devdashboard accordingly. (diff)
downloadnichoj-abcba13afad4ad6ee39d94c33f760f6783b12978.tar.gz
nichoj-abcba13afad4ad6ee39d94c33f760f6783b12978.tar.bz2
nichoj-abcba13afad4ad6ee39d94c33f760f6783b12978.zip
Adding trunk to chroot-manager
svn path=/; revision=64
-rwxr-xr-xprojects/chroot-manager/trunk/bin/chroot-execute41
-rwxr-xr-xprojects/chroot-manager/trunk/bin/chroot-mount15
-rwxr-xr-xprojects/chroot-manager/trunk/bin/chroot-shell10
-rw-r--r--projects/chroot-manager/trunk/etc/chroot-manager.conf5
-rw-r--r--projects/chroot-manager/trunk/etc/chroot-mounts/base.mounts7
-rw-r--r--projects/chroot-manager/trunk/etc/chroot-mounts/experimental.mounts1
-rw-r--r--projects/chroot-manager/trunk/etc/chroot-mounts/migration-overlay.mounts1
-rw-r--r--projects/chroot-manager/trunk/etc/chroot-mounts/staging-overlay.mounts1
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/amd64-stable-stage41
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/amd64-testing-stage41
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/amd64_stable2
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/amd64_testing1
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/broken-1.51
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/gcj-testbed1
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/java_stabilization2
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/kaffe1
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/migration1
-rw-r--r--projects/chroot-manager/trunk/etc/chroots/x86-stable-stage41
-rw-r--r--projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh167
19 files changed, 260 insertions, 0 deletions
diff --git a/projects/chroot-manager/trunk/bin/chroot-execute b/projects/chroot-manager/trunk/bin/chroot-execute
new file mode 100755
index 0000000..00e2249
--- /dev/null
+++ b/projects/chroot-manager/trunk/bin/chroot-execute
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+source /sbin/functions.sh
+
+CHROOT_PREFIX=$(dirname ${0})/.. # is there a better way?
+TARGET_CHROOT="${1}"
+if [[ -z ${TARGET_CHROOT} ]]; then
+ eerror "Expected one argument (the name of the chroot)"
+ exit 1
+fi
+shift # shift TARGET_CHROOT off of $@
+
+if [[ -z ${@} ]]; then
+ eerror "Expected some arguments to execute, but got none"
+ exit 1
+fi
+
+# Load our functions
+source "${CHROOT_PREFIX}/libexec/chroot-manager/chroot-functions.sh"
+# Load our settings
+source "${CHROOT_PREFIX}/etc/chroot-manager.conf"
+
+# Initialize the env
+init_chroot_env ${TARGET_CHROOT}
+
+# Call sudo if we're not root
+sudo=""
+if [[ ${UID} != 0 ]]; then
+ sudo="sudo -H"
+fi
+
+# Do all sorts of binds all over the place
+${sudo} ${CHROOT_PREFIX}/bin/chroot-mount ${TARGET_CHROOT}
+
+# Call linux32 if we're going into an x86 chroot
+linux32=""
+if [[ ${TARGET_CHROOT} =~ x86 ]]; then
+ linux32=linux32
+fi
+
+${sudo} ${linux32} chroot ${CHROOT_HOME} "$@"
diff --git a/projects/chroot-manager/trunk/bin/chroot-mount b/projects/chroot-manager/trunk/bin/chroot-mount
new file mode 100755
index 0000000..527ef95
--- /dev/null
+++ b/projects/chroot-manager/trunk/bin/chroot-mount
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+TARGET_CHROOT="${1}"
+if [[ -z ${TARGET_CHROOT} ]]; then
+ eerror "Expected one argument (the name of the chroot)"
+ exit 1
+fi
+
+CHROOT_MANAGER_HOME=$(dirname $0)/..
+CHROOT_MANAGER_LIBEXEC="${CHROOT_MANAGER_HOME}/libexec/chroot-manager"
+
+source "${CHROOT_MANAGER_LIBEXEC}/chroot-functions.sh"
+
+init_chroot_env ${TARGET_CHROOT}
+bind_chroot_dirs
diff --git a/projects/chroot-manager/trunk/bin/chroot-shell b/projects/chroot-manager/trunk/bin/chroot-shell
new file mode 100755
index 0000000..178fdc1
--- /dev/null
+++ b/projects/chroot-manager/trunk/bin/chroot-shell
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+source /sbin/functions.sh
+TARGET_CHROOT="${1}"
+if [[ -z ${TARGET_CHROOT} ]]; then
+ eerror "Expected one argument (the name of the chroot)"
+ exit 1
+fi
+# Run execute a login shell in our chroot
+$(dirname $0)/chroot-execute "${TARGET_CHROOT}" /bin/bash
diff --git a/projects/chroot-manager/trunk/etc/chroot-manager.conf b/projects/chroot-manager/trunk/etc/chroot-manager.conf
new file mode 100644
index 0000000..9447ef3
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroot-manager.conf
@@ -0,0 +1,5 @@
+CHROOTS_HOME="/chroots"
+CHROOT_PREFIX="/home/nichoj/chroot-manager"
+CHROOT_ETC="${CHROOT_PREFIX}/etc"
+
+ACTIVE_CHROOTS="amd64_stable amd64_testing java_stabilization"
diff --git a/projects/chroot-manager/trunk/etc/chroot-mounts/base.mounts b/projects/chroot-manager/trunk/etc/chroot-mounts/base.mounts
new file mode 100644
index 0000000..a8ba14f
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroot-mounts/base.mounts
@@ -0,0 +1,7 @@
+/usr/portage=/home/nichoj/checkouts/gentoo-x86
+/usr/local/overlays=/usr/local/overlays
+/proc=/proc
+/sys=/sys
+/tmp=/tmp
+/dev=/dev
+/usr/src=/usr/src
diff --git a/projects/chroot-manager/trunk/etc/chroot-mounts/experimental.mounts b/projects/chroot-manager/trunk/etc/chroot-mounts/experimental.mounts
new file mode 100644
index 0000000..5903fbe
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroot-mounts/experimental.mounts
@@ -0,0 +1 @@
+/usr/local/overlays/java-experimental=/development/overlays/java-experimental
diff --git a/projects/chroot-manager/trunk/etc/chroot-mounts/migration-overlay.mounts b/projects/chroot-manager/trunk/etc/chroot-mounts/migration-overlay.mounts
new file mode 100644
index 0000000..69584fa
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroot-mounts/migration-overlay.mounts
@@ -0,0 +1 @@
+/usr/local/overlays/migration=/development/overlays/migration
diff --git a/projects/chroot-manager/trunk/etc/chroot-mounts/staging-overlay.mounts b/projects/chroot-manager/trunk/etc/chroot-mounts/staging-overlay.mounts
new file mode 100644
index 0000000..de1522e
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroot-mounts/staging-overlay.mounts
@@ -0,0 +1 @@
+/usr/local/overlays/staging=/development/overlays/staging
diff --git a/projects/chroot-manager/trunk/etc/chroots/amd64-stable-stage4 b/projects/chroot-manager/trunk/etc/chroots/amd64-stable-stage4
new file mode 100644
index 0000000..77d397a
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/amd64-stable-stage4
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base staging-overlay"
diff --git a/projects/chroot-manager/trunk/etc/chroots/amd64-testing-stage4 b/projects/chroot-manager/trunk/etc/chroots/amd64-testing-stage4
new file mode 100644
index 0000000..77d397a
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/amd64-testing-stage4
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base staging-overlay"
diff --git a/projects/chroot-manager/trunk/etc/chroots/amd64_stable b/projects/chroot-manager/trunk/etc/chroots/amd64_stable
new file mode 100644
index 0000000..2a86d1a
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/amd64_stable
@@ -0,0 +1,2 @@
+MOUNT_CONFIGS="base"
+CHROOT_DEV="/dev/vg/amd64_stable"
diff --git a/projects/chroot-manager/trunk/etc/chroots/amd64_testing b/projects/chroot-manager/trunk/etc/chroots/amd64_testing
new file mode 100644
index 0000000..be786cf
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/amd64_testing
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base"
diff --git a/projects/chroot-manager/trunk/etc/chroots/broken-1.5 b/projects/chroot-manager/trunk/etc/chroots/broken-1.5
new file mode 100644
index 0000000..b0f0065
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/broken-1.5
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base"
diff --git a/projects/chroot-manager/trunk/etc/chroots/gcj-testbed b/projects/chroot-manager/trunk/etc/chroots/gcj-testbed
new file mode 100644
index 0000000..be786cf
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/gcj-testbed
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base"
diff --git a/projects/chroot-manager/trunk/etc/chroots/java_stabilization b/projects/chroot-manager/trunk/etc/chroots/java_stabilization
new file mode 100644
index 0000000..a96333c
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/java_stabilization
@@ -0,0 +1,2 @@
+MOUNT_CONFIGS="base"
+CHROOT_DEV="/dev/vg/java_stabilization"
diff --git a/projects/chroot-manager/trunk/etc/chroots/kaffe b/projects/chroot-manager/trunk/etc/chroots/kaffe
new file mode 100644
index 0000000..be786cf
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/kaffe
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base"
diff --git a/projects/chroot-manager/trunk/etc/chroots/migration b/projects/chroot-manager/trunk/etc/chroots/migration
new file mode 100644
index 0000000..be786cf
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/migration
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base"
diff --git a/projects/chroot-manager/trunk/etc/chroots/x86-stable-stage4 b/projects/chroot-manager/trunk/etc/chroots/x86-stable-stage4
new file mode 100644
index 0000000..b0f0065
--- /dev/null
+++ b/projects/chroot-manager/trunk/etc/chroots/x86-stable-stage4
@@ -0,0 +1 @@
+MOUNT_CONFIGS="base"
diff --git a/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh b/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh
new file mode 100644
index 0000000..51b6d20
--- /dev/null
+++ b/projects/chroot-manager/trunk/libexec/chroot-manager/chroot-functions.sh
@@ -0,0 +1,167 @@
+
+source "/sbin/functions.sh" 2>/dev/null || die "Failed to source /sbin/functions.sh"
+source "/home/nichoj/chroot-manager/etc/chroot-manager.conf" 2>/dev/null || die "failed to source chroot-manager.conf"
+
+
+init_chroot_env() {
+ CHROOT_NAME="${1}"
+
+ local chroot_config="${CHROOT_ETC}/chroots/${CHROOT_NAME}"
+ if [[ ! -f "${chroot_config}" ]]; then
+ eerror "${chroot_config} is not a file or does not exist"
+ return 1
+ fi
+ source "${chroot_config}"
+ CHROOT_HOME="${CHROOTS_HOME}/${CHROOT_NAME}"
+
+ if [[ -n ${CHROOT_DEV} ]]; then
+ if ! is_mounted "${CHROOT_HOME}"; then
+ ebegin "Mounting ${CHROOT_HOME}"
+ mount ${CHROOT_DEV} ${CHROOT_HOME}
+ local result=$?
+ eend ${result}
+ if [[ ${result} != 0 ]]; then
+ eerror "Problem mounting ${CHROOT_DEV} to ${CHROOT_HOME}"
+ exit 1
+ fi
+ fi
+ fi
+}
+
+list_chroots() {
+ for vm_chroot in $(find ${CHROOT_HOME} -maxdepth 1 -type d); do
+ vm_chroot=${vm_chroot#${CHROOT_HOME}}
+ vm_chroot=${vm_chroot//\//}
+ echo ${vm_chroot}
+ done
+}
+
+sudo_wrapper() {
+ local command=${*}
+
+ if [ ${UID} != 0 ]; then
+ sudo ${command}
+ else
+ ${command}
+ fi
+}
+
+setup_initial_chroot() {
+ setup_chroot
+ enter_chroot java-config -S ${TARGET_VM}
+ enter_chroot env-update
+ enter_chroot sed -e 's/buildpkg//' -i /etc/make.conf
+ if [ ! -z ${NOJIKES} ]; then
+ enter_chroot sed -e 's/jikes//' -i /etc/make.conf
+ fi
+ teardown_chroot
+}
+
+
+function bind_chroot_dirs() {
+ chroot_dirs_helper "bind_dir"
+}
+
+function unbind_chroot_dirs() {
+ chroot_dirs_helper "unbind_dir"
+}
+
+function chroot_dirs_helper() {
+ local function="$1"
+ local chroot_config="${CHROOT_ETC}/chroots/${CHROOT_NAME}"
+ echo "Reading config file for ${CHROOT_NAME} at ${chroot_config}"
+
+ if [[ ! -f ${chroot_config} ]]; then
+ echo "File does not exist: ${chroot_config}"
+ return 1
+ fi
+
+ 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"
+ local mount_config_path="${CHROOT_ETC}/chroot-mounts/${mount_config}.mounts"
+ mounts_loop_helper ${function} < ${mount_config_path}
+ done
+}
+
+function bind_dir() {
+ local chroot_path="${1}"
+ local chrooted_path="${CHROOT_HOME}${chroot_path}"
+ local real_path="${2}"
+
+ if ! is_mounted "${chrooted_path}"; then
+ if [[ ! -d "${chrooted_path}" ]]; then
+ ebegin "Creating ${chrooted_path}"
+ mkdir -p "${chrooted_path}"
+ if [[ "$?" != 0 ]]; then
+ eerror "Could not create ${chrooted_path}"
+ return 1
+ fi
+ eend
+ fi
+
+ ebegin "Binding ${real_path} to ${chrooted_path}"
+ mount -o bind ${real_path} ${chrooted_path}
+ eend $?
+ else
+ ewarn "${chrooted_path} already mounted, skipping."
+
+ fi
+}
+
+function 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}"
+
+ umount "${chrooted_path}"
+ eend $?
+ fi
+}
+
+function mounts_loop_helper() {
+ local function="${1}"
+ shift
+
+ local line
+ read line
+ local result=$?
+ while [[ ${result} == 0 ]]; do
+ # Ignore comments
+ [[ ${line%%#*} == "" ]] && continue
+
+ # get rid of any spaces
+ line="${line// /}"
+
+ local chroot_path="${line%%=*}"
+ local real_path="${line##*=}"
+
+ eval "${function}" "${chroot_path}" "${real_path}"
+
+ read line
+ result=$?
+ done
+}
+
+function is_mounted() {
+ local mount_point="${1}"
+
+ # replace double-slashes with single ones
+ mount_point="${mount_point/\/\///}"
+
+ # strip trailing slash
+ [[ ${mount_point} =~ "\/$" ]] && mount_point="${mount_point%%/}"
+
+ local mounted_dir
+ for mounted_dir in $(awk '{print $2}' /etc/mtab); do
+ if [[ "${mounted_dir}" == "${mount_point}" ]]; then
+ return 0
+ fi
+ done
+
+ return 1
+}