2 # main autocluster script
4 # Copyright (C) Andrew Tridgell 2008
5 # Copyright (C) Martin Schwenke 2008
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, see <http://www.gnu.org/licenses/>.
20 ##BEGIN-INSTALLDIR-MAGIC##
21 # There are better ways of doing this but not if you still want to be
22 # able to run straight out of a git tree. :-)
26 autocluster=$(which "$0")
28 if [ -L "$autocluster" ] ; then
29 autocluster=$(readlink "$autocluster")
31 installdir=$(dirname "$autocluster")
32 ##END-INSTALLDIR-MAGIC##
39 Usage: autocluster [OPTION] ... <COMMAND>
41 -c <file> specify config file (default is "config")
42 -e <expr> execute <expr> and exit
43 -E <expr> execute <expr> and continue
44 -x enable script debugging
45 --dump dump config settings and exit
47 configuration options:
58 create cluster CLUSTERNAME
61 create node CLUSTERNAME IP_OFFSET
62 (re)create a single cluster node
65 mount a qemu disk on mnt/
68 unmount a qemu disk from mnt/
79 ###############################
82 fill_text 0 "ERROR: $*" >&2
86 ###############################
88 # Indirectly call a function named by ${1}_${2}
90 local func="$1" ; shift
91 local type="$1" ; shift
93 local f="${func}_${type}"
94 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
98 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
101 die "No function defined for \"${func}\" \"${type}\""
106 # Note that this will work if you pass "call_func f" because the first
107 # element of the node tuple is the node type. Nice... :-)
112 "$@" $(IFS=: ; echo $n)
116 hack_one_node_with ()
118 local filter="$1" ; shift
127 local item="${node_type}:${ip_offset}${name:+:}${name}${ctdb_node:+:}${ctdb_node}"
128 nodes="${nodes}${nodes:+ }${item}"
131 # This also gets used for non-filtering iteration.
132 hack_all_nodes_with ()
137 for_each_node hack_one_node_with "$filter"
146 eval "$hook_var=\"${!hook_var}${!hook_var:+ }${new_hook}\""
154 for i in ${!hook_var} ; do
159 # Use with care, since this may clear some autocluster defaults.!
164 eval "$hook_var=\"\""
167 ##############################
169 # common node creation stuff
170 create_node_COMMON ()
175 local template_file="${4:-$NODE_TEMPLATE}"
177 if [ "$SYSTEM_DISK_FORMAT" != "qcow2" -a "$BASE_FORMAT" = "qcow2" ] ; then
178 die "Error: if BASE_FORMAT is \"qcow2\" then SYSTEM_DISK_FORMAT must also be \"qcow2\"."
181 IPNUM=$(($FIRSTIP + $ip_offset))
182 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}"
183 local base_disk="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}"
185 if [ "$BASE_PER_NODE_TYPE" = "yes" ] ; then
186 base_disk="${VIRTBASE}/${BASENAME}-${type}.${BASE_FORMAT}"
189 mkdir -p $VIRTBASE/$CLUSTER tmp
192 if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then
193 di=$(readlink "$DISK")
196 case "$SYSTEM_DISK_FORMAT" in
198 echo "Creating the disk..."
199 qemu-img create -b "$base_disk" -f qcow2 "$di"
200 create_node_configure_image "$DISK" "$type"
203 echo "Creating the disk..."
204 cp -v --sparse=always "$base_disk" "$di"
205 create_node_configure_image "$DISK" "$type"
208 echo "Creating the disk..."
209 cp -v --reflink=always "$base_disk" "$di"
210 create_node_configure_image "$DISK" "$type"
213 echo "Creating the disk (using mmclone)..."
214 local base_snap="${base_disk}.snap"
215 [ -f "$base_snap" ] || mmclone snap "$base_disk" "$base_snap"
216 mmclone copy "$base_snap" "$di"
217 create_node_configure_image "$DISK" "$type"
220 echo "Skipping disk image creation as requested"
223 die "Error: unknown SYSTEM_DISK_FORMAT=\"${SYSTEM_DISK_FORMAT}\"."
226 set_macaddrs $CLUSTER $ip_offset
228 # Pull the UUID for this node out of the map.
229 UUID=$(awk "\$1 == $ip_offset {print \$2}" $uuid_map)
231 echo "Creating $NAME.xml"
232 substitute_vars $template_file tmp/$NAME.xml
234 # install the XML file
235 $VIRSH undefine $NAME > /dev/null 2>&1 || true
236 $VIRSH define tmp/$NAME.xml
239 create_node_configure_image ()
244 diskimage mount "$disk"
249 # Provides an easy way of removing nodes from $NODE.
250 create_node_null () {
254 ##############################
256 hack_nodes_functions=
259 # Expand out any abbreviations in NODES.
268 for i in ${ips//,/ } ; do
269 ns="${ns}${ns:+ }${t}:${i}"
274 for i in $(seq ${ips/-/ }) ; do
275 ns="${ns}${ns:+ }${t}:${i}"
279 ns="${ns}${ns:+ }${n}"
284 # Apply nodes hacks. Some of this is about backward compatibility
285 # but the hacks also fill in the node names and whether they're
286 # part of the CTDB cluster. The order is the order that
287 # configuration modules register their hacks.
288 run_hooks hack_nodes_functions
290 if [ -n "$NUMNODES" ] ; then
291 # Attempt to respect NUMNODES. Reduce the number of CTDB
293 local numnodes=$NUMNODES
297 if [ "$ctdb_node" = 1 ] ; then
298 if [ $numnodes -gt 0 ] ; then
299 numnodes=$(($numnodes - 1))
307 hack_all_nodes_with hack_filter
309 [ $numnodes -gt 0 ] && \
310 die "Can't not use NUMNODES to increase the number of nodes over that specified by NODES. You need to set NODES instead - please read the documentation."
313 # Check IP addresses for duplicates.
315 # This function doesn't modify anything...
318 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
319 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
320 ip_offsets="${ip_offsets}${ip_offset}:"
322 hack_all_nodes_with get_ip_offset
325 ##############################
327 sanity_check_cluster_name ()
329 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
330 die "Cluster names should be restricted to the characters A-Za-z0-9. \
331 Some cluster filesystems have problems with other characters."
336 common_nodelist_hacking ()
338 # Rework the NODES list
341 # Build /etc/hosts and hack the names of the ctdb nodes
342 hosts_line_hack_name ()
344 # Ignore nodes without names (e.g. "null")
345 [ "$node_type" != "null" -a -n "$name" ] || return 0
349 local ip_addr="$IPBASE.$IPNET0.$(($FIRSTIP + $ip_offset))"
351 if [ "$ctdb_node" = 1 ] ; then
352 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
353 sname="${CLUSTER}n${num_ctdb_nodes}"
354 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
357 hosts_line="$ip_addr ${name}.${ld} $name"
360 # This allows you to add a function to your configuration file
361 # to modify hostnames (and other aspects of nodes). This
362 # function can access/modify $name (the existing name),
363 # $node_type and $ctdb_node (1, if the node is a member of the
364 # CTDB cluster, 0 otherwise).
365 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
366 local old_name="$name"
367 $HOSTNAME_HACKING_FUNCTION
368 if [ "$name" != "$old_name" ] ; then
369 hosts_line="$ip_addr ${name}.${ld} $name"
375 hosts_file="tmp/hosts.$CLUSTER"
377 local num_ctdb_nodes=0
378 local ld=$(echo $DOMAIN | tr A-Z a-z)
379 echo "# autocluster $CLUSTER"
380 hack_all_nodes_with hosts_line_hack_name
384 # Build /etc/ctdb/nodes
387 [ "$ctdb_node" = 1 ] || return 0
388 echo "$IPBASE.$IPNET0.$(($FIRSTIP + $ip_offset))"
389 num_nodes=$(($num_nodes + 1))
391 nodes_file="tmp/nodes.$CLUSTER"
393 hack_all_nodes_with ctdb_nodes_line >$nodes_file
394 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
397 uuid_map="tmp/uuid_map.$CLUSTER"
400 echo "${ip_offset} $(uuidgen) ${node_type}"
402 hack_all_nodes_with uuid_map_line >$uuid_map
405 create_cluster_hooks=
406 cluster_created_hooks=
412 sanity_check_cluster_name
414 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
416 # Run hooks before doing anything else.
417 run_hooks create_cluster_hooks
419 common_nodelist_hacking
421 for_each_node call_func create_node
423 echo "Cluster $CLUSTER created"
426 run_hooks cluster_created_hooks
429 cluster_created_hosts_message ()
431 echo "You may want to add this to your /etc/hosts file:"
435 register_hook cluster_created_hooks cluster_created_hosts_message
440 local single_node_ip_offset="$2"
442 sanity_check_cluster_name
444 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
446 common_nodelist_hacking
449 set -- $(IFS=: ; echo $n)
450 [ $single_node_ip_offset -eq $2 ] || continue
451 call_func create_node "$@"
453 echo "Requested node created"
455 echo "You may want to update your /etc/hosts file:"
462 ###############################
463 # test the proxy setup
465 export http_proxy=$WEBPROXY
466 wget -O /dev/null $INSTALL_SERVER || \
467 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
473 kickstart_floppy_create_hooks=
479 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
483 echo "Testing WEBPROXY $WEBPROXY"
487 if [ "$DISK_FOLLOW_SYMLINKS" = "yes" -a -L "$DISK" ] ; then
488 di=$(readlink "$DISK")
491 echo "Creating the disk"
492 qemu-img create -f $BASE_FORMAT "$di" $DISKSIZE
495 mkdir -p mnt tmp tmp/ISO
499 echo "Creating kickstart file from template"
500 substitute_vars "$KICKSTART" "tmp/ks.cfg"
502 if [ $INSTALLKEY = "--skip" ]; then
504 --------------------------------------------------------------------------------------
505 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
507 Please enter a valid RHEL install key in your config file like this:
509 INSTALLKEY="1234-5678-0123-4567"
511 The install will continue without an install key in 5 seconds
512 --------------------------------------------------------------------------------------
517 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
520 (*) ISO="${ISO_DIR}/${ISO}"
523 echo "Creating kickstart floppy"
524 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
525 mkdosfs tmp/floppy.img
526 mount -o loop -t msdos tmp/floppy.img mnt
528 mount -o loop,ro $ISO tmp/ISO
530 echo "Setting up bootloader"
531 cp tmp/ISO/isolinux/isolinux.bin tmp
532 cp tmp/ISO/isolinux/vmlinuz tmp
533 cp tmp/ISO/isolinux/initrd.img tmp
535 run_hooks kickstart_floppy_create_hooks
542 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
544 rm -f $KVMLOG/serial.$NAME
546 # boot the install CD
547 $VIRSH create tmp/$NAME.xml
549 echo "Waiting for install to start"
552 # wait for the install to finish
553 if ! waitfor $KVMLOG/serial.$NAME "$KS_DONE_MESSAGE" $CREATE_BASE_TIMEOUT ; then
555 die "Failed to create base image ${DISK} after waiting for ${CREATE_BASE_TIMEOUT} seconds.
556 You may need to increase the value of CREATE_BASE_TIMEOUT.
557 Alternatively, the install might have completed but KS_DONE_MESSAGE
558 (currently \"${KS_DONE_MESSAGE}\")
559 may not have matched anything at the end of the kickstart output."
567 Install finished, base image $DISK created
571 To ensure that this image does not change
573 Note that the root password has been set to $ROOTPASSWORD
578 ###############################
584 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
592 diskimage mount $DISK
598 echo "Creating $NAME.xml"
599 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
601 # boot the base system
602 $VIRSH create tmp/$NAME.xml
605 ######################################################################
607 # various functions...
609 # Set some MAC address variables based on a hash of the cluster name
610 # plus the node number and each adapter number.
615 local md5=$(echo $cname | md5sum)
616 local nh=$(printf "%02x" $ip_offset)
617 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
619 MAC1="${mac_prefix}01"
620 MAC2="${mac_prefix}02"
621 MAC3="${mac_prefix}03"
622 MAC4="${mac_prefix}04"
623 MAC5="${mac_prefix}05"
624 MAC6="${mac_prefix}06"
627 ######################################################################
629 # Updating a disk image...
635 call_func diskimage_"$func" "$SYSTEM_DISK_ACCESS_METHOD" "$@"
638 # setup the files from $BASE_TEMPLATES/, substituting any variables
639 # based on the config
640 copy_base_dir_substitute_templates ()
644 local d="$BASE_TEMPLATES/$dir"
645 [ -d "$d" ] || return 0
648 for f in $(cd "$d" && find . \! -name '*~' \( -type d -name .svn -prune -o -print \) ) ; do
649 f="${f#./}" # remove leading "./" for clarity
650 if [ -d "$d/$f" ]; then
651 # Don't chmod existing directory
652 if diskimage is_directory "/$f" ; then
655 diskimage mkdir_p "/$f"
658 diskimage substitute_vars "$d/$f" "/$f"
660 diskimage chmod_reference "$d/$f" "/$f"
666 setup_base_ssh_keys ()
668 # this is needed as git doesn't store file permissions other
670 # Note that we protect the wildcards from the local shell.
671 diskimage chmod 600 "/etc/ssh/*key" "/root/.ssh/*"
672 diskimage chmod 700 "/etc/ssh" "/root/.ssh" "/root"
673 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
674 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
675 diskimage append_text_file "$HOME/.ssh/id_rsa.pub" "/root/.ssh/authorized_keys"
677 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
678 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
679 diskimage append_text_file "$HOME/.ssh/id_dsa.pub" "/root/.ssh/authorized_keys"
683 register_hook setup_base_hooks setup_base_ssh_keys
685 setup_base_grub_conf ()
687 echo "Adjusting grub.conf"
688 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
689 diskimage sed "/boot/grub/grub.conf" \
690 -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
691 -e "s/ nodmraid//" -e "s/ nompath//" \
692 -e "s/quiet/noapic divider=10${o:+ }${o}/g"
695 register_hook setup_base_hooks setup_base_grub_conf
702 echo "Copy base files"
703 copy_base_dir_substitute_templates "all"
704 if [ -n "$type" ] ; then
705 copy_base_dir_substitute_templates "$type"
708 run_hooks setup_base_hooks
711 # setup various networking components
714 # This avoids doing anything when we're called from boot_base().
715 if [ -z "$hosts_file" ] ; then
716 echo "Skipping network-related setup"
720 echo "Setting up networks"
721 diskimage append_text_file "$hosts_file" "/etc/hosts"
723 echo "Setting up /etc/ctdb/nodes"
724 diskimage mkdir_p "/etc/ctdb"
725 diskimage put "$nodes_file" "/etc/ctdb/nodes"
727 [ "$WEBPROXY" = "" ] || {
728 diskimage append_text "export http_proxy=$WEBPROXY" "/etc/bashrc"
731 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
732 echo "Enabling nfs mount of $NFSSHARE"
733 diskimage mkdir_p "$NFS_MOUNTPOINT"
734 diskimage append_text "$NFSSHARE $NFS_MOUNTPOINT nfs nfsvers=3,intr 0 0" "/etc/fstab"
737 diskimage mkdir_p "/etc/yum.repos.d"
738 echo '@@@YUM_TEMPLATE@@@' | diskimage substitute_vars - "/etc/yum.repos.d/autocluster.repo"
740 diskimage rm_f "/etc/udev/rules.d/70-persistent-net.rules"
743 register_hook setup_base_hooks setup_network
746 [ -z "$TIMEZONE" ] && {
747 [ -r /etc/timezone ] && {
748 TIMEZONE=`cat /etc/timezone`
750 [ -r /etc/sysconfig/clock ] && {
751 . /etc/sysconfig/clock
754 TIMEZONE="${TIMEZONE// /_}"
756 [ -n "$TIMEZONE" ] || \
757 die "Unable to determine TIMEZONE - please set in config"
760 # substite a set of variables of the form @@XX@@ for the shell
761 # variables $XX in a file.
763 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
764 # contain a filename whose contents are substituted, with variable
765 # substitution applied to those contents. If filename starts with '|'
766 # it is a command instead - however, quoting is extremely fragile.
768 infile="${1:-/dev/null}" # if empty then default to /dev/null
769 outfile="$2" # optional
772 cat "$infile" >"$tmp_out"
774 # Handle any indirects by looping until nothing changes.
775 # However, only handle 10 levels of recursion.
778 if ! _substitute_vars "$tmp_out" "@@@" ; then
780 die "Failed to expand template $infile"
783 # No old version of file means no changes made.
784 if [ ! -f "${tmp_out}.old" ] ; then
788 rm -f "${tmp_out}.old"
790 count=$(($count + 1))
791 if [ $count -ge 10 ] ; then
793 die "Recursion too deep in $infile - only 10 levels allowed!"
797 # Now regular variables.
798 if ! _substitute_vars "$tmp_out" "@@" ; then
800 die "Failed to expand template $infile"
802 rm -f "${tmp_out}.old"
804 if [ -n "$outfile" ] ; then
805 mv "$tmp_out" "$outfile"
813 # Delimiter @@ means to substitute contents of variable.
814 # Delimiter @@@ means to substitute contents of file named by variable.
815 # @@@ supports leading '|' in variable value, which means to excute a
817 _substitute_vars() {(
821 # Get the list of variables used in the template. The grep
822 # gets rid of any blank lines and lines with extraneous '@'s
823 # next to template substitutions.
824 VARS=$(sed -n -e "s#[^@]*${delimiter}\([A-Z0-9_][A-Z0-9_]*\)${delimiter}[^@]*#\1\n#gp" "$tmp_out" |
825 grep '^[A-Z0-9_][A-Z0-9_]*$' |
830 # variable variables are fun .....
833 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
837 if [ "$delimiter" = "@@@" ] ; then
839 c="${f#|}" # Is is a command, signified by a leading '|'?
840 if [ "$c" = "$f" ] ; then
841 # No leading '|', cat file.
845 die "Could not substitute contents of file $f"
848 # Leading '|', execute command.
849 # Quoting problems here - using eval "$c" doesn't help.
853 die "Could not execute command $c"
858 # escape some pesky chars
859 # This first one can be too slow if done using a bash
860 # variable pattern subsitution.
861 s=$(echo -n "$s" | tr '\n' '\001' | sed -e 's/\o001/\\n/g')
864 echo "s#${delimiter}${v}${delimiter}#${s}#g"
867 # Get the in-place sed to make a backup of the old file.
868 # Remove the backup if it is the same as the resulting file -
869 # this acts as a flag to the caller that no changes were made.
870 sed -i.old -f $tmp "$tmp_out"
871 if cmp -s "${tmp_out}.old" "$tmp_out" ; then
872 rm -f "${tmp_out}.old"
879 which $1 > /dev/null || die "Please install $1 to continue"
882 # Set a variable if it isn't already set. This allows environment
883 # variables to override default config settings.
888 [ "${!v+x}" ] || eval "$v=\"$e\""
894 for i in "${installdir}/config.d/"*.defconf ; do
899 # Print the list of config variables defined in config.d/.
900 get_config_options () {( # sub-shell for local declaration of defconf()
902 defconf() { options="$options $1" ; }
907 # Produce a list of long options, suitable for use with getopt, that
908 # represent the config variables defined in config.d/.
909 getopt_config_options () {
910 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
914 # Unconditionally set the config variable associated with the given
920 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
921 # unset so defconf will set it
926 # Dump all of the current config variables.
929 for o in $(get_config_options) ; do
930 echo "${o}=\"${!o}\""
935 # $COLUMNS is set in interactive bash shells. It probably isn't set
936 # in this shell, so let's set it if it isn't.
937 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
941 # Print text assuming it starts after other text in $startcol and
942 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
943 # Long "words" will extend past $COLUMNS - 2.
948 local width=$(($COLUMNS - 2 - $startcol))
949 [ $width -lt 0 ] && width=$((78 - $startcol))
954 if [ $startcol -gt 0 ] ; then
955 padding=$(printf "\n%${startcol}s" " ")
961 while [ -n "$text" ] ; do
964 # If we already have output then arrange padding on the next line.
965 [ -n "$out" ] && out="${out}${padding}"
967 # Break the text at $width.
968 out="${out}${text:0:${width}}"
969 text="${text:${width}}"
971 # If we have left over text then the line break may be ugly,
972 # so let's check and try to break it on a space.
973 if [ -n "$text" ] ; then
974 # The 'x's stop us producing a special character like '(',
975 # ')' or '!'. Yuck - there must be a better way.
976 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
977 # We didn't break on a space. Arrange for the
978 # beginning of the broken "word" to appear on the next
979 # line but not if it will make us loop infinitely.
980 if [ "${orig}" != "${out##* }${text}" ] ; then
981 text="${out##* }${text}"
984 # Hmmm, doing that would make us loop, so add the
985 # rest of the word from the remainder of the text
986 # to this line and let it extend past $COLUMNS - 2.
987 out="${out}${text%% *}"
988 if [ "${text# *}" != "$text" ] ; then
989 # Remember the text after the next space for next time.
992 # No text after next space.
997 # We broke on a space. If it will be at the beginning
998 # of the next line then remove it.
1007 # Display usage text, trying these approaches in order.
1008 # 1. See if it all fits on one line before $COLUMNS - 2.
1009 # 2. See if splitting before the default value and indenting it
1010 # to $startcol means that nothing passes $COLUMNS - 2.
1011 # 3. Treat the message and default value as a string and just us fill_text()
1013 usage_display_text () {
1018 local width=$(($COLUMNS - 2 - $startcol))
1019 [ $width -lt 0 ] && width=$((78 - $startcol))
1021 default="(default \"$default\")"
1023 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
1024 echo "${desc} ${default}"
1026 local padding=$(printf "%${startcol}s" " ")
1028 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
1030 echo "${padding}${default}"
1032 fill_text $startcol "${desc} ${default}"
1037 # Display usage information for long config options.
1038 usage_smart_display () {( # sub-shell for local declaration of defconf()
1042 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
1044 printf " --%-25s " "${longopt}=${3}"
1046 usage_display_text $startcol "$4" "$2"
1053 # Display usage information for long config options.
1054 usage_config_options (){
1055 usage_smart_display load_config
1059 local releases=$(cd $installdir/releases && echo *.release)
1060 releases="${releases//.release}"
1061 releases="${releases// /\", \"}"
1062 echo "\"$releases\""
1065 has_public_addresses_DEFAULT ()
1070 make_public_addresses() {
1071 local firstip="${1:-$[${FIRSTIP} + ${PUBLIC_IP_OFFSET}]}"
1072 local num_addrs="${2:-${NUMNODES}}"
1074 if [ $(( $firstip + $num_addrs - 1 )) -gt 254 ]; then
1075 die "make_public_addresses: last octet > 254 - change PUBLIC_IP_OFFSET"
1079 for e in $IPNET1 $IPNET2 ; do
1080 echo -ne "${IPBASE}.${e}.${firstip},${num_addrs},eth${e} "
1085 ######################################################################
1089 ######################################################################
1093 ############################
1094 # parse command line options
1095 long_opts=$(getopt_config_options)
1096 getopt_output=$(getopt -n autocluster -o "c:e:E:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1097 [ $? != 0 ] && usage
1099 use_default_config=true
1101 # We do 2 passes of the options. The first time we just handle usage
1102 # and check whether -c is being used.
1103 eval set -- "$getopt_output"
1106 -c) shift 2 ; use_default_config=false ;;
1109 --) shift ; break ;;
1110 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1112 -h|--help) usage ;; # Usage should be shown here for real defaults.
1113 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1114 *) usage ;; # shouldn't happen, so this is reasonable.
1119 $use_default_config && [ -r "$config" ] && . "$config"
1121 eval set -- "$getopt_output"
1125 # force at least ./local_file to avoid accidental file from $PATH
1126 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1127 -e) run_hooks post_config_hooks ; eval "$2" ; exit ;;
1128 -E) eval "$2" ; shift 2 ;;
1129 -x) set -x; shift ;;
1130 --dump) run_hooks post_config_hooks ; dump_config ;;
1131 --) shift ; break ;;
1132 -h|--help) usage ;; # Redundant.
1134 # Putting --opt1|opt2|... into a variable and having case
1135 # match against it as a pattern doesn't work. The | is
1136 # part of shell syntax, so we need to do this. Look away
1137 # now to stop your eyes from bleeding! :-)
1138 x=",${long_opts}" # Now each option is surrounded by , and :
1139 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1140 # Our option, $1, surrounded by , and : was in $x, so is legal.
1141 setconf_longopt "$1" "$2"; shift 2
1146 *) usage ;; # shouldn't happen, so this is reasonable.
1150 run_hooks post_config_hooks
1156 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1159 # check for needed programs
1160 check_command expect
1162 [ $# -lt 1 ] && usage
1173 [ $# != 0 ] && usage
1177 [ $# != 1 ] && usage
1181 [ $# != 2 ] && usage
1182 create_one_node "$1" "$2"
1190 [ $# != 1 ] && usage
1191 diskimage mount "$1"
1194 [ $# != 0 ] && usage