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 # Use with care, since this may clear some autocluster defaults.!
169 eval "$hook_var=\"\""
172 ##############################
174 # common node creation stuff
175 create_node_COMMON ()
180 local template_file="${4:-$NODE_TEMPLATE}"
182 if [ "$SYSTEM_DISK_FORMAT" = "raw" -a "$BASE_FORMAT" != "raw" ] ; then
183 die "Error: if SYSTEM_DISK_FORMAT is \"raw\" then BASE_FORMAT must also be \"raw\"."
186 IPNUM=$(($FIRSTIP + $ip_offset))
187 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}"
188 local base_disk="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}"
190 if [ "$BASE_PER_NODE_TYPE" = "yes" ] ; then
191 base_disk="${VIRTBASE}/${BASENAME}-${type}.${BASE_FORMAT}"
194 mkdir -p $VIRTBASE/$CLUSTER tmp
197 case "$SYSTEM_DISK_FORMAT" in
199 echo "Creating the disk..."
200 qemu-img create -b "$base_disk" -f qcow2 "$DISK"
201 create_node_configure_image "$DISK" "$type"
204 echo "Creating the disk..."
205 cp -v --sparse=always "$base_disk" "$DISK"
206 create_node_configure_image "$DISK" "$type"
209 echo "Skipping disk image creation as requested"
212 die "Error: unknown SYSTEM_DISK_FORMAT=\"${SYSTEM_DISK_FORMAT}\"."
215 set_macaddrs $CLUSTER $ip_offset
218 echo "Creating $NAME.xml"
219 substitute_vars $template_file tmp/$NAME.xml
221 # install the XML file
222 $VIRSH undefine $NAME > /dev/null 2>&1 || true
223 $VIRSH define tmp/$NAME.xml
226 create_node_configure_image ()
236 # Provides an easy way of removing nodes from $NODE.
237 create_node_null () {
241 ##############################
243 hack_nodes_functions=
246 # Expand out any abbreviations in NODES.
255 for i in ${ips//,/ } ; do
256 ns="${ns}${ns:+ }${t}:${i}"
261 for i in $(seq ${ips/-/ }) ; do
262 ns="${ns}${ns:+ }${t}:${i}"
266 ns="${ns}${ns:+ }${n}"
271 # Apply nodes hacks. Some of this is about backward compatibility
272 # but the hacks also fill in the node names and whether they're
273 # part of the CTDB cluster. The order is the order that
274 # configuration modules register their hacks.
275 run_hooks hack_nodes_functions
277 if [ -n "$NUMNODES" ] ; then
278 # Attempt to respect NUMNODES. Reduce the number of CTDB
280 local numnodes=$NUMNODES
284 if [ "$ctdb_node" = 1 ] ; then
285 if [ $numnodes -gt 0 ] ; then
286 numnodes=$(($numnodes - 1))
294 hack_all_nodes_with hack_filter
296 [ $numnodes -gt 0 ] && \
297 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."
300 # Check IP addresses for duplicates.
302 # This function doesn't modify anything...
305 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
306 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
307 ip_offsets="${ip_offsets}${ip_offset}:"
309 hack_all_nodes_with get_ip_offset
312 ##############################
314 sanity_check_cluster_name ()
316 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
317 die "Cluster names should be restricted to the characters A-Za-z0-9. \
318 Some cluster filesystems have problems with other characters."
323 common_nodelist_hacking ()
325 # Rework the NODES list
328 # Build /etc/hosts and hack the names of the ctdb nodes
329 hosts_line_hack_name ()
331 # Ignore nodes without names (e.g. "null")
332 [ "$node_type" != "null" -a -n "$name" ] || return 0
336 local ip_addr="$IPBASE.0.$(($FIRSTIP + $ip_offset))"
338 if [ "$ctdb_node" = 1 ] ; then
339 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
340 sname="${CLUSTER}n${num_ctdb_nodes}"
341 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
344 hosts_line="$ip_addr ${name}.${ld} $name"
347 # This allows you to add a function to your configuration file
348 # to modify hostnames (and other aspects of nodes). This
349 # function can access/modify $name (the existing name),
350 # $node_type and $ctdb_node (1, if the node is a member of the
351 # CTDB cluster, 0 otherwise).
352 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
353 local old_name="$name"
354 $HOSTNAME_HACKING_FUNCTION
355 if [ "$name" != "$old_name" ] ; then
356 hosts_line="$ip_addr ${name}.${ld} $name"
362 hosts_file="tmp/hosts.$CLUSTER"
364 local num_ctdb_nodes=0
365 local ld=$(echo $DOMAIN | tr A-Z a-z)
366 echo "# autocluster $CLUSTER"
367 hack_all_nodes_with hosts_line_hack_name
371 # Build /etc/ctdb/nodes
374 [ "$ctdb_node" = 1 ] || return 0
375 echo "$IPBASE.0.$(($FIRSTIP + $ip_offset))"
376 num_nodes=$(($num_nodes + 1))
378 nodes_file="tmp/nodes.$CLUSTER"
380 hack_all_nodes_with ctdb_nodes_line >$nodes_file
381 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
384 uuid_map="tmp/uuid_map.$CLUSTER"
387 echo "${ip_offset} $(uuidgen)"
389 hack_all_nodes_with uuid_map_line >$uuid_map
392 create_cluster_hooks=
393 cluster_created_hooks=
399 sanity_check_cluster_name
401 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
403 # Run hooks before doing anything else.
404 run_hooks create_cluster_hooks
406 common_nodelist_hacking
408 for_each_node call_func create_node
410 echo "Cluster $CLUSTER created"
411 echo "You may want to add this to your /etc/hosts file:"
414 run_hooks cluster_created_hooks
420 local single_node_ip_offset="$2"
422 sanity_check_cluster_name
424 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
426 common_nodelist_hacking
429 set -- $(IFS=: ; echo $n)
430 [ $single_node_ip_offset -eq $2 ] || continue
431 call_func create_node "$@"
433 echo "Requested node created"
434 echo "You may want to update your /etc/hosts file:"
441 ###############################
442 # test the proxy setup
444 export http_proxy=$WEBPROXY
445 wget -O /dev/null $INSTALL_SERVER || \
446 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
452 kickstart_floppy_create_hooks=
458 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
462 echo "Testing WEBPROXY $WEBPROXY"
465 echo "Creating the disk"
466 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
469 mkdir -p mnt tmp tmp/ISO
473 echo "Creating kickstart file from template"
474 substitute_vars "$KICKSTART" "tmp/ks.cfg"
476 if [ $INSTALLKEY = "--skip" ]; then
478 --------------------------------------------------------------------------------------
479 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
481 Please enter a valid RHEL install key in your config file like this:
483 INSTALLKEY="1234-5678-0123-4567"
485 The install will continue without an install key in 5 seconds
486 --------------------------------------------------------------------------------------
491 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
494 (*) ISO="${ISO_DIR}/${ISO}"
497 echo "Creating kickstart floppy"
498 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
499 mkdosfs tmp/floppy.img
500 mount -o loop -t msdos tmp/floppy.img mnt
502 mount -o loop,ro $ISO tmp/ISO
504 echo "Setting up bootloader"
505 cp tmp/ISO/isolinux/isolinux.bin tmp
506 cp tmp/ISO/isolinux/vmlinuz tmp
507 cp tmp/ISO/isolinux/initrd.img tmp
509 run_hooks kickstart_floppy_create_hooks
516 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
518 rm -f $KVMLOG/serial.$NAME
520 # boot the install CD
521 $VIRSH create tmp/$NAME.xml
523 echo "Waiting for install to start"
526 # wait for the install to finish
527 if ! waitfor $KVMLOG/serial.$NAME "$KS_DONE_MESSAGE" $CREATE_BASE_TIMEOUT ; then
529 die "Failed to create base image $DISK"
537 Install finished, base image $DISK created
541 To ensure that this image does not change
543 Note that the root password has been set to $ROOTPASSWORD
548 ###############################
554 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
568 echo "Creating $NAME.xml"
569 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
571 # boot the base system
572 $VIRSH create tmp/$NAME.xml
575 ######################################################################
577 # various functions...
579 # Set some MAC address variables based on a hash of the cluster name
580 # plus the node number and each adapter number.
585 local md5=$(echo $cname | md5sum)
586 local nh=$(printf "%02x" $ip_offset)
587 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
589 MAC1="${mac_prefix}01"
590 MAC2="${mac_prefix}02"
591 MAC3="${mac_prefix}03"
592 MAC4="${mac_prefix}04"
593 MAC5="${mac_prefix}05"
594 MAC6="${mac_prefix}06"
597 # mount a qemu image via nbd
599 echo "Connecting nbd to $1"
602 killall -9 -q $QEMU_NBD || true
603 $QEMU_NBD -p 1300 $1 &
605 [ -r $NBD_DEVICE ] || {
606 mknod $NBD_DEVICE b 43 0
608 umount mnt 2> /dev/null || true
609 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
610 killall -9 -q nbd-client || true
611 nbd-client localhost 1300 $NBD_DEVICE > /dev/null 2>&1 || true &
617 echo "Disconnecting nbd"
619 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
620 killall -9 -q nbd-client || true
621 killall -q $QEMU_NBD || true
628 case "$SYSTEM_DISK_FORMAT" in
632 extra_mount_options=""
636 extra_mount_options=",loop"
639 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
645 case "$SYSTEM_DISK_FORMAT" in
653 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
657 # mount a qemu image via nbd
662 local device extra_mount_options
666 echo "Mounting disk ${disk}..."
668 for m in $SYSTEM_DISK_MOUNTS ; do
670 o="${m#*:}" # Offset is after colon
671 m="${m%:*}" # Mountpoint is before colon
672 echo " mount ${m} from offset ${o}"
674 for i in $(seq 1 5); do
675 mount -o offset=${o}${extra_mount_options} $device "mnt${m}" && {
679 umount mnt 2>/dev/null || true
682 [ $mount_ok = 1 ] || die "Failed to mount $disk"
686 echo "Mounted directory does not look like a root filesystem"
692 # unmount a qemu image
694 echo "Unmounting disk"
697 # umounts are done in reverse. Be lazy and construct a reverse
698 # list, since the shell will handle any strange whitespace for
702 for m in $SYSTEM_DISK_MOUNTS ; do
703 umounts="${m%:*}${umounts:+ }${umounts}"
705 for m in $umounts ; do
707 umount "mnt${m}" || umount "mnt${m}" || true
712 # setup the files from $BASE_TEMPLATES/, substituting any variables
713 # based on the config
714 copy_base_dir_substitute_templates ()
718 local d="$BASE_TEMPLATES/$dir"
719 [ -d "$d" ] || return 0
722 for f in $(cd "$d" && find . \! -name '*~') ; do
723 if [ -d "$d/$f" ]; then
726 substitute_vars "$d/$f" "mnt/$f"
728 chmod --reference="$d/$f" "mnt/$f"
734 setup_base_ssh_keys ()
736 # this is needed as git doesn't store file permissions other
738 chmod 600 mnt/etc/ssh/*key mnt/root/.ssh/*
739 chmod 700 mnt/etc/ssh mnt/root/.ssh mnt/root
740 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
741 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
742 cat "$HOME/.ssh/id_rsa.pub" >> mnt/root/.ssh/authorized_keys
744 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
745 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
746 cat "$HOME/.ssh/id_dsa.pub" >> mnt/root/.ssh/authorized_keys
750 register_hook setup_base_hooks setup_base_ssh_keys
752 setup_base_grub_conf ()
754 echo "Adjusting grub.conf"
755 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
756 sed -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
757 -e "s/ nodmraid//" -e "s/ nompath//" \
758 -e "s/quiet/noapic divider=10${o:+ }${o}/g" mnt/boot/grub/grub.conf -i.org
761 register_hook setup_base_hooks setup_base_grub_conf
768 echo "Copy base files"
769 copy_base_dir_substitute_templates "all"
770 if [ -n "$type" ] ; then
771 copy_base_dir_substitute_templates "$type"
774 run_hooks setup_base_hooks
777 # setup various networking components
780 # This avoids doing anything when we're called from boot_base().
781 if [ -z "$hosts_file" ] ; then
782 echo "Skipping network-related setup"
786 echo "Setting up networks"
787 cat $hosts_file >>mnt/etc/hosts
789 echo "Setting up /etc/ctdb/nodes"
790 mkdir -p mnt/etc/ctdb
791 cp $nodes_file mnt/etc/ctdb/nodes
793 [ "$WEBPROXY" = "" ] || {
794 echo "export http_proxy=$WEBPROXY" >> mnt/etc/bashrc
797 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
798 echo "Enabling nfs mount of $NFSSHARE"
799 mkdir -p "mnt$NFS_MOUNTPOINT"
800 echo "$NFSSHARE $NFS_MOUNTPOINT nfs intr" >> mnt/etc/fstab
803 mkdir -p mnt/etc/yum.repos.d
804 echo '@@@YUM_TEMPLATE@@@' | substitute_vars - > mnt/etc/yum.repos.d/autocluster.repo
807 register_hook setup_base_hooks setup_network
810 [ -z "$TIMEZONE" ] && {
811 [ -r /etc/timezone ] && {
812 TIMEZONE=`cat /etc/timezone`
814 [ -r /etc/sysconfig/clock ] && {
815 . /etc/sysconfig/clock
818 TIMEZONE="${TIMEZONE// /_}"
820 [ -n "$TIMEZONE" ] || \
821 die "Unable to determine TIMEZONE - please set in config"
824 # substite a set of variables of the form @@XX@@ for the shell
825 # variables $XX in a file.
827 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
828 # contain a filename whose contents are substituted, with variable
829 # substitution applied to those contents. If filename starts with '|'
830 # it is a command instead - however, quoting is extremely fragile.
832 infile="${1:-/dev/null}" # if empty then default to /dev/null
833 outfile="$2" # optional
835 instring=$(cat $infile)
837 # Handle any indirects by looping until nothing changes.
838 # However, only handle 10 levels of recursion.
841 outstring=$(_substitute_vars "$instring" "@@@")
842 [ $? -eq 0 ] || die "Failed to expand template $infile"
844 [ "$instring" = "$outstring" ] && break
846 count=$(($count + 1))
847 [ $count -lt 10 ] || \
848 die "Recursion too deep in $infile - only 10 levels allowed!"
850 instring="$outstring"
853 # Now regular variables.
854 outstring=$(_substitute_vars "$instring" "@@")
855 [ $? -eq 0 ] || die "Failed to expand template $infile"
857 if [ -n "$outfile" ] ; then
858 echo "$outstring" > "$outfile"
865 # Delimiter @@ means to substitute contents of variable.
866 # Delimiter @@@ means to substitute contents of file named by variable.
867 # @@@ supports leading '|' in variable value, which means to excute a
869 _substitute_vars() {(
873 # get the list of variables used in the template
874 VARS=`echo "$instring" |
875 tr -cs "A-Z0-9_$delimiter" '\012' |
877 sed -n -e "s#^${delimiter}\(.*\)${delimiter}\\$#\1#p"`
881 # variable variables are fun .....
884 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
888 if [ "$delimiter" = "@@@" ] ; then
890 c="${f#|}" # Is is a command, signified by a leading '|'?
891 if [ "$c" = "$f" ] ; then
892 # No leading '|', cat file.
896 die "Could not substitute contents of file $f"
899 # Leading '|', execute command.
900 # Quoting problems here - using eval "$c" doesn't help.
904 die "Could not execute command $c"
909 # escape some pesky chars
914 echo "s#${delimiter}${v}${delimiter}#${s}#g"
917 echo "$instring" | sed -f $tmp
923 which $1 > /dev/null || die "Please install $1 to continue"
926 # Set a variable if it isn't already set. This allows environment
927 # variables to override default config settings.
932 [ "${!v+x}" ] || eval "$v=\"$e\""
938 for i in "${installdir}/config.d/"*.defconf ; do
943 # Print the list of config variables defined in config.d/.
944 get_config_options () {( # sub-shell for local declaration of defconf()
946 defconf() { options="$options $1" ; }
951 # Produce a list of long options, suitable for use with getopt, that
952 # represent the config variables defined in config.d/.
953 getopt_config_options () {
954 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
958 # Unconditionally set the config variable associated with the given
964 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
965 # unset so defconf will set it
970 # Dump all of the current config variables.
973 for o in $(get_config_options) ; do
974 echo "${o}=\"${!o}\""
979 # $COLUMNS is set in interactive bash shells. It probably isn't set
980 # in this shell, so let's set it if it isn't.
981 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
985 # Print text assuming it starts after other text in $startcol and
986 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
987 # Long "words" will extend past $COLUMNS - 2.
992 local width=$(($COLUMNS - 2 - $startcol))
993 [ $width -lt 0 ] && width=$((78 - $startcol))
998 if [ $startcol -gt 0 ] ; then
999 padding=$(printf "\n%${startcol}s" " ")
1005 while [ -n "$text" ] ; do
1008 # If we already have output then arrange padding on the next line.
1009 [ -n "$out" ] && out="${out}${padding}"
1011 # Break the text at $width.
1012 out="${out}${text:0:${width}}"
1013 text="${text:${width}}"
1015 # If we have left over text then the line break may be ugly,
1016 # so let's check and try to break it on a space.
1017 if [ -n "$text" ] ; then
1018 # The 'x's stop us producing a special character like '(',
1019 # ')' or '!'. Yuck - there must be a better way.
1020 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
1021 # We didn't break on a space. Arrange for the
1022 # beginning of the broken "word" to appear on the next
1023 # line but not if it will make us loop infinitely.
1024 if [ "${orig}" != "${out##* }${text}" ] ; then
1025 text="${out##* }${text}"
1028 # Hmmm, doing that would make us loop, so add the
1029 # rest of the word from the remainder of the text
1030 # to this line and let it extend past $COLUMNS - 2.
1031 out="${out}${text%% *}"
1032 if [ "${text# *}" != "$text" ] ; then
1033 # Remember the text after the next space for next time.
1036 # No text after next space.
1041 # We broke on a space. If it will be at the beginning
1042 # of the next line then remove it.
1051 # Display usage text, trying these approaches in order.
1052 # 1. See if it all fits on one line before $COLUMNS - 2.
1053 # 2. See if splitting before the default value and indenting it
1054 # to $startcol means that nothing passes $COLUMNS - 2.
1055 # 3. Treat the message and default value as a string and just us fill_text()
1057 usage_display_text () {
1062 local width=$(($COLUMNS - 2 - $startcol))
1063 [ $width -lt 0 ] && width=$((78 - $startcol))
1065 default="(default \"$default\")"
1067 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
1068 echo "${desc} ${default}"
1070 local padding=$(printf "%${startcol}s" " ")
1072 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
1074 echo "${padding}${default}"
1076 fill_text $startcol "${desc} ${default}"
1081 # Display usage information for long config options.
1082 usage_smart_display () {( # sub-shell for local declaration of defconf()
1086 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
1088 printf " --%-25s " "${longopt}=${3}"
1090 usage_display_text $startcol "$4" "$2"
1097 # Display usage information for long config options.
1098 usage_config_options (){
1099 usage_smart_display load_config
1103 local releases=$(cd $installdir/releases && echo *.release)
1104 releases="${releases//.release}"
1105 releases="${releases// /\", \"}"
1106 echo "\"$releases\""
1111 shift # subsequent args are passed to release file
1113 # This simply loads an extra config file from $installdir/releases
1114 f="${installdir}/releases/${release}.release"
1115 if [ -r "$f" ] ; then
1118 f="${installdir}/releases/${release%%-*}.release"
1119 if [ -r "$f" ] ; then
1120 . "$f" "${release#*-}"
1122 echo "Unknown release \"${release}\" specified to --with-release"
1123 printf "%-25s" "Supported releases are: "
1124 fill_text 25 "$(list_releases)"
1131 has_public_addresses_DEFAULT ()
1136 # Build public address configuration.
1137 # * 1st public IP: unless specified, last octet is $FIRSTIP + $PUBLIC_IP_OFFSET
1138 # * Excluded nodes: unless specified via comma-separated list of IP offsets,
1139 # nodes are excluded via their node types
1140 # * Number of public addresses per interface is either specified or $NUMNODES.
1141 make_public_addresses () {
1142 local firstip="${1:-$(($FIRSTIP + $PUBLIC_IP_OFFSET))}"
1143 local excluded_nodes="$2"
1144 local num_addrs="${3:-${NUMNODES}}"
1146 # For delimiting matches.
1147 excluded_nodes="${excluded_nodes:+,}${excluded_nodes}${excluded_nodes:+,}"
1149 excluded_nodes="${excluded_nodes// /}"
1151 make_public_addresses_for_node ()
1153 [ "$ctdb_node" = 1 ] || return 0
1155 echo "[/etc/ctdb/public_addresses:${name}.${DOMAIN}]"
1157 if [ -n "$excluded_nodes" -a \
1158 "${excluded_nodes/,${ip_offset},}" = "$excluded_nodes" ] ||
1159 ([ -z "$excluded_nodes" ] &&
1160 call_func has_public_addresses "$node_type") ; then
1163 for e in "1" "2" ; do
1164 for i in $(seq $firstip $(($firstip + $num_addrs - 1))) ; do
1165 if [ $i -gt 254 ] ; then
1166 die "make_public_addresses: octet > 254 - consider setting PUBLIC_IP_OFFSET"
1168 printf "\t${IPBASE}.${e}.${i}/24 eth${e}\n"
1174 hack_all_nodes_with make_public_addresses_for_node
1177 ######################################################################
1181 ############################
1182 # parse command line options
1183 long_opts=$(getopt_config_options)
1184 getopt_output=$(getopt -n autocluster -o "c:e:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1185 [ $? != 0 ] && usage
1187 use_default_config=true
1189 # We do 2 passes of the options. The first time we just handle usage
1190 # and check whether -c is being used.
1191 eval set -- "$getopt_output"
1194 -c) shift 2 ; use_default_config=false ;;
1196 --) shift ; break ;;
1197 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1199 -h|--help) usage ;; # Usage should be shown here for real defaults.
1200 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1201 *) usage ;; # shouldn't happen, so this is reasonable.
1206 $use_default_config && [ -r "$config" ] && . "$config"
1208 eval set -- "$getopt_output"
1212 # force at least ./local_file to avoid accidental file from $PATH
1213 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1214 -e) eval "$2" ; exit ;;
1219 -x) set -x; shift ;;
1220 --dump) dump_config ;;
1221 --) shift ; break ;;
1222 -h|--help) usage ;; # Redundant.
1224 # Putting --opt1|opt2|... into a variable and having case
1225 # match against it as a pattern doesn't work. The | is
1226 # part of shell syntax, so we need to do this. Look away
1227 # now to stop your eyes from bleeding! :-)
1228 x=",${long_opts}" # Now each option is surrounded by , and :
1229 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1230 # Our option, $1, surrounded by , and : was in $x, so is legal.
1231 setconf_longopt "$1" "$2"; shift 2
1236 *) usage ;; # shouldn't happen, so this is reasonable.
1244 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1247 # check for needed programs
1248 check_command expect
1249 if [ "$SYSTEM_DISK_FORMAT" != "raw" ] ; then
1250 check_command $QEMU_NBD
1251 check_command nbd-client
1254 [ $# -lt 1 ] && usage
1265 [ $# != 0 ] && usage
1269 [ $# != 1 ] && usage
1273 [ $# != 2 ] && usage
1274 create_one_node "$1" "$2"
1282 [ $# != 1 ] && usage
1286 [ $# != 0 ] && usage