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
217 # Pull the UUID for this node out of the map.
218 UUID=$(awk "\$1 == $ip_offset {print \$2}" $uuid_map)
220 echo "Creating $NAME.xml"
221 substitute_vars $template_file tmp/$NAME.xml
223 # install the XML file
224 $VIRSH undefine $NAME > /dev/null 2>&1 || true
225 $VIRSH define tmp/$NAME.xml
228 create_node_configure_image ()
238 # Provides an easy way of removing nodes from $NODE.
239 create_node_null () {
243 ##############################
245 hack_nodes_functions=
248 # Expand out any abbreviations in NODES.
257 for i in ${ips//,/ } ; do
258 ns="${ns}${ns:+ }${t}:${i}"
263 for i in $(seq ${ips/-/ }) ; do
264 ns="${ns}${ns:+ }${t}:${i}"
268 ns="${ns}${ns:+ }${n}"
273 # Apply nodes hacks. Some of this is about backward compatibility
274 # but the hacks also fill in the node names and whether they're
275 # part of the CTDB cluster. The order is the order that
276 # configuration modules register their hacks.
277 run_hooks hack_nodes_functions
279 if [ -n "$NUMNODES" ] ; then
280 # Attempt to respect NUMNODES. Reduce the number of CTDB
282 local numnodes=$NUMNODES
286 if [ "$ctdb_node" = 1 ] ; then
287 if [ $numnodes -gt 0 ] ; then
288 numnodes=$(($numnodes - 1))
296 hack_all_nodes_with hack_filter
298 [ $numnodes -gt 0 ] && \
299 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."
302 # Check IP addresses for duplicates.
304 # This function doesn't modify anything...
307 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
308 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
309 ip_offsets="${ip_offsets}${ip_offset}:"
311 hack_all_nodes_with get_ip_offset
314 ##############################
316 sanity_check_cluster_name ()
318 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
319 die "Cluster names should be restricted to the characters A-Za-z0-9. \
320 Some cluster filesystems have problems with other characters."
325 common_nodelist_hacking ()
327 # Rework the NODES list
330 # Build /etc/hosts and hack the names of the ctdb nodes
331 hosts_line_hack_name ()
333 # Ignore nodes without names (e.g. "null")
334 [ "$node_type" != "null" -a -n "$name" ] || return 0
338 local ip_addr="$IPBASE.0.$(($FIRSTIP + $ip_offset))"
340 if [ "$ctdb_node" = 1 ] ; then
341 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
342 sname="${CLUSTER}n${num_ctdb_nodes}"
343 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
346 hosts_line="$ip_addr ${name}.${ld} $name"
349 # This allows you to add a function to your configuration file
350 # to modify hostnames (and other aspects of nodes). This
351 # function can access/modify $name (the existing name),
352 # $node_type and $ctdb_node (1, if the node is a member of the
353 # CTDB cluster, 0 otherwise).
354 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
355 local old_name="$name"
356 $HOSTNAME_HACKING_FUNCTION
357 if [ "$name" != "$old_name" ] ; then
358 hosts_line="$ip_addr ${name}.${ld} $name"
364 hosts_file="tmp/hosts.$CLUSTER"
366 local num_ctdb_nodes=0
367 local ld=$(echo $DOMAIN | tr A-Z a-z)
368 echo "# autocluster $CLUSTER"
369 hack_all_nodes_with hosts_line_hack_name
373 # Build /etc/ctdb/nodes
376 [ "$ctdb_node" = 1 ] || return 0
377 echo "$IPBASE.0.$(($FIRSTIP + $ip_offset))"
378 num_nodes=$(($num_nodes + 1))
380 nodes_file="tmp/nodes.$CLUSTER"
382 hack_all_nodes_with ctdb_nodes_line >$nodes_file
383 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
386 uuid_map="tmp/uuid_map.$CLUSTER"
389 echo "${ip_offset} $(uuidgen) ${node_type}"
391 hack_all_nodes_with uuid_map_line >$uuid_map
394 create_cluster_hooks=
395 cluster_created_hooks=
401 sanity_check_cluster_name
403 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
405 # Run hooks before doing anything else.
406 run_hooks create_cluster_hooks
408 common_nodelist_hacking
410 for_each_node call_func create_node
412 echo "Cluster $CLUSTER created"
413 echo "You may want to add this to your /etc/hosts file:"
416 run_hooks cluster_created_hooks
422 local single_node_ip_offset="$2"
424 sanity_check_cluster_name
426 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
428 common_nodelist_hacking
431 set -- $(IFS=: ; echo $n)
432 [ $single_node_ip_offset -eq $2 ] || continue
433 call_func create_node "$@"
435 echo "Requested node created"
436 echo "You may want to update your /etc/hosts file:"
443 ###############################
444 # test the proxy setup
446 export http_proxy=$WEBPROXY
447 wget -O /dev/null $INSTALL_SERVER || \
448 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
454 kickstart_floppy_create_hooks=
460 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
464 echo "Testing WEBPROXY $WEBPROXY"
467 echo "Creating the disk"
468 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
471 mkdir -p mnt tmp tmp/ISO
475 echo "Creating kickstart file from template"
476 substitute_vars "$KICKSTART" "tmp/ks.cfg"
478 if [ $INSTALLKEY = "--skip" ]; then
480 --------------------------------------------------------------------------------------
481 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
483 Please enter a valid RHEL install key in your config file like this:
485 INSTALLKEY="1234-5678-0123-4567"
487 The install will continue without an install key in 5 seconds
488 --------------------------------------------------------------------------------------
493 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
496 (*) ISO="${ISO_DIR}/${ISO}"
499 echo "Creating kickstart floppy"
500 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
501 mkdosfs tmp/floppy.img
502 mount -o loop -t msdos tmp/floppy.img mnt
504 mount -o loop,ro $ISO tmp/ISO
506 echo "Setting up bootloader"
507 cp tmp/ISO/isolinux/isolinux.bin tmp
508 cp tmp/ISO/isolinux/vmlinuz tmp
509 cp tmp/ISO/isolinux/initrd.img tmp
511 run_hooks kickstart_floppy_create_hooks
518 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
520 rm -f $KVMLOG/serial.$NAME
522 # boot the install CD
523 $VIRSH create tmp/$NAME.xml
525 echo "Waiting for install to start"
528 # wait for the install to finish
529 if ! waitfor $KVMLOG/serial.$NAME "$KS_DONE_MESSAGE" $CREATE_BASE_TIMEOUT ; then
531 die "Failed to create base image $DISK"
539 Install finished, base image $DISK created
543 To ensure that this image does not change
545 Note that the root password has been set to $ROOTPASSWORD
550 ###############################
556 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
570 echo "Creating $NAME.xml"
571 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
573 # boot the base system
574 $VIRSH create tmp/$NAME.xml
577 ######################################################################
579 # various functions...
581 # Set some MAC address variables based on a hash of the cluster name
582 # plus the node number and each adapter number.
587 local md5=$(echo $cname | md5sum)
588 local nh=$(printf "%02x" $ip_offset)
589 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
591 MAC1="${mac_prefix}01"
592 MAC2="${mac_prefix}02"
593 MAC3="${mac_prefix}03"
594 MAC4="${mac_prefix}04"
595 MAC5="${mac_prefix}05"
596 MAC6="${mac_prefix}06"
599 # mount a qemu image via nbd
601 echo "Connecting nbd to $1"
604 killall -9 -q $QEMU_NBD || true
605 $QEMU_NBD -p 1300 $1 &
607 [ -r $NBD_DEVICE ] || {
608 mknod $NBD_DEVICE b 43 0
610 umount mnt 2> /dev/null || true
611 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
612 killall -9 -q nbd-client || true
613 nbd-client localhost 1300 $NBD_DEVICE > /dev/null 2>&1 || true &
619 echo "Disconnecting nbd"
621 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
622 killall -9 -q nbd-client || true
623 killall -q $QEMU_NBD || true
630 case "$SYSTEM_DISK_FORMAT" in
634 extra_mount_options=""
638 extra_mount_options=",loop"
641 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
647 case "$SYSTEM_DISK_FORMAT" in
655 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
659 # mount a qemu image via nbd
664 local device extra_mount_options
668 echo "Mounting disk ${disk}..."
670 for m in $SYSTEM_DISK_MOUNTS ; do
672 o="${m#*:}" # Offset is after colon
673 m="${m%:*}" # Mountpoint is before colon
674 echo " mount ${m} from offset ${o}"
676 for i in $(seq 1 5); do
677 mount -o offset=${o}${extra_mount_options} $device "mnt${m}" && {
681 umount mnt 2>/dev/null || true
684 [ $mount_ok = 1 ] || die "Failed to mount $disk"
688 echo "Mounted directory does not look like a root filesystem"
694 # unmount a qemu image
696 echo "Unmounting disk"
699 # umounts are done in reverse. Be lazy and construct a reverse
700 # list, since the shell will handle any strange whitespace for
704 for m in $SYSTEM_DISK_MOUNTS ; do
705 umounts="${m%:*}${umounts:+ }${umounts}"
707 for m in $umounts ; do
709 umount "mnt${m}" || umount "mnt${m}" || true
714 # setup the files from $BASE_TEMPLATES/, substituting any variables
715 # based on the config
716 copy_base_dir_substitute_templates ()
720 local d="$BASE_TEMPLATES/$dir"
721 [ -d "$d" ] || return 0
724 for f in $(cd "$d" && find . \! -name '*~') ; do
725 if [ -d "$d/$f" ]; then
728 substitute_vars "$d/$f" "mnt/$f"
730 chmod --reference="$d/$f" "mnt/$f"
736 setup_base_ssh_keys ()
738 # this is needed as git doesn't store file permissions other
740 chmod 600 mnt/etc/ssh/*key mnt/root/.ssh/*
741 chmod 700 mnt/etc/ssh mnt/root/.ssh mnt/root
742 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
743 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
744 cat "$HOME/.ssh/id_rsa.pub" >> mnt/root/.ssh/authorized_keys
746 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
747 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
748 cat "$HOME/.ssh/id_dsa.pub" >> mnt/root/.ssh/authorized_keys
752 register_hook setup_base_hooks setup_base_ssh_keys
754 setup_base_grub_conf ()
756 echo "Adjusting grub.conf"
757 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
758 sed -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
759 -e "s/ nodmraid//" -e "s/ nompath//" \
760 -e "s/quiet/noapic divider=10${o:+ }${o}/g" mnt/boot/grub/grub.conf -i.org
763 register_hook setup_base_hooks setup_base_grub_conf
770 echo "Copy base files"
771 copy_base_dir_substitute_templates "all"
772 if [ -n "$type" ] ; then
773 copy_base_dir_substitute_templates "$type"
776 run_hooks setup_base_hooks
779 # setup various networking components
782 # This avoids doing anything when we're called from boot_base().
783 if [ -z "$hosts_file" ] ; then
784 echo "Skipping network-related setup"
788 echo "Setting up networks"
789 cat $hosts_file >>mnt/etc/hosts
791 echo "Setting up /etc/ctdb/nodes"
792 mkdir -p mnt/etc/ctdb
793 cp $nodes_file mnt/etc/ctdb/nodes
795 [ "$WEBPROXY" = "" ] || {
796 echo "export http_proxy=$WEBPROXY" >> mnt/etc/bashrc
799 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
800 echo "Enabling nfs mount of $NFSSHARE"
801 mkdir -p "mnt$NFS_MOUNTPOINT"
802 echo "$NFSSHARE $NFS_MOUNTPOINT nfs intr" >> mnt/etc/fstab
805 mkdir -p mnt/etc/yum.repos.d
806 echo '@@@YUM_TEMPLATE@@@' | substitute_vars - > mnt/etc/yum.repos.d/autocluster.repo
809 register_hook setup_base_hooks setup_network
812 [ -z "$TIMEZONE" ] && {
813 [ -r /etc/timezone ] && {
814 TIMEZONE=`cat /etc/timezone`
816 [ -r /etc/sysconfig/clock ] && {
817 . /etc/sysconfig/clock
820 TIMEZONE="${TIMEZONE// /_}"
822 [ -n "$TIMEZONE" ] || \
823 die "Unable to determine TIMEZONE - please set in config"
826 # substite a set of variables of the form @@XX@@ for the shell
827 # variables $XX in a file.
829 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
830 # contain a filename whose contents are substituted, with variable
831 # substitution applied to those contents. If filename starts with '|'
832 # it is a command instead - however, quoting is extremely fragile.
834 infile="${1:-/dev/null}" # if empty then default to /dev/null
835 outfile="$2" # optional
837 instring=$(cat $infile)
839 # Handle any indirects by looping until nothing changes.
840 # However, only handle 10 levels of recursion.
843 outstring=$(_substitute_vars "$instring" "@@@")
844 [ $? -eq 0 ] || die "Failed to expand template $infile"
846 [ "$instring" = "$outstring" ] && break
848 count=$(($count + 1))
849 [ $count -lt 10 ] || \
850 die "Recursion too deep in $infile - only 10 levels allowed!"
852 instring="$outstring"
855 # Now regular variables.
856 outstring=$(_substitute_vars "$instring" "@@")
857 [ $? -eq 0 ] || die "Failed to expand template $infile"
859 if [ -n "$outfile" ] ; then
860 echo "$outstring" > "$outfile"
867 # Delimiter @@ means to substitute contents of variable.
868 # Delimiter @@@ means to substitute contents of file named by variable.
869 # @@@ supports leading '|' in variable value, which means to excute a
871 _substitute_vars() {(
875 # get the list of variables used in the template
876 VARS=`echo "$instring" |
877 tr -cs "A-Z0-9_$delimiter" '\012' |
879 sed -n -e "s#^${delimiter}\(.*\)${delimiter}\\$#\1#p"`
883 # variable variables are fun .....
886 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
890 if [ "$delimiter" = "@@@" ] ; then
892 c="${f#|}" # Is is a command, signified by a leading '|'?
893 if [ "$c" = "$f" ] ; then
894 # No leading '|', cat file.
898 die "Could not substitute contents of file $f"
901 # Leading '|', execute command.
902 # Quoting problems here - using eval "$c" doesn't help.
906 die "Could not execute command $c"
911 # escape some pesky chars
916 echo "s#${delimiter}${v}${delimiter}#${s}#g"
919 echo "$instring" | sed -f $tmp
925 which $1 > /dev/null || die "Please install $1 to continue"
928 # Set a variable if it isn't already set. This allows environment
929 # variables to override default config settings.
934 [ "${!v+x}" ] || eval "$v=\"$e\""
940 for i in "${installdir}/config.d/"*.defconf ; do
945 # Print the list of config variables defined in config.d/.
946 get_config_options () {( # sub-shell for local declaration of defconf()
948 defconf() { options="$options $1" ; }
953 # Produce a list of long options, suitable for use with getopt, that
954 # represent the config variables defined in config.d/.
955 getopt_config_options () {
956 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
960 # Unconditionally set the config variable associated with the given
966 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
967 # unset so defconf will set it
972 # Dump all of the current config variables.
975 for o in $(get_config_options) ; do
976 echo "${o}=\"${!o}\""
981 # $COLUMNS is set in interactive bash shells. It probably isn't set
982 # in this shell, so let's set it if it isn't.
983 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
987 # Print text assuming it starts after other text in $startcol and
988 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
989 # Long "words" will extend past $COLUMNS - 2.
994 local width=$(($COLUMNS - 2 - $startcol))
995 [ $width -lt 0 ] && width=$((78 - $startcol))
1000 if [ $startcol -gt 0 ] ; then
1001 padding=$(printf "\n%${startcol}s" " ")
1007 while [ -n "$text" ] ; do
1010 # If we already have output then arrange padding on the next line.
1011 [ -n "$out" ] && out="${out}${padding}"
1013 # Break the text at $width.
1014 out="${out}${text:0:${width}}"
1015 text="${text:${width}}"
1017 # If we have left over text then the line break may be ugly,
1018 # so let's check and try to break it on a space.
1019 if [ -n "$text" ] ; then
1020 # The 'x's stop us producing a special character like '(',
1021 # ')' or '!'. Yuck - there must be a better way.
1022 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
1023 # We didn't break on a space. Arrange for the
1024 # beginning of the broken "word" to appear on the next
1025 # line but not if it will make us loop infinitely.
1026 if [ "${orig}" != "${out##* }${text}" ] ; then
1027 text="${out##* }${text}"
1030 # Hmmm, doing that would make us loop, so add the
1031 # rest of the word from the remainder of the text
1032 # to this line and let it extend past $COLUMNS - 2.
1033 out="${out}${text%% *}"
1034 if [ "${text# *}" != "$text" ] ; then
1035 # Remember the text after the next space for next time.
1038 # No text after next space.
1043 # We broke on a space. If it will be at the beginning
1044 # of the next line then remove it.
1053 # Display usage text, trying these approaches in order.
1054 # 1. See if it all fits on one line before $COLUMNS - 2.
1055 # 2. See if splitting before the default value and indenting it
1056 # to $startcol means that nothing passes $COLUMNS - 2.
1057 # 3. Treat the message and default value as a string and just us fill_text()
1059 usage_display_text () {
1064 local width=$(($COLUMNS - 2 - $startcol))
1065 [ $width -lt 0 ] && width=$((78 - $startcol))
1067 default="(default \"$default\")"
1069 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
1070 echo "${desc} ${default}"
1072 local padding=$(printf "%${startcol}s" " ")
1074 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
1076 echo "${padding}${default}"
1078 fill_text $startcol "${desc} ${default}"
1083 # Display usage information for long config options.
1084 usage_smart_display () {( # sub-shell for local declaration of defconf()
1088 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
1090 printf " --%-25s " "${longopt}=${3}"
1092 usage_display_text $startcol "$4" "$2"
1099 # Display usage information for long config options.
1100 usage_config_options (){
1101 usage_smart_display load_config
1105 local releases=$(cd $installdir/releases && echo *.release)
1106 releases="${releases//.release}"
1107 releases="${releases// /\", \"}"
1108 echo "\"$releases\""
1113 shift # subsequent args are passed to release file
1115 # This simply loads an extra config file from $installdir/releases
1116 f="${installdir}/releases/${release}.release"
1117 if [ -r "$f" ] ; then
1120 f="${installdir}/releases/${release%%-*}.release"
1121 if [ -r "$f" ] ; then
1122 . "$f" "${release#*-}"
1124 echo "Unknown release \"${release}\" specified to --with-release"
1125 printf "%-25s" "Supported releases are: "
1126 fill_text 25 "$(list_releases)"
1133 has_public_addresses_DEFAULT ()
1138 # Build public address configuration.
1139 # * 1st public IP: unless specified, last octet is $FIRSTIP + $PUBLIC_IP_OFFSET
1140 # * Excluded nodes: unless specified via comma-separated list of IP offsets,
1141 # nodes are excluded via their node types
1142 # * Number of public addresses per interface is either specified or $NUMNODES.
1143 make_public_addresses () {
1144 local firstip="${1:-$(($FIRSTIP + $PUBLIC_IP_OFFSET))}"
1145 local excluded_nodes="$2"
1146 local num_addrs="${3:-${NUMNODES}}"
1148 # For delimiting matches.
1149 excluded_nodes="${excluded_nodes:+,}${excluded_nodes}${excluded_nodes:+,}"
1151 excluded_nodes="${excluded_nodes// /}"
1153 make_public_addresses_for_node ()
1155 [ "$ctdb_node" = 1 ] || return 0
1157 echo "[/etc/ctdb/public_addresses:${name}.${DOMAIN}]"
1159 if [ -n "$excluded_nodes" -a \
1160 "${excluded_nodes/,${ip_offset},}" = "$excluded_nodes" ] ||
1161 ([ -z "$excluded_nodes" ] &&
1162 call_func has_public_addresses "$node_type") ; then
1165 for e in "1" "2" ; do
1166 for i in $(seq $firstip $(($firstip + $num_addrs - 1))) ; do
1167 if [ $i -gt 254 ] ; then
1168 die "make_public_addresses: octet > 254 - consider setting PUBLIC_IP_OFFSET"
1170 printf "\t${IPBASE}.${e}.${i}/24 eth${e}\n"
1176 hack_all_nodes_with make_public_addresses_for_node
1179 ######################################################################
1183 ############################
1184 # parse command line options
1185 long_opts=$(getopt_config_options)
1186 getopt_output=$(getopt -n autocluster -o "c:e:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1187 [ $? != 0 ] && usage
1189 use_default_config=true
1191 # We do 2 passes of the options. The first time we just handle usage
1192 # and check whether -c is being used.
1193 eval set -- "$getopt_output"
1196 -c) shift 2 ; use_default_config=false ;;
1198 --) shift ; break ;;
1199 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1201 -h|--help) usage ;; # Usage should be shown here for real defaults.
1202 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1203 *) usage ;; # shouldn't happen, so this is reasonable.
1208 $use_default_config && [ -r "$config" ] && . "$config"
1210 eval set -- "$getopt_output"
1214 # force at least ./local_file to avoid accidental file from $PATH
1215 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1216 -e) eval "$2" ; exit ;;
1221 -x) set -x; shift ;;
1222 --dump) dump_config ;;
1223 --) shift ; break ;;
1224 -h|--help) usage ;; # Redundant.
1226 # Putting --opt1|opt2|... into a variable and having case
1227 # match against it as a pattern doesn't work. The | is
1228 # part of shell syntax, so we need to do this. Look away
1229 # now to stop your eyes from bleeding! :-)
1230 x=",${long_opts}" # Now each option is surrounded by , and :
1231 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1232 # Our option, $1, surrounded by , and : was in $x, so is legal.
1233 setconf_longopt "$1" "$2"; shift 2
1238 *) usage ;; # shouldn't happen, so this is reasonable.
1246 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1249 # check for needed programs
1250 check_command expect
1251 if [ "$SYSTEM_DISK_FORMAT" != "raw" ] ; then
1252 check_command $QEMU_NBD
1253 check_command nbd-client
1256 [ $# -lt 1 ] && usage
1267 [ $# != 0 ] && usage
1271 [ $# != 1 ] && usage
1275 [ $# != 2 ] && usage
1276 create_one_node "$1" "$2"
1284 [ $# != 1 ] && usage
1288 [ $# != 0 ] && usage