Hi,

I added some code also allowing voyage.update to
be run unattended which really helps if one 
has to set up a bunch of alix (or other) boxes.

So it may be called this way:

cd voyage-current
./usr/local/sbin/voyage.update  -i  -P ALIX -t /dev/sdc -p 1 -m /mnt/cf -b 1 -g 
-s 9600 -c serial -d .

and everything's fine.

Comments are welcome.

-Chris

-- 
LiHAS - Adrian Reyer - Krehlstra??e 1 - D-70563 Stuttgart
Fon: +49 (7 11) 78 28 50 90 - Fax:  +49 (7 11) 78 28 50 91
Mail: [email protected] - Web: http://lihas.de
Linux, Netzwerke, Consulting & Support - USt-ID: DE 227 816 626 Stuttgart
--- voyage-current/usr/local/sbin/voyage.update-x	2009-09-22 16:29:03.000000000 +0200
+++ voyage-current/usr/local/sbin/voyage.update	2009-09-22 15:20:45.000000000 +0200
@@ -20,12 +20,21 @@
 # select-profile is a separate script but usually needed
 source $EXECDIR/select-profile.sh
 
-# now ask what the user wants to do
-OPTIONS="Create new Voyage Linux disk%Update existing Voyage configuration%Exit"
-ask_setting "What would you like to do?" "$OPTIONS" 1
+case "$1" in
+	-i) v=1
+		shift
+		;;
+	-u) v=2
+		shift
+		;;
+	*) # now ask what the user wants to do
+		OPTIONS="1:Create new Voyage Linux disk:%2:Update existing Voyage configuration:%3:Exit:"
+		ask_setting "What would you like to do?" "$OPTIONS" 1
+		;;
+esac
 
 case $v in
-	1) $EXECDIR/voyage-install.sh;;
+	1) $EXECDIR/voyage-install.sh "$@";;
 	2) $EXECDIR/voyage-update.sh;;
 	*) err_quit "No action taken";;
 esac
--- voyage-current/usr/local/sbin/voyage-install.sh-x	2009-09-21 18:08:14.000000000 +0200
+++ voyage-current/usr/local/sbin/voyage-install.sh	2009-09-22 16:25:39.000000000 +0200
@@ -223,12 +223,14 @@
 EOM
 	fi
 
-	read_response "\nOK to continue (y/n)? " a
-	if [ "$a" == "Y" ]; then
-		a="y"
-	fi
-	if [ "$a" != "y" ]; then
-		return
+	if [ "$1" != "run" ]; then 
+		read_response "\nOK to continue (y/n)? " a
+		if [ "$a" == "Y" ]; then
+			a="y"
+		fi
+		if [ "$a" != "y" ]; then
+			return
+		fi
 	fi
 
 	echo "Ready to go ...." >&2
@@ -266,6 +268,94 @@
 VOYAGE_SYSTEM_SERIAL=38400
 VOYAGE_SYSTEM_CONSOLE=serial
 
+run_dialog=1
+
+usage () {
+	cat << EOF
+usage: $0 [options]
+		-i  install voyage linux  default=ask
+		-u  update  voyage linux  default=ask
+		-P  VOYAGE_PROFILE        default=$VOYAGE_PROFILE
+		-t  TARGET_DISK           default=$TARGET_DISK
+		-p  TARGET_PART           default=$TARGET_PART
+		-m  TARGET_MOUNT          default=$TARGET_MOUNT
+		-b  BOOTSTRAP_PART        default=$BOOTSTRAP_PART
+		-g  SYSTEM_BOOTSTRAP=grub default=$SYSTEM_BOOTSTRAP
+		-l  SYSTEM_BOOTSTRAP=lilo default=$SYSTEM_BOOTSTRAP
+		-s  VOYAGE_SYSTEM_SERIAL  default=$VOYAGE_SYSTEM_SERIAL
+		-c  VOYAGE_SYSTEM_CONSOLE default=$VOYAGE_SYSTEM_CONSOLE
+		-d  DISTDIR               default=$DISTDIR
+EOF
+}
+
+doopt () {
+	# Variable usage:
+	# x       actual command line element being evaluated
+	# BITMAP  a bit vector to collect if all parameters are set
+	# CLA_*   variables corresponding to teh configuration variables
+	# 
+	# output: $run_dialog $CLA_*
+
+	local x
+	local BITMAP
+	BITMAP=0
+	while [ $# -gt 0 ]; do
+		x="$1"; shift
+	
+		case "$x" in
+		-P) CLA_VOYAGE_PROFILE="$1"
+			BITMAP=$[ $BITMAP | 1 ]
+		    shift
+			;;
+		-t) CLA_TARGET_DISK="$1"
+			BITMAP=$[ $BITMAP | 2 ]
+		    shift
+			;;
+		-p) CLA_TARGET_PART="$1"
+			BITMAP=$[ $BITMAP | 4 ]
+		    shift
+			;;
+		-m) CLA_TARGET_MOUNT="$1"
+			BITMAP=$[ $BITMAP | 8 ]
+		    shift
+			;;
+		-b) CLA_BOOTSTRAP_PART="$1"
+			BITMAP=$[ $BITMAP | 16 ]
+		    shift
+			;;
+		-g) CLA_SYSTEM_BOOTSTRAP="grub"
+			BITMAP=$[ $BITMAP | 32 ]
+			;;
+		-l) CLA_SYSTEM_BOOTSTRAP="lilo"
+			BITMAP=$[ $BITMAP | 32 ]
+			;;
+		-s) CLA_VOYAGE_SYSTEM_SERIAL="$1"
+			BITMAP=$[ $BITMAP | 64 ]
+		    shift
+			;;
+		-c) CLA_VOYAGE_SYSTEM_CONSOLE="$1"
+			BITMAP=$[ $BITMAP | 128 ]
+		    shift
+			;;
+		-d) CLA_DISTDIR="$1"
+			BITMAP=$[ $BITMAP | 256 ]
+		    shift
+			;;
+		*)  usage
+			exit 1
+			;;
+		esac
+	done
+	if [ $BITMAP != 511 ]; then
+		echo "some mandatory options are unset, please enter them interactively"
+		run_dialog=1
+	else 
+		run_dialog=0
+	fi
+}
+
+doopt "$@"
+
 # The logic here is a little confusing.  Basically, we may or may
 # not have a stored $CONFIGFILE [.voyage-install.conf] which
 # contains data saved from previous invocations.  If we do have it,
@@ -302,35 +392,56 @@
 # assure the profile is saved in the user's saved defaults
 save_config_var VOYAGE_PROFILE CONFIGLIST
 
-# here we define the different choices which can be made by the user
-OPTIONS="Specify Distribution Directory%Select Target Profile%Select Target Disk%Select Target Bootstrap Loader%Configure Target Console%Copy Distribution to Target%Exit"
-opt=1
-while true
-do
-    opt=$((opt + 1))
-    if [ $opt -ge 7 ] ; then opt=7 ; fi
-    
-    # Work starts here.  The default is set to "2" at first
-    #ask_setting "What would you like to do?" "$OPTIONS" 7
-    ask_setting "What would you like to do?" "$OPTIONS" $opt
-    opt=$v
-	case $v in
-		1) ask_work_dir $DISTDIR "distribution";
-		   DISTDIR=$w;;
-		2) select-profile $DISTDIR;
-		   if [ -z $w ]; then
-		   	err_msg "Check Distribution Directory setting!\n\n";
-		   fi;;
-		3) select_target_disk;;
-		4) select_target_boot;;
-		5) select_target_console;;
-		6) confirm_copy_details;;
-		7) break;;
-		*) err_quit "Invalid return code from ask_setting";;
-	esac
-done
-
-write_config $CONFIGFILE "$CONFIGLIST"
+# command line parameters are not supposed to overwrite the config 
+# file on disk. so they go here
+[ ! -z "$CLA_VOYAGE_PROFILE"        ] && VOYAGE_PROFILE="$CLA_VOYAGE_PROFILE"               
+[ ! -z "$CLA_TARGET_DISK"           ] && TARGET_DISK="$CLA_TARGET_DISK"                      
+[ ! -z "$CLA_TARGET_PART"           ] && TARGET_PART="$CLA_TARGET_PART"                      
+[ ! -z "$CLA_TARGET_MOUNT"          ] && TARGET_MOUNT="$CLA_TARGET_MOUNT"                      
+[ ! -z "$CLA_BOOTSTRAP_PART"        ] && BOOTSTRAP_PART="$CLA_BOOTSTRAP_PART"                      
+[ ! -z "$CLA_SYSTEM_BOOTSTRAP"      ] && SYSTEM_BOOTSTRAP="$CLA_SYSTEM_BOOTSTRAP"                      
+[ ! -z "$CLA_VOYAGE_SYSTEM_SERIAL"  ] && VOYAGE_SYSTEM_SERIAL="$CLA_VOYAGE_SYSTEM_SERIAL"                      
+[ ! -z "$CLA_VOYAGE_SYSTEM_CONSOLE" ] && VOYAGE_SYSTEM_CONSOLE="$CLA_VOYAGE_SYSTEM_CONSOLE"                      
+[ ! -z "$CLA_DISTDIR"               ] && DISTDIR="$CLA_DISTDIR"                             
+
+if [ "$run_dialog" = 1 ]; then 
+
+	# here we define the different choices which can be made by the user
+	# OPTIONS-Format: option "%" option "%" option
+	# option-Format:  number ":" description ":" preset (here: by command line)
+	OPTIONS="1:Specify Distribution Directory:$CLA_DISTDIR%2:Select Target Profile:$CLA_VOYAGE_PROFILE%3:Select Target Disk:$CLA_TARGET_DISK%4:Select Target Bootstrap Loader:$CLA_SYSTEM_BOOTSTRAP%5:Configure Target Console:$CLA_VOYAGE_SYSTEM_CONSOLE%6:Copy Distribution to Target:1%7:Exit:1%0:Test:1"
+	
+	opt=1
+	while true
+	do
+	    opt=$((opt + 1))
+	    if [ $opt -ge 7 ] ; then opt=7 ; fi
+	    
+	    # Work starts here.  The default is set to "2" at first
+	    #ask_setting "What would you like to do?" "$OPTIONS" 7
+	    ask_setting "What would you like to do?" "$OPTIONS" $opt
+	    opt=$v
+		case $v in
+			1) ask_work_dir $DISTDIR "distribution";
+			   DISTDIR=$w;;
+			2) select-profile $DISTDIR;
+			   if [ -z $w ]; then
+			   	err_msg "Check Distribution Directory setting!\n\n";
+			   fi;;
+			3) select_target_disk;;
+			4) select_target_boot;;
+			5) select_target_console;;
+			6) confirm_copy_details;;
+			7) break;;
+			*) err_quit "Invalid return code from ask_setting";;
+		esac
+	done
+	
+	write_config $CONFIGFILE "$CONFIGLIST"
+
+	# Just for testing we write out the results to a local file
+	write_config "test.conf" "$VOYAGE_CONF_LIST"
+else 
+	confirm_copy_details run
+fi
 
-# Just for testing we write out the results to a local file
-write_config "test.conf" "$VOYAGE_CONF_LIST"
--- voyage-current/usr/local/sbin/script-utils.sh-x	2009-07-13 05:22:16.000000000 +0200
+++ voyage-current/usr/local/sbin/script-utils.sh	2009-09-22 16:18:28.000000000 +0200
@@ -255,6 +255,23 @@
 }
 
 #
+#	Function split_ask_setting_option ()
+#	Params: $1  option consisting of  number ":" description ":" command line argument
+#	Returns: $saso_nr $saso_desc $saso_cla
+#
+split_ask_setting_option () {
+	local saveifs
+	saveifs="$IFS"
+	IFS=':'
+	set -- $1
+
+	saso_nr="$1" 
+	saso_desc="$2"
+	saso_cla="$3"
+
+	IFS="$saveifs"
+}
+#
 #	Function ask_setting()
 #	Params: $1=Question string, $2=Value list, $3=default
 #	Returns: $v set to postion in list (starting from 1)
@@ -270,11 +287,14 @@
 		len=0
 		# Calculate the length of the list, and find the default
 		for ix in $2; do
+			split_ask_setting_option $ix
 			len=$(($len + 1))
 			if [ "$3" -eq "$len" ]; then
-				default=$ix
+				default="$saso_desc"
+			fi
+			if [ -z "$saso_cla" ]; then
+				echo "  $saso_nr - $saso_desc" >&2
 			fi
-			echo "  $len - $ix" >&2
 		done
 		read_response "       (default=$3 [$default]): " v
 		v=${v:-$3}
voyage.update : 
        added support for "-i" (install) and "-u" (update) command line options

        changed $OPTIONS to reflect the modified behaviour of ask_setting()

script-utils.sh : 
        changed format of the OPTIONS variable in ask_setting()

        now there are two layers cascaded:
        the options separated by "%" (as they used to be) 
        are now divided by ":" into a number displayed on the dialog menue,
        the discriptive text and a flag string indicating if the
        option should be displayed at all

        the separation of the individual "option" is done by 
        split_ask_setting_option() which returns $saso_nr, $saso_desc, $saso_cla

voyage-install.sh :
        added usage() for displaying help

        added doopt() as command line interpreter
        changed $OPTIONS to reflect the modified behaviour of ask_setting()

_______________________________________________
Voyage-linux mailing list
[email protected]
http://list.voyage.hk/mailman/listinfo/voyage-linux

Reply via email to