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"
146 ##############################
148 # common node creation stuff
149 create_node_COMMON ()
154 local template_file="${4:-$NODE_TEMPLATE}"
156 IPNUM=$(($FIRSTIP + $ip_offset))
157 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.qcow2"
159 mkdir -p $VIRTBASE/$CLUSTER tmp
161 echo "Creating the disk"
163 qemu-img create -b "$VIRTBASE/$BASENAME.img" -f qcow2 "$DISK"
170 set_macaddrs $CLUSTER $ip_offset
173 echo "Creating $NAME.xml"
174 substitute_vars $template_file tmp/$NAME.xml
176 # install the XML file
177 $VIRSH undefine $NAME > /dev/null 2>&1 || true
178 $VIRSH define tmp/$NAME.xml
181 # Provides an easy way of removing nodes from $NODE.
182 create_node_null () {
186 ##############################
188 hack_nodes_functions=
190 register_nodes_hack ()
194 hack_nodes_functions="${hack_nodes_functions}${hack_nodes_functions:+ }${hack}"
198 # Expand out any abbreviations in NODES.
207 for i in ${ips//,/ } ; do
208 ns="${ns}${ns:+ }${t}:${i}"
213 for i in $(seq ${ips/-/ }) ; do
214 ns="${ns}${ns:+ }${t}:${i}"
218 ns="${ns}${ns:+ }${n}"
223 # Apply nodes hacks. Some of this is about backward compatibility
224 # but the hacks also fill in the node names and whether they're
225 # part of the CTDB cluster. The order is the order that
226 # configuration modules register their hacks.
227 for n in $hack_nodes_functions ; do
231 if [ -n "$NUMNODES" ] ; then
232 # Attempt to respect NUMNODES. Reduce the number of CTDB
234 local numnodes=$NUMNODES
238 if [ "$ctdb_node" = 1 ] ; then
239 if [ $numnodes -gt 0 ] ; then
240 numnodes=$(($numnodes - 1))
248 hack_all_nodes_with hack_filter
250 [ $numnodes -gt 0 ] && \
251 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."
254 # Check IP addresses for duplicates.
256 # This function doesn't modify anything...
259 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
260 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
261 ip_offsets="${ip_offsets}${ip_offset}:"
263 hack_all_nodes_with get_ip_offset
266 ##############################
268 create_cluster_hooks=
270 register_create_cluster_hook ()
274 create_cluster_hooks="${create_cluster_hooks}${create_cluster_hooks:+ }${hook}"
277 sanity_check_cluster_name ()
279 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
280 die "Cluster names should be restricted to the characters A-Za-z0-9. \
281 Some cluster filesystems have problems with other characters."
284 common_nodelist_hacking ()
286 # Rework the NODES list
289 # Build /etc/hosts and hack the names of the ctdb nodes
290 hosts_line_hack_name ()
292 # Ignore nodes without names (e.g. "null")
293 [ "$node_type" != "null" -a -n "$name" ] || return 0
297 local ip_addr="$IPBASE.0.$(($FIRSTIP + $ip_offset))"
299 if [ "$ctdb_node" = 1 ] ; then
300 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
301 sname="${CLUSTER}n${num_ctdb_nodes}"
302 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
305 hosts_line="$ip_addr ${name}.${ld} $name"
308 # This allows you to add a function to your configuration file
309 # to modify hostnames (and other aspects of nodes). This
310 # function can access/modify $name (the existing name),
311 # $node_type and $ctdb_node (1, if the node is a member of the
312 # CTDB cluster, 0 otherwise).
313 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
314 local old_name="$name"
315 $HOSTNAME_HACKING_FUNCTION
316 if [ "$name" != "$old_name" ] ; then
317 hosts_line="$ip_addr ${name}.${ld} $name"
323 hosts_file="tmp/hosts.$CLUSTER"
325 local num_ctdb_nodes=0
326 local ld=$(echo $DOMAIN | tr A-Z a-z)
327 echo "# autocluster $CLUSTER"
328 hack_all_nodes_with hosts_line_hack_name
332 # Build /etc/ctdb/nodes
335 [ "$ctdb_node" = 1 ] || return 0
336 echo "$IPBASE.0.$(($FIRSTIP + $ip_offset))"
337 num_nodes=$(($num_nodes + 1))
339 nodes_file="tmp/nodes.$CLUSTER"
341 hack_all_nodes_with ctdb_nodes_line >$nodes_file
342 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
349 sanity_check_cluster_name
351 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
353 # Run hooks before doing anything else.
355 for n in $create_cluster_hooks ; do
359 common_nodelist_hacking
361 for_each_node call_func create_node
363 echo "Cluster $CLUSTER created"
364 echo "You may want to add this to your /etc/hosts file:"
371 local single_node_ip_offset="$2"
373 sanity_check_cluster_name
375 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
377 common_nodelist_hacking
380 set -- $(IFS=: ; echo $n)
381 [ $single_node_ip_offset -eq $2 ] || continue
382 call_func create_node "$@"
384 echo "Requested node created"
385 echo "You may want to update your /etc/hosts file:"
392 ###############################
393 # test the proxy setup
395 export http_proxy=$WEBPROXY
396 wget -O /dev/null $INSTALL_SERVER || \
397 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
406 DISK="$VIRTBASE/$NAME.img"
410 echo "Testing WEBPROXY $WEBPROXY"
413 echo "Creating the disk"
414 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
417 mkdir -p mnt tmp tmp/ISO
421 echo "Creating kickstart file from template"
422 substitute_vars "$KICKSTART" "tmp/ks.cfg"
424 if [ $INSTALLKEY = "--skip" ]; then
426 --------------------------------------------------------------------------------------
427 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
429 Please enter a valid RHEL install key in your config file like this:
431 INSTALLKEY="1234-5678-0123-4567"
433 The install will continue without an install key in 5 seconds
434 --------------------------------------------------------------------------------------
439 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
442 (*) ISO="${ISO_DIR}/${ISO}"
445 echo "Creating kickstart floppy"
446 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
447 mkdosfs tmp/floppy.img
448 mount -o loop -t msdos tmp/floppy.img mnt
450 mount -o loop,ro $ISO tmp/ISO
452 echo "Setting up bootloader"
453 cp tmp/ISO/isolinux/isolinux.bin tmp
454 cp tmp/ISO/isolinux/vmlinuz tmp
455 cp tmp/ISO/isolinux/initrd.img tmp
461 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
463 rm -f $KVMLOG/serial.$NAME
465 # boot the install CD
466 $VIRSH create tmp/$NAME.xml
468 echo "Waiting for install to start"
471 # wait for the install to finish
472 if ! waitfor $KVMLOG/serial.$NAME "you may safely reboot your system" $CREATE_BASE_TIMEOUT ; then
474 die "Failed to create base image $DISK"
482 Install finished, base image $DISK created
486 To ensure that this image does not change
488 Note that the root password has been set to $ROOTPASSWORD
493 ###############################
499 DISK="$VIRTBASE/$NAME.img"
513 echo "Creating $NAME.xml"
514 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
516 # boot the base system
517 $VIRSH create tmp/$NAME.xml
520 ######################################################################
522 # various functions...
524 # Set some MAC address variables based on a hash of the cluster name
525 # plus the node number and each adapter number.
530 local md5=$(echo $cname | md5sum)
531 local nh=$(printf "%02x" $ip_offset)
532 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
534 MAC1="${mac_prefix}01"
535 MAC2="${mac_prefix}02"
536 MAC3="${mac_prefix}03"
537 MAC4="${mac_prefix}04"
538 MAC5="${mac_prefix}05"
539 MAC6="${mac_prefix}06"
542 # mount a qemu image via nbd
544 echo "Connecting nbd to $1"
547 killall -9 -q $QEMU_NBD || true
548 $QEMU_NBD -p 1300 $1 &
550 [ -r $NBD_DEVICE ] || {
551 mknod $NBD_DEVICE b 43 0
553 umount mnt 2> /dev/null || true
554 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
555 killall -9 -q nbd-client || true
556 nbd-client localhost 1300 $NBD_DEVICE > /dev/null 2>&1 || true &
562 echo "Disconnecting nbd"
564 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
565 killall -9 -q nbd-client || true
566 killall -q $QEMU_NBD || true
569 # mount a qemu image via nbd
572 echo "Mounting disk $1"
574 for i in `seq 1 5`; do
575 mount -o offset=32256 $NBD_DEVICE mnt && {
579 umount mnt 2>/dev/null || true
582 [ $mount_ok = 1 ] || die "Failed to mount $1"
585 echo "Mounted directory does not look like a root filesystem"
591 # unmount a qemu image
593 echo "Unmounting disk"
595 umount mnt || umount mnt || true
599 # setup the files from $BASE_TEMPLATES/, substituting any variables
600 # based on the config
601 copy_base_dir_substitute_templates ()
605 local d="$BASE_TEMPLATES/$dir"
606 [ -d "$d" ] || return 0
609 for f in $(cd "$d" && find . \! -name '*~') ; do
610 if [ -d "$d/$f" ]; then
613 substitute_vars "$d/$f" "mnt/$f"
615 chmod --reference="$d/$f" "mnt/$f"
624 echo "Copy base files"
625 copy_base_dir_substitute_templates "all"
626 if [ -n "$type" ] ; then
627 copy_base_dir_substitute_templates "$type"
630 # this is needed as git doesn't store file permissions other
632 chmod 600 mnt/etc/ssh/*key mnt/root/.ssh/*
633 chmod 700 mnt/etc/ssh mnt/root/.ssh mnt/root
634 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
635 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
636 cat "$HOME/.ssh/id_rsa.pub" >> mnt/root/.ssh/authorized_keys
638 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
639 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
640 cat "$HOME/.ssh/id_dsa.pub" >> mnt/root/.ssh/authorized_keys
642 echo "Adjusting grub.conf"
643 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
644 sed -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
645 -e "s/ nodmraid//" -e "s/ nompath//" \
646 -e "s/quiet/noapic divider=10${o:+ }${o}/g" mnt/boot/grub/grub.conf -i.org
649 # setup various networking components
651 echo "Setting up networks"
653 cat $hosts_file >>mnt/etc/hosts
655 echo "Setting up /etc/ctdb/nodes"
656 mkdir -p mnt/etc/ctdb
657 cp $nodes_file mnt/etc/ctdb/nodes
659 [ "$WEBPROXY" = "" ] || {
660 echo "export http_proxy=$WEBPROXY" >> mnt/etc/bashrc
663 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
664 echo "Enabling nfs mount of $NFSSHARE"
665 mkdir -p "mnt$NFS_MOUNTPOINT"
666 echo "$NFSSHARE $NFS_MOUNTPOINT nfs intr" >> mnt/etc/fstab
669 mkdir -p mnt/etc/yum.repos.d
670 echo '@@@YUM_TEMPLATE@@@' | substitute_vars - > mnt/etc/yum.repos.d/autocluster.repo
674 [ -z "$TIMEZONE" ] && {
675 [ -r /etc/timezone ] && {
676 TIMEZONE=`cat /etc/timezone`
678 [ -r /etc/sysconfig/clock ] && {
679 . /etc/sysconfig/clock
682 TIMEZONE="${TIMEZONE// /_}"
684 [ -n "$TIMEZONE" ] || \
685 die "Unable to determine TIMEZONE - please set in config"
688 # substite a set of variables of the form @@XX@@ for the shell
689 # variables $XX in a file.
691 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
692 # contain a filename whose contents are substituted, with variable
693 # substitution applied to those contents. If filename starts with '|'
694 # it is a command instead - however, quoting is extremely fragile.
696 infile="${1:-/dev/null}" # if empty then default to /dev/null
697 outfile="$2" # optional
699 instring=$(cat $infile)
701 # Handle any indirects by looping until nothing changes.
702 # However, only handle 10 levels of recursion.
705 outstring=$(_substitute_vars "$instring" "@@@")
706 [ $? -eq 0 ] || die "Failed to expand template $infile"
708 [ "$instring" = "$outstring" ] && break
710 count=$(($count + 1))
711 [ $count -lt 10 ] || \
712 die "Recursion too deep in $infile - only 10 levels allowed!"
714 instring="$outstring"
717 # Now regular variables.
718 outstring=$(_substitute_vars "$instring" "@@")
719 [ $? -eq 0 ] || die "Failed to expand template $infile"
721 if [ -n "$outfile" ] ; then
722 echo "$outstring" > "$outfile"
729 # Delimiter @@ means to substitute contents of variable.
730 # Delimiter @@@ means to substitute contents of file named by variable.
731 # @@@ supports leading '|' in variable value, which means to excute a
733 _substitute_vars() {(
737 # get the list of variables used in the template
738 VARS=`echo "$instring" |
739 tr -cs "A-Z0-9_$delimiter" '\012' |
741 sed -n -e "s#^${delimiter}\(.*\)${delimiter}\\$#\1#p"`
745 # variable variables are fun .....
748 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
752 if [ "$delimiter" = "@@@" ] ; then
754 c="${f#|}" # Is is a command, signified by a leading '|'?
755 if [ "$c" = "$f" ] ; then
756 # No leading '|', cat file.
760 die "Could not substitute contents of file $f"
763 # Leading '|', execute command.
764 # Quoting problems here - using eval "$c" doesn't help.
768 die "Could not execute command $c"
773 # escape some pesky chars
778 echo "s#${delimiter}${v}${delimiter}#${s}#g"
781 echo "$instring" | sed -f $tmp
787 which $1 > /dev/null || die "Please install $1 to continue"
790 # Set a variable if it isn't already set. This allows environment
791 # variables to override default config settings.
796 [ "${!v+x}" ] || eval "$v=\"$e\""
802 for i in "${installdir}/config.d/"*.defconf ; do
807 # Print the list of config variables defined in config.d/.
808 get_config_options () {( # sub-shell for local declaration of defconf()
810 defconf() { options="$options $1" ; }
815 # Produce a list of long options, suitable for use with getopt, that
816 # represent the config variables defined in config.d/.
817 getopt_config_options () {
818 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
822 # Unconditionally set the config variable associated with the given
828 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
829 # unset so defconf will set it
834 # Dump all of the current config variables.
837 for o in $(get_config_options) ; do
838 echo "${o}=\"${!o}\""
843 # $COLUMNS is set in interactive bash shells. It probably isn't set
844 # in this shell, so let's set it if it isn't.
845 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
849 # Print text assuming it starts after other text in $startcol and
850 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
851 # Long "words" will extend past $COLUMNS - 2.
856 local width=$(($COLUMNS - 2 - $startcol))
857 [ $width -lt 0 ] && width=$((78 - $startcol))
862 if [ $startcol -gt 0 ] ; then
863 padding=$(printf "\n%${startcol}s" " ")
869 while [ -n "$text" ] ; do
872 # If we already have output then arrange padding on the next line.
873 [ -n "$out" ] && out="${out}${padding}"
875 # Break the text at $width.
876 out="${out}${text:0:${width}}"
877 text="${text:${width}}"
879 # If we have left over text then the line break may be ugly,
880 # so let's check and try to break it on a space.
881 if [ -n "$text" ] ; then
882 # The 'x's stop us producing a special character like '(',
883 # ')' or '!'. Yuck - there must be a better way.
884 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
885 # We didn't break on a space. Arrange for the
886 # beginning of the broken "word" to appear on the next
887 # line but not if it will make us loop infinitely.
888 if [ "${orig}" != "${out##* }${text}" ] ; then
889 text="${out##* }${text}"
892 # Hmmm, doing that would make us loop, so add the
893 # rest of the word from the remainder of the text
894 # to this line and let it extend past $COLUMNS - 2.
895 out="${out}${text%% *}"
896 if [ "${text# *}" != "$text" ] ; then
897 # Remember the text after the next space for next time.
900 # No text after next space.
905 # We broke on a space. If it will be at the beginning
906 # of the next line then remove it.
915 # Display usage text, trying these approaches in order.
916 # 1. See if it all fits on one line before $COLUMNS - 2.
917 # 2. See if splitting before the default value and indenting it
918 # to $startcol means that nothing passes $COLUMNS - 2.
919 # 3. Treat the message and default value as a string and just us fill_text()
921 usage_display_text () {
926 local width=$(($COLUMNS - 2 - $startcol))
927 [ $width -lt 0 ] && width=$((78 - $startcol))
929 default="(default \"$default\")"
931 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
932 echo "${desc} ${default}"
934 local padding=$(printf "%${startcol}s" " ")
936 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
938 echo "${padding}${default}"
940 fill_text $startcol "${desc} ${default}"
945 # Display usage information for long config options.
946 usage_smart_display () {( # sub-shell for local declaration of defconf()
950 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
952 printf " --%-25s " "${longopt}=${3}"
954 usage_display_text $startcol "$4" "$2"
961 # Display usage information for long config options.
962 usage_config_options (){
963 usage_smart_display load_config
967 local releases=$(cd $installdir/releases && echo *.release)
968 releases="${releases//.release}"
969 releases="${releases// /\", \"}"
976 # This simply loads an extra config file from $installdir/releases
977 f="${installdir}/releases/${release}.release"
978 if [ -r "$f" ] ; then
981 echo "Unknown release \"${release}\" specified to --with-release"
982 printf "%-25s" "Supported releases are: "
983 # The 70 is lazy but it will do.
984 fill_text 25 "$(list_releases)"
990 has_public_addresses_DEFAULT ()
995 # Build public address configuration.
996 # * 1st public IP: unless specified, last octet is $FIRSTIP + $PUBLIC_IP_OFFSET
997 # * Excluded nodes: unless specified via comma-separated list of IP offsets,
998 # nodes are excluded via their node types
999 # * Number of public addresses per interface is either specified or $NUMNODES.
1000 make_public_addresses () {
1001 local firstip="${1:-$(($FIRSTIP + $PUBLIC_IP_OFFSET))}"
1002 local excluded_nodes="$2"
1003 local num_addrs="${3:-${NUMNODES}}"
1005 # For delimiting matches.
1006 excluded_nodes="${excluded_nodes:+,}${excluded_nodes}${excluded_nodes:+,}"
1008 excluded_nodes="${excluded_nodes// /}"
1010 make_public_addresses_for_node ()
1012 [ "$ctdb_node" = 1 ] || return 0
1014 echo "[/etc/ctdb/public_addresses:${name}.${DOMAIN}]"
1016 if [ -n "$excluded_nodes" -a \
1017 "${excluded_nodes/,${ip_offset},}" = "$excluded_nodes" ] ||
1018 ([ -z "$excluded_nodes" ] &&
1019 call_func has_public_addresses "$node_type") ; then
1022 for e in "1" "2" ; do
1023 for i in $(seq $firstip $(($firstip + $num_addrs - 1))) ; do
1024 if [ $i -gt 254 ] ; then
1025 die "make_public_addresses: octet > 254 - consider setting PUBLIC_IP_OFFSET"
1027 printf "\t${IPBASE}.${e}.${i}/24 eth${e}\n"
1033 hack_all_nodes_with make_public_addresses_for_node
1036 ######################################################################
1040 ############################
1041 # parse command line options
1042 long_opts=$(getopt_config_options)
1043 getopt_output=$(getopt -n autocluster -o "c:e:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1044 [ $? != 0 ] && usage
1046 use_default_config=true
1048 # We do 2 passes of the options. The first time we just handle usage
1049 # and check whether -c is being used.
1050 eval set -- "$getopt_output"
1053 -c) shift 2 ; use_default_config=false ;;
1055 --) shift ; break ;;
1056 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1058 -h|--help) usage ;; # Usage should be shown here for real defaults.
1059 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1060 *) usage ;; # shouldn't happen, so this is reasonable.
1065 $use_default_config && [ -r "$config" ] && . "$config"
1067 eval set -- "$getopt_output"
1071 # force at least ./local_file to avoid accidental file from $PATH
1072 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1073 -e) eval "$2" ; exit ;;
1078 -x) set -x; shift ;;
1079 --dump) dump_config ;;
1080 --) shift ; break ;;
1081 -h|--help) usage ;; # Redundant.
1083 # Putting --opt1|opt2|... into a variable and having case
1084 # match against it as a pattern doesn't work. The | is
1085 # part of shell syntax, so we need to do this. Look away
1086 # now to stop your eyes from bleeding! :-)
1087 x=",${long_opts}" # Now each option is surrounded by , and :
1088 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1089 # Our option, $1, surrounded by , and : was in $x, so is legal.
1090 setconf_longopt "$1" "$2"; shift 2
1095 *) usage ;; # shouldn't happen, so this is reasonable.
1103 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1106 # check for needed programs
1107 check_command nbd-client
1108 check_command expect
1109 check_command $QEMU_NBD
1111 [ $# -lt 1 ] && usage
1122 [ $# != 0 ] && usage
1126 [ $# != 1 ] && usage
1130 [ $# != 2 ] && usage
1131 create_one_node "$1" "$2"
1139 [ $# != 1 ] && usage
1143 [ $# != 0 ] && usage