Reformat (remove tabs).
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 10 Dec 2015 19:10:22 +0000 (20:10 +0100)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 10 Dec 2015 19:10:22 +0000 (20:10 +0100)
lxc.sh

diff --git a/lxc.sh b/lxc.sh
index d33db5a..3de64fa 100755 (executable)
--- a/lxc.sh
+++ b/lxc.sh
@@ -1,11 +1,11 @@
 #!/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
 
@@ -16,20 +16,20 @@ IMAGE_SOURCE=/var/lib/lxc/debian7-x86_64.tar.gz
 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})
@@ -37,14 +37,14 @@ image() {
 
 
 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).
 
@@ -53,15 +53,15 @@ auto lo
 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
@@ -69,29 +69,29 @@ iface eth0 inet static
         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
@@ -107,29 +107,29 @@ __EOF__
 
 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}'/>
@@ -137,8 +137,8 @@ xml() {
     </interface>
 
 "
-       else
-               XML_NET="
+    else
+        XML_NET="
     <interface type='network'>
       <source network='default'/>
       <mac address='${FACTER_macaddress}'/>
@@ -146,8 +146,8 @@ xml() {
     </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>
@@ -184,7 +184,7 @@ shift
 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
@@ -192,23 +192,23 @@ image) image ;;
 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