Skip to content
Browse files

initial profile support

  • Loading branch information...
1 parent fa3a0fc commit 616c7d3f3fc46afd23abb941b45d587a747b032b @mika committed Oct 31, 2011
View
17 debian/rules
@@ -9,10 +9,6 @@
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
-INSTALL = install
-INSTALL_EXECUTABLES = $(INSTALL)
-INSTALL_FILES = $(INSTALL) -p -oroot -groot -m644
-
build: build-stamp
build-stamp:
@@ -30,14 +26,11 @@ clean:
install: build
dh_testdir
dh_testroot
- dh_installdirs usr/share/kantan/boot/ usr/share/kantan/debs/ \
- usr/share/kantan/scripts/ usr/share/kantan/netboot \
- usr/sbin etc/kantan/
-
- $(INSTALL_FILES) config/* debian/kantan/etc/kantan/
- $(INSTALL_FILES) scripts/* debian/kantan/usr/share/kantan/scripts/
- $(INSTALL_FILES) netboot/*iso debian/kantan/usr/share/kantan/netboot/
- $(INSTALL_EXECUTABLES) sbin/kantan debian/kantan/usr/sbin/
+ dh_installdirs usr/share/kantan/scripts/ usr/sbin
+
+ cp -a example_profile debian/kantan/usr/share/kantan/
+ cp -a scripts debian/kantan/usr/share/kantan/
+ install -m 755 sbin/kantan debian/kantan/usr/sbin/
binary-arch: install
View
0 netboot/ipxe.iso → example_profile/ipxe.iso
File renamed without changes.
View
0 config/server.cfg → example_profile/server.cfg
File renamed without changes.
View
0 scripts/fai.conf → example_profile/share/fai.conf
File renamed without changes.
View
0 scripts/hook-post → example_profile/share/hook-post
File renamed without changes.
View
0 scripts/netscript.sh → example_profile/share/netscript.sh
File renamed without changes.
View
93 sbin/kantan
@@ -6,7 +6,6 @@
# License: This file is licensed under the GPL v2 or any later version.
################################################################################
-set -e
set -u
info() {
@@ -29,7 +28,9 @@ bailout() {
[ -n "${kvm_pid:-}" ] && kill -9 "$kvm_pid" &>/dev/null
[ -n "${vde_pid:-}" ] && kill -9 "$vde_pid" &>/dev/null
[ -d "${tmpfile:-}" ] && rm -f "$tmpfile"
- [ "$TYPE" == "server" ] && [ -d /tmp/kantan_share/ ] && rm -rf /tmp/kantan_share/
+ if [ "$TYPE" == "server" ] ; then
+ [ -d /tmp/kantan_share/${PROFILE_DIRECTORY} ] && rm -rf /tmp/kantan_share/${PROFILE_DIRECTORY}
+ fi
[ -n "${1:-}" ] && exit "$1" || exit 1
}
@@ -40,17 +41,17 @@ usage() {
Usage:
- $0 server <disk.img> <grml.iso> </mnt/point/of/iso/>
+ $0 server <profile_directory> <disk.img> <grml.iso> </mnt/point/of/iso/>
or
- $0 client <disk.img> [<name>] [kvm_arguments]
+ $0 client <profile_directory> <disk.img> [<name>] [kvm_arguments]
$0 help -- display usage instructions (this screen)
$0 server -- start main KVM instance
$0 client -- start client KVM instance
-Copyright (c) 2010, Michael Prokop <mika@grml.org>
+Copyright (c) 2011, Michael Prokop <mika@grml.org>
"
}
@@ -59,19 +60,26 @@ if [[ "${1:-}" == "help" ]] || [[ "${1:-}" == "--help" ]] || [[ -z "${1:-}" ]] ;
exit 0
fi
-VDE_SWITCH='/tmp/kantan_share/vde_switch'
-
# server handling
server_execution() {
- . /etc/kantan/server.cfg
-
- current_working_dir=$(pwd)
+ VDE_SWITCH="/tmp/kantan_share/${PROFILE_DIRECTORY}/vde_switch"
+ mkdir -p "$VDE_SWITCH"
+ # checks
if ! [ -d "${ISO_DIR}/boot" ] ; then
error "Error: no directory /boot found on $ISO_DIR (forgot to mount ISO?)"
exit 1
fi
+ if ! [ -d "${PROFILE_DIRECTORY}/share/" ] ; then
+ error "Error: ${PROFILE_DIRECTORY}/share/ not found."
+ exit 1
+ fi
+
+ . "${PROFILE_DIRECTORY}/server.cfg"
+
+ current_working_dir=$(pwd)
+
[ -d /tmp/kantan_share ] || mkdir -m 700 /tmp/kantan_share
vde_switch -s ${VDE_SWITCH} &
vde_pid="$!"
@@ -80,12 +88,12 @@ server_execution() {
INITRD=$(find ${ISO_DIR}/boot -name initrd.gz -print0)
if [ -z "${KERNEL:-}" ] ; then
- error "Error: no kernel file linux26 found on $ISO_DIR"
+ error "Error: no kernel file linux26 found on $ISO_DIR" >&2
exit 1
fi
if [ -z "${INITRD:-}" ] ; then
- error "Error: no initrd file initrd.gz found on $ISO_DIR"
+ error "Error: no initrd file initrd.gz found on $ISO_DIR" >&2
exit 1
fi
@@ -98,17 +106,17 @@ server_execution() {
socat -u TCP4-LISTEN:8888,reuseaddr,fork - > "${tmpfile}" &
socat_pid="$!"
- info "Serving /usr/share/kantan/scripts/ to port 8000 for netscript bootoption."
- cd /usr/share/kantan/scripts/
+ info "Serving ${PROFILE_DIRECTORY}/share/ to port 8000 for netscript bootoption."
+ cd "${PROFILE_DIRECTORY}/share/"
python -m SimpleHTTPServer 8000 &>/dev/null &
http_pid_scripts="$!"
cd "$current_working_dir"
- if ! [ -d "debs" ] ; then
- warn "No directory debs/ found, will not serve local Debian packages."
+ if ! [ -d "${PROFILE_DIRECTORY}/debs" ] ; then
+ warn "No directory ${PROFILE_DIRECTORY}/debs/ found, will not serve local Debian packages."
else
- cd debs
+ cd "${PROFILE_DIRECTORY}/debs"
if ! which dpkg-scanpackages &>/dev/null ; then
error "dpkg-scanpackages not available, please install package dpkg-dev."
@@ -151,12 +159,14 @@ server_execution() {
# client handling
client_execution() {
+ VDE_SWITCH="/tmp/kantan_share/${PROFILE_DIRECTORY}/vde_switch"
+
if [ -n "$CLIENTNAME" ] ; then
- if [ -r "/etc/kantan/${CLIENTNAME}.cfg" ] ; then
- info "Reading configuration file /etc/kantan/${CLIENTNAME}.cfg"
- . "/etc/kantan/${CLIENTNAME}.cfg"
+ if [ -r "${PROFILE_DIRECTORY}/${CLIENTNAME}.cfg" ] ; then
+ info "Reading configuration file ${PROFILE_DIRECTORY}/${CLIENTNAME}.cfg"
+ . "${PROFILE_DIRECTORY}/${CLIENTNAME}.cfg"
else
- info "Configuration file /etc/kantan/${CLIENTNAME}.cfg not found, using defaults."
+ info "Configuration file ${PROFILE_DIRECTORY}/${CLIENTNAME}.cfg not found, using defaults."
fi
fi
@@ -167,7 +177,14 @@ client_execution() {
fi
# default if unset
- [ -z "${CLIENT_ISO:-}" ] && CLIENT_ISO='/usr/share/kantan/netboot/ipxe.iso'
+ if [ -z "${CLIENT_ISO:-}" ] ; then
+ CLIENT_ISO="${PROFILE_DIRECTORY}/ipxe.iso"
+ fi
+
+ if ! [ -r "${CLIENT_ARGS:-}" ] ; then
+ error "Client ISO $CLIENT_ISO can not be read."
+ exit 1
+ fi
if [ -z "${KVM_CMDLINE:-}" ] ; then
KVM_CMDLINE="kvm -k en-us -m ${CLIENT_MEMORY:-512} \
@@ -232,38 +249,44 @@ console() {
}
# main execution
-TYPE="${1:-}"
-HDA="${2:-}"
+PROFILE_DIRECTORY="${1:-}"
+TYPE="${2:-}"
+HDA="${3:-}"
-if [[ "${1:-}" == "server" ]] ; then
+if ! [ -d "$PROFILE_DIRECTORY" ] ; then
+ error "Error: profile directory $PROFILE_DIRECTORY does not exist."
+ exit 1
+fi
+
+if [[ "${2:-}" == "server" ]] ; then
# check args
- if [[ -z "${4:-}" ]] ; then
+ if [[ -z "${5:-}" ]] ; then
usage
exit 1
fi
- ISO_FILE="${3:-}"
- ISO_DIR="${4:-}"
+ ISO_FILE="${4:-}"
+ ISO_DIR="${5:-}"
- if [ -n "${5:-}" ] ; then
+ if [ -n "${6:-}" ] ; then
ADDITIONAL_KVMSERVER_ARGS="$5"
fi
server_execution
-elif [[ "${1:-}" == "client" ]] ; then
+elif [[ "${2:-}" == "client" ]] ; then
# check args
- if [[ -z "${2:-}" ]] ; then
+ if [[ -z "${3:-}" ]] ; then
usage
exit 1
fi
- if [ -n "${3:-}" ] ; then
- CLIENTNAME="${3:-}"
+ if [ -n "${4:-}" ] ; then
+ CLIENTNAME="${4:-}"
fi
- if [ -n "${4:-}" ] ; then
- CLIENT_ARGS="$4"
+ if [ -n "${5:-}" ] ; then
+ CLIENT_ARGS="$5"
fi
client_execution

0 comments on commit 616c7d3

Please sign in to comment.
Something went wrong with that request. Please try again.