#!/bin/sh -e
if [ -z $1 ]; then
- echo "Usage:"
- echo
- echo "$0 cfg_hostname.sh [image | setup | xml | define | start]"
- echo "$0 cfg_hostname.sh [undefine | delete]"
- exit 1
+ echo "Usage:"
+ echo
+ echo "$0 cfg_hostname.sh [image | setup | xml | define | start]"
+ echo "$0 cfg_hostname.sh [undefine | delete]"
+ exit 1
fi
. ./$1 || exit 1
VIRSH_ARGS="-c lxc://"
if [ -z $FACTER_fqdn ]; then
- echo "ERROR: no facter fqdn settings found"
- exit 1
+ echo "ERROR: no facter fqdn settings found"
+ exit 1
fi
if [ -z $FACTER_hostname ]; then
- echo "ERROR: no facter hostname settings found"
- exit 1
+ echo "ERROR: no facter hostname settings found"
+ exit 1
fi
image() {
- if [ -e ${IMAGE_FILE} ]; then
- echo "ERROR: image ${IMAGE_FILE} already exists"
- exit 1
- fi
+ if [ -e ${IMAGE_FILE} ]; then
+ echo "ERROR: image ${IMAGE_FILE} already exists"
+ exit 1
+ fi
mkdir ${IMAGE_FILE}
(cd ${IMAGE_FILE}; tar xzf ${IMAGE_SOURCE})
setup() {
- cd ${IMAGE_FILE} || exit 1
+ cd ${IMAGE_FILE} || exit 1
cp -vp /etc/resolv.conf /etc/apt/sources.list /etc/krb5.conf ./etc/
echo "pts/0" >> etc/securetty
- echo "${FACTER_hostname}" > etc/hostname
+ echo "${FACTER_hostname}" > etc/hostname
- cat << __EOF__ > etc/network/interfaces
+ cat << __EOF__ > etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
iface lo inet loopback
__EOF__
- if [ -n "${FACTER_ipaddress}" ]; then
- if [ "${FACTER_ipaddress}" = 'dhcp' ]; then
- cat << __EOF__ >> etc/network/interfaces
+ if [ -n "${FACTER_ipaddress}" ]; then
+ if [ "${FACTER_ipaddress}" = 'dhcp' ]; then
+ cat << __EOF__ >> etc/network/interfaces
auto eth0
iface eth0 inet dhcp
__EOF__
- else
- cat << __EOF__ >> etc/network/interfaces
+ else
+ cat << __EOF__ >> etc/network/interfaces
auto eth0
iface eth0 inet static
address $FACTER_ipaddress
gateway $FACTER_gw
__EOF__
- fi
- fi
- if [ -n "${FACTER_ipaddress6}" ]; then
- cat << __EOF__ >> etc/network/interfaces
+ fi
+ fi
+ if [ -n "${FACTER_ipaddress6}" ]; then
+ cat << __EOF__ >> etc/network/interfaces
iface eth0 inet6 static
- address ${FACTER_ipaddress6}
- netmask ${FACTER_netmask6}
- gateway ${FACTER_gw6}
+ address ${FACTER_ipaddress6}
+ netmask ${FACTER_netmask6}
+ gateway ${FACTER_gw6}
__EOF__
- fi
-
- if [ ! -d root/.ssh ]; then
- mkdir -p root/.ssh
- fi
- if [ ! -f root/.ssh/authorized_keys -a -f /root/.ssh/authorized_keys ]; then
- cp -v /root/.ssh/authorized_keys root/.ssh
- fi
-
- #sed -i etc/inittab -e 's/^#T\(0\)/T\1/'
- sed -i etc/inittab -e 's/^\([2-6]:\)/#\1/'
-
- cat >> root/.k5login << __EOF__
+ fi
+
+ if [ ! -d root/.ssh ]; then
+ mkdir -p root/.ssh
+ fi
+ if [ ! -f root/.ssh/authorized_keys -a -f /root/.ssh/authorized_keys ]; then
+ cp -v /root/.ssh/authorized_keys root/.ssh
+ fi
+
+ #sed -i etc/inittab -e 's/^#T\(0\)/T\1/'
+ sed -i etc/inittab -e 's/^\([2-6]:\)/#\1/'
+
+ cat >> root/.k5login << __EOF__
dexter@ADMIN.META
mulac@ADMIN.META
salvet@ADMIN.META
xml() {
if [ -n "${DISKS}" ]; then
- i=1
+ i=1
if echo ${DISKS} | grep -q '^/dev/sda'; then
src_i=1
else
src_i=7
fi
- for d in ${DISKS}; do
- XML_DISK="${XML_DISK}
+ for d in ${DISKS}; do
+ XML_DISK="${XML_DISK}
<filesystem type='mount' accessmode='passthrough'>
<source dir='/data/${src_i}${DISK_SUBDIR}'/>
<target dir='/data/${i}'/>
</filesystem>"
- i=$((i+1))
- src_i=$((src_i+1))
- done
- XML_DISK="${XML_DISK}
+ i=$((i+1))
+ src_i=$((src_i+1))
+ done
+ XML_DISK="${XML_DISK}
<filesystem type='mount' accessmode='passthrough'>
<source dir='/scratch${DISK_SUBDIR}'/>
<target dir='/scratch'/>
</filesystem>"
fi
- if [ -n "${XENBR}" ]; then
- XML_NET="
+ if [ -n "${XENBR}" ]; then
+ XML_NET="
<interface type='bridge'>
<source bridge='${XENBR}'/>
<mac address='${FACTER_macaddress}'/>
</interface>
"
- else
- XML_NET="
+ else
+ XML_NET="
<interface type='network'>
<source network='default'/>
<mac address='${FACTER_macaddress}'/>
</interface>
"
- fi
- cat << __EOF__ > /tmp/machine.xml
+ fi
+ cat << __EOF__ > /tmp/machine.xml
<domain type='lxc'>
<name>${FACTER_hostname}</name>
<currentMemory unit='MiB'>${SIZE_MEM}</currentMemory>
actions="$@"
if [ -z "${actions}" ]; then
- actions='image setup xml define start'
+ actions='image setup xml define start'
fi
for action in ${actions}; do case ${action} in
setup) setup ;;
xml) xml ;;
define)
- virsh ${VIRSH_ARGS} define /tmp/machine.xml
- ;;
+ virsh ${VIRSH_ARGS} define /tmp/machine.xml
+ ;;
start)
- virsh ${VIRSH_ARGS} start ${FACTER_hostname}
- echo "INFO: ${FACTER_hostname} started"
- ;;
+ virsh ${VIRSH_ARGS} start ${FACTER_hostname}
+ echo "INFO: ${FACTER_hostname} started"
+ ;;
stop)
- virsh ${VIRSH_ARGS} destroy ${FACTER_hostname}
- echo "INFO: ${FACTER_hostname} destroyed"
- ;;
+ virsh ${VIRSH_ARGS} destroy ${FACTER_hostname}
+ echo "INFO: ${FACTER_hostname} destroyed"
+ ;;
undefine)
- virsh ${VIRSH_ARGS} undefine ${FACTER_hostname}
- ;;
+ virsh ${VIRSH_ARGS} undefine ${FACTER_hostname}
+ ;;
delete)
- virsh ${VIRSH_ARGS} undefine ${FACTER_hostname} || :
- rm -fr ${IMAGE_POOL}/${FACTER_hostname}
- ;;
+ virsh ${VIRSH_ARGS} undefine ${FACTER_hostname} || :
+ rm -fr ${IMAGE_POOL}/${FACTER_hostname}
+ ;;
esac
done