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. :-)
24 installdir="`dirname \"$0\"`"
26 autocluster=`which $0`
27 installdir="`dirname \"$autocluster\"`"
29 ##END-INSTALLDIR-MAGIC##
36 Usage: autocluster [OPTION] ... <COMMAND>
38 -c <file> specify config file (default is "config")
41 releases=$(list_releases)
44 defconf "WITH_RELEASE" "" \
45 "<string>" "specify preset options for a release using a version string. Possible values are: ${releases}."
48 -e <expr> execute <expr> and exit (advanced debugging)
49 -x enable script debugging
50 --dump dump config settings and exit
52 configuration options:
63 create cluster CLUSTERNAME
66 create node CLUSTERNAME IP_OFFSET
67 (re)create a single cluster node
70 mount a qemu disk on mnt/
73 unmount a qemu disk from mnt/
84 ###############################
87 fill_text 0 "ERROR: $*" >&2
91 ###############################
93 # Indirectly call a function named by ${1}_${2}
95 local func="$1" ; shift
96 local type="$1" ; shift
98 local f="${func}_${type}"
99 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
103 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
106 die "No function defined for \"${func}\" \"${type}\""
111 # Note that this will work if you pass "call_func f" because the first
112 # element of the node tuple is the node type. Nice... :-)
117 "$@" $(IFS=: ; echo $n)
121 hack_one_node_with ()
123 local filter="$1" ; shift
132 local item="${node_type}:${ip_offset}${name:+:}${name}${ctdb_node:+:}${ctdb_node}"
133 nodes="${nodes}${nodes:+ }${item}"
136 # This also gets used for non-filtering iteration.
137 hack_all_nodes_with ()
142 for_each_node hack_one_node_with "$filter"
151 eval "$hook_var=\"${!hook_var}${!hook_var:+ }${new_hook}\""
159 for i in ${!hook_var} ; do
164 ##############################
166 # common node creation stuff
167 create_node_COMMON ()
172 local template_file="${4:-$NODE_TEMPLATE}"
174 IPNUM=$(($FIRSTIP + $ip_offset))
175 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.qcow2"
177 mkdir -p $VIRTBASE/$CLUSTER tmp
179 echo "Creating the disk"
181 qemu-img create -b "$VIRTBASE/$BASENAME.img" -f qcow2 "$DISK"
188 set_macaddrs $CLUSTER $ip_offset
191 echo "Creating $NAME.xml"
192 substitute_vars $template_file tmp/$NAME.xml
194 # install the XML file
195 $VIRSH undefine $NAME > /dev/null 2>&1 || true
196 $VIRSH define tmp/$NAME.xml
199 # Provides an easy way of removing nodes from $NODE.
200 create_node_null () {
204 ##############################
206 hack_nodes_functions=
208 register_nodes_hack ()
212 hack_nodes_functions="${hack_nodes_functions}${hack_nodes_functions:+ }${hack}"
216 # Expand out any abbreviations in NODES.
225 for i in ${ips//,/ } ; do
226 ns="${ns}${ns:+ }${t}:${i}"
231 for i in $(seq ${ips/-/ }) ; do
232 ns="${ns}${ns:+ }${t}:${i}"
236 ns="${ns}${ns:+ }${n}"
241 # Apply nodes hacks. Some of this is about backward compatibility
242 # but the hacks also fill in the node names and whether they're
243 # part of the CTDB cluster. The order is the order that
244 # configuration modules register their hacks.
245 for n in $hack_nodes_functions ; do
249 if [ -n "$NUMNODES" ] ; then
250 # Attempt to respect NUMNODES. Reduce the number of CTDB
252 local numnodes=$NUMNODES
256 if [ "$ctdb_node" = 1 ] ; then
257 if [ $numnodes -gt 0 ] ; then
258 numnodes=$(($numnodes - 1))
266 hack_all_nodes_with hack_filter
268 [ $numnodes -gt 0 ] && \
269 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."
272 # Check IP addresses for duplicates.
274 # This function doesn't modify anything...
277 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
278 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
279 ip_offsets="${ip_offsets}${ip_offset}:"
281 hack_all_nodes_with get_ip_offset
284 ##############################
286 create_cluster_hooks=
288 register_create_cluster_hook ()
292 create_cluster_hooks="${create_cluster_hooks}${create_cluster_hooks:+ }${hook}"
295 sanity_check_cluster_name ()
297 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
298 die "Cluster names should be restricted to the characters A-Za-z0-9. \
299 Some cluster filesystems have problems with other characters."
302 common_nodelist_hacking ()
304 # Rework the NODES list
307 # Build /etc/hosts and hack the names of the ctdb nodes
308 hosts_line_hack_name ()
310 # Ignore nodes without names (e.g. "null")
311 [ "$node_type" != "null" -a -n "$name" ] || return 0
315 local ip_addr="$IPBASE.0.$(($FIRSTIP + $ip_offset))"
317 if [ "$ctdb_node" = 1 ] ; then
318 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
319 sname="${CLUSTER}n${num_ctdb_nodes}"
320 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
323 hosts_line="$ip_addr ${name}.${ld} $name"
326 # This allows you to add a function to your configuration file
327 # to modify hostnames (and other aspects of nodes). This
328 # function can access/modify $name (the existing name),
329 # $node_type and $ctdb_node (1, if the node is a member of the
330 # CTDB cluster, 0 otherwise).
331 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
332 local old_name="$name"
333 $HOSTNAME_HACKING_FUNCTION
334 if [ "$name" != "$old_name" ] ; then
335 hosts_line="$ip_addr ${name}.${ld} $name"
341 hosts_file="tmp/hosts.$CLUSTER"
343 local num_ctdb_nodes=0
344 local ld=$(echo $DOMAIN | tr A-Z a-z)
345 echo "# autocluster $CLUSTER"
346 hack_all_nodes_with hosts_line_hack_name
350 # Build /etc/ctdb/nodes
353 [ "$ctdb_node" = 1 ] || return 0
354 echo "$IPBASE.0.$(($FIRSTIP + $ip_offset))"
355 num_nodes=$(($num_nodes + 1))
357 nodes_file="tmp/nodes.$CLUSTER"
359 hack_all_nodes_with ctdb_nodes_line >$nodes_file
360 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
367 sanity_check_cluster_name
369 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
371 # Run hooks before doing anything else.
373 for n in $create_cluster_hooks ; do
377 common_nodelist_hacking
379 for_each_node call_func create_node
381 echo "Cluster $CLUSTER created"
382 echo "You may want to add this to your /etc/hosts file:"
389 local single_node_ip_offset="$2"
391 sanity_check_cluster_name
393 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
395 common_nodelist_hacking
398 set -- $(IFS=: ; echo $n)
399 [ $single_node_ip_offset -eq $2 ] || continue
400 call_func create_node "$@"
402 echo "Requested node created"
403 echo "You may want to update your /etc/hosts file:"
410 ###############################
411 # test the proxy setup
413 export http_proxy=$WEBPROXY
414 wget -O /dev/null $INSTALL_SERVER || \
415 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
424 DISK="$VIRTBASE/$NAME.img"
428 echo "Testing WEBPROXY $WEBPROXY"
431 echo "Creating the disk"
432 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
435 mkdir -p mnt tmp tmp/ISO
439 echo "Creating kickstart file from template"
440 substitute_vars "$KICKSTART" "tmp/ks.cfg"
442 if [ $INSTALLKEY = "--skip" ]; then
444 --------------------------------------------------------------------------------------
445 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
447 Please enter a valid RHEL install key in your config file like this:
449 INSTALLKEY="1234-5678-0123-4567"
451 The install will continue without an install key in 5 seconds
452 --------------------------------------------------------------------------------------
457 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
460 (*) ISO="${ISO_DIR}/${ISO}"
463 echo "Creating kickstart floppy"
464 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
465 mkdosfs tmp/floppy.img
466 mount -o loop -t msdos tmp/floppy.img mnt
468 mount -o loop,ro $ISO tmp/ISO
470 echo "Setting up bootloader"
471 cp tmp/ISO/isolinux/isolinux.bin tmp
472 cp tmp/ISO/isolinux/vmlinuz tmp
473 cp tmp/ISO/isolinux/initrd.img tmp
479 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
481 rm -f $KVMLOG/serial.$NAME
483 # boot the install CD
484 $VIRSH create tmp/$NAME.xml
486 echo "Waiting for install to start"
489 # wait for the install to finish
490 if ! waitfor $KVMLOG/serial.$NAME "you may safely reboot your system" $CREATE_BASE_TIMEOUT ; then
492 die "Failed to create base image $DISK"
500 Install finished, base image $DISK created
504 To ensure that this image does not change
506 Note that the root password has been set to $ROOTPASSWORD
511 ###############################
517 DISK="$VIRTBASE/$NAME.img"
531 echo "Creating $NAME.xml"
532 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
534 # boot the base system
535 $VIRSH create tmp/$NAME.xml
538 ######################################################################
540 # various functions...
542 # Set some MAC address variables based on a hash of the cluster name
543 # plus the node number and each adapter number.
548 local md5=$(echo $cname | md5sum)
549 local nh=$(printf "%02x" $ip_offset)
550 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
552 MAC1="${mac_prefix}01"
553 MAC2="${mac_prefix}02"
554 MAC3="${mac_prefix}03"
555 MAC4="${mac_prefix}04"
556 MAC5="${mac_prefix}05"
557 MAC6="${mac_prefix}06"
560 # mount a qemu image via nbd
562 echo "Connecting nbd to $1"
565 killall -9 -q $QEMU_NBD || true
566 $QEMU_NBD -p 1300 $1 &
568 [ -r $NBD_DEVICE ] || {
569 mknod $NBD_DEVICE b 43 0
571 umount mnt 2> /dev/null || true
572 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
573 killall -9 -q nbd-client || true
574 nbd-client localhost 1300 $NBD_DEVICE > /dev/null 2>&1 || true &
580 echo "Disconnecting nbd"
582 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
583 killall -9 -q nbd-client || true
584 killall -q $QEMU_NBD || true
587 # mount a qemu image via nbd
590 echo "Mounting disk $1"
592 for i in `seq 1 5`; do
593 mount -o offset=32256 $NBD_DEVICE mnt && {
597 umount mnt 2>/dev/null || true
600 [ $mount_ok = 1 ] || die "Failed to mount $1"
603 echo "Mounted directory does not look like a root filesystem"
609 # unmount a qemu image
611 echo "Unmounting disk"
613 umount mnt || umount mnt || true
617 # setup the files from $BASE_TEMPLATES/, substituting any variables
618 # based on the config
619 copy_base_dir_substitute_templates ()
623 local d="$BASE_TEMPLATES/$dir"
624 [ -d "$d" ] || return 0
627 for f in $(cd "$d" && find . \! -name '*~') ; do
628 if [ -d "$d/$f" ]; then
631 substitute_vars "$d/$f" "mnt/$f"
633 chmod --reference="$d/$f" "mnt/$f"
639 register_setup_base_hook ()
643 setup_base_hooks="${setup_base_hooks}${setup_base_hooks:+ }${hook}"
651 echo "Copy base files"
652 copy_base_dir_substitute_templates "all"
653 if [ -n "$type" ] ; then
654 copy_base_dir_substitute_templates "$type"
657 # this is needed as git doesn't store file permissions other
659 chmod 600 mnt/etc/ssh/*key mnt/root/.ssh/*
660 chmod 700 mnt/etc/ssh mnt/root/.ssh mnt/root
661 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
662 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
663 cat "$HOME/.ssh/id_rsa.pub" >> mnt/root/.ssh/authorized_keys
665 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
666 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
667 cat "$HOME/.ssh/id_dsa.pub" >> mnt/root/.ssh/authorized_keys
669 echo "Adjusting grub.conf"
670 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
671 sed -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
672 -e "s/ nodmraid//" -e "s/ nompath//" \
673 -e "s/quiet/noapic divider=10${o:+ }${o}/g" mnt/boot/grub/grub.conf -i.org
674 for i in $setup_base_hooks ; do
679 # setup various networking components
681 echo "Setting up networks"
683 cat $hosts_file >>mnt/etc/hosts
685 echo "Setting up /etc/ctdb/nodes"
686 mkdir -p mnt/etc/ctdb
687 cp $nodes_file mnt/etc/ctdb/nodes
689 [ "$WEBPROXY" = "" ] || {
690 echo "export http_proxy=$WEBPROXY" >> mnt/etc/bashrc
693 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
694 echo "Enabling nfs mount of $NFSSHARE"
695 mkdir -p "mnt$NFS_MOUNTPOINT"
696 echo "$NFSSHARE $NFS_MOUNTPOINT nfs intr" >> mnt/etc/fstab
699 mkdir -p mnt/etc/yum.repos.d
700 echo '@@@YUM_TEMPLATE@@@' | substitute_vars - > mnt/etc/yum.repos.d/autocluster.repo
704 [ -z "$TIMEZONE" ] && {
705 [ -r /etc/timezone ] && {
706 TIMEZONE=`cat /etc/timezone`
708 [ -r /etc/sysconfig/clock ] && {
709 . /etc/sysconfig/clock
712 TIMEZONE="${TIMEZONE// /_}"
714 [ -n "$TIMEZONE" ] || \
715 die "Unable to determine TIMEZONE - please set in config"
718 # substite a set of variables of the form @@XX@@ for the shell
719 # variables $XX in a file.
721 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
722 # contain a filename whose contents are substituted, with variable
723 # substitution applied to those contents. If filename starts with '|'
724 # it is a command instead - however, quoting is extremely fragile.
726 infile="${1:-/dev/null}" # if empty then default to /dev/null
727 outfile="$2" # optional
729 instring=$(cat $infile)
731 # Handle any indirects by looping until nothing changes.
732 # However, only handle 10 levels of recursion.
735 outstring=$(_substitute_vars "$instring" "@@@")
736 [ $? -eq 0 ] || die "Failed to expand template $infile"
738 [ "$instring" = "$outstring" ] && break
740 count=$(($count + 1))
741 [ $count -lt 10 ] || \
742 die "Recursion too deep in $infile - only 10 levels allowed!"
744 instring="$outstring"
747 # Now regular variables.
748 outstring=$(_substitute_vars "$instring" "@@")
749 [ $? -eq 0 ] || die "Failed to expand template $infile"
751 if [ -n "$outfile" ] ; then
752 echo "$outstring" > "$outfile"
759 # Delimiter @@ means to substitute contents of variable.
760 # Delimiter @@@ means to substitute contents of file named by variable.
761 # @@@ supports leading '|' in variable value, which means to excute a
763 _substitute_vars() {(
767 # get the list of variables used in the template
768 VARS=`echo "$instring" |
769 tr -cs "A-Z0-9_$delimiter" '\012' |
771 sed -n -e "s#^${delimiter}\(.*\)${delimiter}\\$#\1#p"`
775 # variable variables are fun .....
778 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
782 if [ "$delimiter" = "@@@" ] ; then
784 c="${f#|}" # Is is a command, signified by a leading '|'?
785 if [ "$c" = "$f" ] ; then
786 # No leading '|', cat file.
790 die "Could not substitute contents of file $f"
793 # Leading '|', execute command.
794 # Quoting problems here - using eval "$c" doesn't help.
798 die "Could not execute command $c"
803 # escape some pesky chars
808 echo "s#${delimiter}${v}${delimiter}#${s}#g"
811 echo "$instring" | sed -f $tmp
817 which $1 > /dev/null || die "Please install $1 to continue"
820 # Set a variable if it isn't already set. This allows environment
821 # variables to override default config settings.
826 [ "${!v+x}" ] || eval "$v=\"$e\""
832 for i in "${installdir}/config.d/"*.defconf ; do
837 # Print the list of config variables defined in config.d/.
838 get_config_options () {( # sub-shell for local declaration of defconf()
840 defconf() { options="$options $1" ; }
845 # Produce a list of long options, suitable for use with getopt, that
846 # represent the config variables defined in config.d/.
847 getopt_config_options () {
848 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
852 # Unconditionally set the config variable associated with the given
858 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
859 # unset so defconf will set it
864 # Dump all of the current config variables.
867 for o in $(get_config_options) ; do
868 echo "${o}=\"${!o}\""
873 # $COLUMNS is set in interactive bash shells. It probably isn't set
874 # in this shell, so let's set it if it isn't.
875 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
879 # Print text assuming it starts after other text in $startcol and
880 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
881 # Long "words" will extend past $COLUMNS - 2.
886 local width=$(($COLUMNS - 2 - $startcol))
887 [ $width -lt 0 ] && width=$((78 - $startcol))
892 if [ $startcol -gt 0 ] ; then
893 padding=$(printf "\n%${startcol}s" " ")
899 while [ -n "$text" ] ; do
902 # If we already have output then arrange padding on the next line.
903 [ -n "$out" ] && out="${out}${padding}"
905 # Break the text at $width.
906 out="${out}${text:0:${width}}"
907 text="${text:${width}}"
909 # If we have left over text then the line break may be ugly,
910 # so let's check and try to break it on a space.
911 if [ -n "$text" ] ; then
912 # The 'x's stop us producing a special character like '(',
913 # ')' or '!'. Yuck - there must be a better way.
914 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
915 # We didn't break on a space. Arrange for the
916 # beginning of the broken "word" to appear on the next
917 # line but not if it will make us loop infinitely.
918 if [ "${orig}" != "${out##* }${text}" ] ; then
919 text="${out##* }${text}"
922 # Hmmm, doing that would make us loop, so add the
923 # rest of the word from the remainder of the text
924 # to this line and let it extend past $COLUMNS - 2.
925 out="${out}${text%% *}"
926 if [ "${text# *}" != "$text" ] ; then
927 # Remember the text after the next space for next time.
930 # No text after next space.
935 # We broke on a space. If it will be at the beginning
936 # of the next line then remove it.
945 # Display usage text, trying these approaches in order.
946 # 1. See if it all fits on one line before $COLUMNS - 2.
947 # 2. See if splitting before the default value and indenting it
948 # to $startcol means that nothing passes $COLUMNS - 2.
949 # 3. Treat the message and default value as a string and just us fill_text()
951 usage_display_text () {
956 local width=$(($COLUMNS - 2 - $startcol))
957 [ $width -lt 0 ] && width=$((78 - $startcol))
959 default="(default \"$default\")"
961 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
962 echo "${desc} ${default}"
964 local padding=$(printf "%${startcol}s" " ")
966 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
968 echo "${padding}${default}"
970 fill_text $startcol "${desc} ${default}"
975 # Display usage information for long config options.
976 usage_smart_display () {( # sub-shell for local declaration of defconf()
980 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
982 printf " --%-25s " "${longopt}=${3}"
984 usage_display_text $startcol "$4" "$2"
991 # Display usage information for long config options.
992 usage_config_options (){
993 usage_smart_display load_config
997 local releases=$(cd $installdir/releases && echo *.release)
998 releases="${releases//.release}"
999 releases="${releases// /\", \"}"
1000 echo "\"$releases\""
1006 # This simply loads an extra config file from $installdir/releases
1007 f="${installdir}/releases/${release}.release"
1008 if [ -r "$f" ] ; then
1011 echo "Unknown release \"${release}\" specified to --with-release"
1012 printf "%-25s" "Supported releases are: "
1013 # The 70 is lazy but it will do.
1014 fill_text 25 "$(list_releases)"
1020 has_public_addresses_DEFAULT ()
1025 # Build public address configuration.
1026 # * 1st public IP: unless specified, last octet is $FIRSTIP + $PUBLIC_IP_OFFSET
1027 # * Excluded nodes: unless specified via comma-separated list of IP offsets,
1028 # nodes are excluded via their node types
1029 # * Number of public addresses per interface is either specified or $NUMNODES.
1030 make_public_addresses () {
1031 local firstip="${1:-$(($FIRSTIP + $PUBLIC_IP_OFFSET))}"
1032 local excluded_nodes="$2"
1033 local num_addrs="${3:-${NUMNODES}}"
1035 # For delimiting matches.
1036 excluded_nodes="${excluded_nodes:+,}${excluded_nodes}${excluded_nodes:+,}"
1038 excluded_nodes="${excluded_nodes// /}"
1040 make_public_addresses_for_node ()
1042 [ "$ctdb_node" = 1 ] || return 0
1044 echo "[/etc/ctdb/public_addresses:${name}.${DOMAIN}]"
1046 if [ -n "$excluded_nodes" -a \
1047 "${excluded_nodes/,${ip_offset},}" = "$excluded_nodes" ] ||
1048 ([ -z "$excluded_nodes" ] &&
1049 call_func has_public_addresses "$node_type") ; then
1052 for e in "1" "2" ; do
1053 for i in $(seq $firstip $(($firstip + $num_addrs - 1))) ; do
1054 if [ $i -gt 254 ] ; then
1055 die "make_public_addresses: octet > 254 - consider setting PUBLIC_IP_OFFSET"
1057 printf "\t${IPBASE}.${e}.${i}/24 eth${e}\n"
1063 hack_all_nodes_with make_public_addresses_for_node
1066 ######################################################################
1070 ############################
1071 # parse command line options
1072 long_opts=$(getopt_config_options)
1073 getopt_output=$(getopt -n autocluster -o "c:e:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1074 [ $? != 0 ] && usage
1076 use_default_config=true
1078 # We do 2 passes of the options. The first time we just handle usage
1079 # and check whether -c is being used.
1080 eval set -- "$getopt_output"
1083 -c) shift 2 ; use_default_config=false ;;
1085 --) shift ; break ;;
1086 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1088 -h|--help) usage ;; # Usage should be shown here for real defaults.
1089 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1090 *) usage ;; # shouldn't happen, so this is reasonable.
1095 $use_default_config && [ -r "$config" ] && . "$config"
1097 eval set -- "$getopt_output"
1101 # force at least ./local_file to avoid accidental file from $PATH
1102 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1103 -e) eval "$2" ; exit ;;
1108 -x) set -x; shift ;;
1109 --dump) dump_config ;;
1110 --) shift ; break ;;
1111 -h|--help) usage ;; # Redundant.
1113 # Putting --opt1|opt2|... into a variable and having case
1114 # match against it as a pattern doesn't work. The | is
1115 # part of shell syntax, so we need to do this. Look away
1116 # now to stop your eyes from bleeding! :-)
1117 x=",${long_opts}" # Now each option is surrounded by , and :
1118 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1119 # Our option, $1, surrounded by , and : was in $x, so is legal.
1120 setconf_longopt "$1" "$2"; shift 2
1125 *) usage ;; # shouldn't happen, so this is reasonable.
1133 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1136 # check for needed programs
1137 check_command nbd-client
1138 check_command expect
1139 check_command $QEMU_NBD
1141 [ $# -lt 1 ] && usage
1152 [ $# != 0 ] && usage
1156 [ $# != 1 ] && usage
1160 [ $# != 2 ] && usage
1161 create_one_node "$1" "$2"
1169 [ $# != 1 ] && usage
1173 [ $# != 0 ] && usage