[Fusionforge-commits] r12607 - in trunk/tests: lxc scripts

Christian Bayle cbayle at fusionforge.org
Tue Mar 8 14:15:11 CET 2011


Author: cbayle
Date: 2011-03-08 14:15:10 +0100 (Tue, 08 Mar 2011)
New Revision: 12607

Modified:
   trunk/tests/lxc/lxc-centos5.postinst
   trunk/tests/lxc/lxc-debian6.postinst
   trunk/tests/scripts/start_lxc.sh
Log:
generate and store per hostname hostkeys


Modified: trunk/tests/lxc/lxc-centos5.postinst
===================================================================
--- trunk/tests/lxc/lxc-centos5.postinst	2011-03-07 23:37:23 UTC (rev 12606)
+++ trunk/tests/lxc/lxc-centos5.postinst	2011-03-08 13:15:10 UTC (rev 12607)
@@ -54,24 +54,36 @@
 configure_hostkeydir(){
 	rootfs=$1
 	hostkeydir=$2
-	if [ $# -ne 2 ]
+	name=$3
+	if [ $# -ne 3 ]
 	then
 		exit 1
 	else
 		[ -d $rootfs/etc/ssh ] || mkdir -p $rootfs/etc/ssh
-		[ -e $hostkeydir ] && cp $hostkeydir/ssh_host_* $rootfs/etc/ssh/
+		if [ -e $hostkeydir ]
+		then 
+			if [ ! -d $hostkeydir/$name ]
+			then
+				mkdir $hostkeydir/$name
+				echo "Creating SSH2 RSA key; this may take some time ..."
+				ssh-keygen -q -f $hostkeydir/$name/ssh_host_rsa_key -N '' -t rsa
+				echo "Creating SSH2 DSA key; this may take some time ..."
+				ssh-keygen -q -f $hostkeydir/$name/ssh_host_dsa_key -N '' -t dsa
+			fi
+			cp $hostkeydir/$name/ssh_host_* $rootfs/etc/ssh/
+		fi
 	fi
 }
 
 usage()
 {
     cat <<EOF
-$1 -h|--help -p|--path=<path> --clean --address=<address> --netmask=<netmask> --gateway=<gateway> --pubkey=<pubkey> --hostkeydir=<hostkeydir>
+$1 -h|--help -p|--path=<path> --clean --address=<address> --netmask=<netmask> --gateway=<gateway> --pubkey=<pubkey>
 EOF
     return 0
 }
 
-options=$(getopt -o hp:n:c -l help,path:,name:,clean:,address:,netmask:,gateway:,pubkey:,hostkeydir: -- "$@")
+options=$(getopt -o hp:n:c -l help,path:,name:,clean:,address:,netmask:,gateway:,pubkey: -- "$@")
 if [ $? -ne 0 ]; then
         usage $(basename $0)
         exit 1
@@ -88,7 +100,6 @@
 	--netmask)	netmask=$2; shift 2;;
 	--gateway)	gateway=$2; shift 2;;
 	--pubkey)	pubkey=$2; shift 2;;
-	--hostkeydir)	hostkeydir=$2; shift 2;;
         --)             shift 1; break ;;
         *)              break ;;
     esac
@@ -105,6 +116,8 @@
 fi
 
 rootfs=$path/rootfs
+hostkeydir=/var/lib/lxc/ssh
+mkdir $hostkeydir
 
 configure_network $rootfs $address $netmask $gateway $name
 if [ $? -ne 0 ]; then
@@ -118,7 +131,7 @@
     exit 1
 fi
 
-configure_hostkeydir $rootfs $hostkeydir
+configure_hostkeydir $rootfs $hostkeydir $name
 if [ $? -ne 0 ]; then
     echo "failed to configure hostkeydir"
     exit 1

Modified: trunk/tests/lxc/lxc-debian6.postinst
===================================================================
--- trunk/tests/lxc/lxc-debian6.postinst	2011-03-07 23:37:23 UTC (rev 12606)
+++ trunk/tests/lxc/lxc-debian6.postinst	2011-03-08 13:15:10 UTC (rev 12607)
@@ -48,24 +48,36 @@
 configure_hostkeydir(){
 	rootfs=$1
 	hostkeydir=$2
-	if [ $# -ne 2 ]
+	name=$3
+	if [ $# -ne 3 ]
 	then
 		exit 1
 	else
 		[ -d $rootfs/etc/ssh ] || mkdir -p $rootfs/etc/ssh
-		[ -e $hostkeydir ] || cp $hostkeydir/ssh_host_* $rootfs/etc/ssh/
+		if [ -e $hostkeydir ]
+		then 
+			if [ ! -d $hostkeydir/$name ]
+			then
+				mkdir $hostkeydir/$name
+				echo "Creating SSH2 RSA key; this may take some time ..."
+				ssh-keygen -q -f $hostkeydir/$name/ssh_host_rsa_key -N '' -t rsa
+				echo "Creating SSH2 DSA key; this may take some time ..."
+				ssh-keygen -q -f $hostkeydir/$name/ssh_host_dsa_key -N '' -t dsa
+			fi
+			cp $hostkeydir/$name/ssh_host_* $rootfs/etc/ssh/
+		fi
 	fi
 }
 
 usage()
 {
     cat <<EOF
-$1 -h|--help -p|--path=<path> --clean --address=<address> --netmask=<netmask> --gateway=<gateway> --pubkey=<pubkey> --hostkeydir=<hostkeydir>
+$1 -h|--help -p|--path=<path> --clean --address=<address> --netmask=<netmask> --gateway=<gateway> --pubkey=<pubkey>
 EOF
     return 0
 }
 
-options=$(getopt -o hp:n:c -l help,path:,name:,clean:,address:,netmask:,gateway:,pubkey:,hostkeydir: -- "$@")
+options=$(getopt -o hp:n:c -l help,path:,name:,clean:,address:,netmask:,gateway:,pubkey: -- "$@")
 if [ $? -ne 0 ]; then
         usage $(basename $0)
         exit 1
@@ -82,7 +94,6 @@
 	--netmask)	netmask=$2; shift 2;;
 	--gateway)	gateway=$2; shift 2;;
 	--pubkey)	pubkey=$2; shift 2;;
-	--hostkeydir)	hostkeydir=$2; shift 2;;
         --)             shift 1; break ;;
         *)              break ;;
     esac
@@ -99,6 +110,8 @@
 fi
 
 rootfs=$path/rootfs
+hostkeydir=/var/lib/lxc/ssh
+mkdir $hostkeydir
 
 configure_network $rootfs $address $netmask $gateway $name
 if [ $? -ne 0 ]; then
@@ -112,7 +125,7 @@
     exit 1
 fi
 
-configure_hostkeydir $rootfs $hostkeydir
+configure_hostkeydir $rootfs $hostkeydir $name
 if [ $? -ne 0 ]; then
     echo "failed to configure hostkeydir"
     exit 1

Modified: trunk/tests/scripts/start_lxc.sh
===================================================================
--- trunk/tests/scripts/start_lxc.sh	2011-03-07 23:37:23 UTC (rev 12606)
+++ trunk/tests/scripts/start_lxc.sh	2011-03-08 13:15:10 UTC (rev 12607)
@@ -63,8 +63,7 @@
 		--address=$IPBASE.$VEID \
 		--netmask=$IPMASK \
 		--gateway=$IPGW \
-		--pubkey=$SSHPUBKEY \
-		--hostkeydir=$HOSTKEYDIR
+		--pubkey=$SSHPUBKEY
 	sudo /usr/bin/lxc-start -n $HOST -d
 fi
 




More information about the Fusionforge-commits mailing list