From 8aafb557bafaa98f325d10e4aa6c049cc850b7c2 Mon Sep 17 00:00:00 2001 From: Andy Fiddaman Date: Sun, 14 Mar 2021 21:34:25 +0000 Subject: [PATCH] Remove more bashisms in favour of POSIX constructs --- installer/config-menu | 170 ++++++++++++++------------------------ installer/dialog-tzselect | 24 ++---- installer/kayak-menu | 30 +++---- lib/dialog.sh | 16 ++-- lib/disk_help.sh | 46 +++++------ lib/hvm_help.sh | 18 ++-- lib/install_help.sh | 112 ++++++++++++------------- lib/net_help.sh | 12 +-- lib/utils.sh | 20 ++--- lib/vm.sh | 10 +-- 10 files changed, 195 insertions(+), 263 deletions(-) diff --git a/installer/config-menu b/installer/config-menu index 146e7b1..6e0114a 100755 --- a/installer/config-menu +++ b/installer/config-menu @@ -13,7 +13,7 @@ # }}} # -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # ALTROOT=/mnt @@ -40,13 +40,11 @@ echo "Reading system configuration..." SetupLog /tmp/kayak.log -dmsg() -{ +function dmsg { [ $debug -eq 1 ] && echo "$@" } -pause() -{ +function pause { echo echo "$@" echo @@ -61,7 +59,7 @@ function ask { echo "$* (y/n) \\c" read a done - [[ "$a" = [yY] ]] + [[ "$a" == [yY] ]] } function cycle { @@ -156,8 +154,7 @@ function show_text_menu { return 0 } -show_menu() -{ +function show_menu { nameref menu="$1" if [ -n "$USE_DIALOG" ]; then @@ -201,13 +198,11 @@ function remove_config { ############################################################################## # Networking -reset_dma() -{ +function reset_dma { sed -i '/^MAILNAME /d' $ALTROOT/etc/dma/dma.conf } -set_dma() -{ +function set_dma { typeset domain="$net_domain" [ -z "$domain" ] && domain=local @@ -216,8 +211,7 @@ MAILNAME $domain " $ALTROOT/etc/dma/dma.conf } -reset_hosts() -{ +function reset_hosts { sed -i '/^[^#]/d' $ALTROOT/etc/inet/hosts cat <<- EOM >> $ALTROOT/etc/inet/hosts ::1 localhost $NODENAME.local $NODENAME @@ -225,8 +219,7 @@ reset_hosts() EOM } -set_hosts() -{ +function set_hosts { typeset ip=${net_ip%/*} typeset domain="$net_domain" [ -z "$domain" ] && domain=local @@ -246,8 +239,7 @@ $ip $NODENAME.$domain $NODENAME fi } -save_networking() -{ +function save_networking { remove_config NETWORK reset_hosts reset_dma @@ -283,8 +275,7 @@ save_networking() ) >> $INITIALBOOT } -load_networking() -{ +function load_networking { net_if= net_ifmode= net_ip= @@ -311,14 +302,12 @@ load_networking() [ -z "$net_dns" ] && net_dns=1.1.1.1 } -clear_networking() -{ +function clear_networking { remove_config NETWORK load_networking } -show_networking() -{ +function show_networking { if [ ! -f $INITIALBOOT ]; then echo '' elif egrep -s -- '-T static' $INITIALBOOT; then @@ -330,14 +319,13 @@ show_networking() fi } -mkiflist() -{ +function mkiflist { # LINK MEDIA STATE SPEED DUPLEX DEVICE # vioif0 Ethernet up 1000 full vioif0 iflist=() i=0 /sbin/dladm show-phys | sed 1d | while read line; do - [[ $line = *Infiniband* ]] && continue + [[ $line == *Infiniband* ]] && continue set -- $line iflist[$i]=(link=$1 media=$2 state=$3 speed=$4 duplex=$5) ((i = i + 1)) @@ -370,8 +358,7 @@ function dcfg_interface { rm -f $tmpf } -cfg_interface() -{ +function cfg_interface { echo cat <<- EOM @@ -383,7 +370,7 @@ cfg_interface() i=0 /sbin/dladm show-phys | while read line; do - [[ $line = *Infiniband* ]] && continue + [[ $line == *Infiniband* ]] && continue if [ $i -eq 0 ]; then printf " $line\n" else @@ -410,13 +397,11 @@ cfg_interface() done } -show_interface() -{ +function show_interface { echo $net_if } -cfg_ifmode() -{ +function cfg_ifmode { if [ "$net_ifmode" = "static" ]; then net_ifmode=dhcp else @@ -424,8 +409,7 @@ cfg_ifmode() fi } -show_ifmode() -{ +function show_ifmode { if [ "$net_ifmode" = "dhcp" ]; then echo "DHCP" else @@ -605,8 +589,7 @@ function dcfg_ip { done } -cfg_ipaddress() -{ +function cfg_ipaddress { if [ "$net_ifmode" != "static" ]; then pause "IP address will be retrieved via DHCP" return @@ -647,13 +630,11 @@ cfg_ipaddress() done } -show_ipaddress() -{ +function show_ipaddress { [ "$net_ifmode" = "static" ] && echo $net_ip || echo "via DHCP" } -cfg_gateway() -{ +function cfg_gateway { if [ "$net_ifmode" != "static" ]; then pause "Gateway address will be retrieved via DHCP" return @@ -692,13 +673,11 @@ cfg_gateway() done } -show_gateway() -{ +function show_gateway { [ "$net_ifmode" = "static" ] && echo $net_gw || echo "via DHCP" } -cfg_domain() -{ +function cfg_domain { if [ "$net_ifmode" != "static" ]; then pause "Domain name will be retrieved via DHCP" return @@ -726,13 +705,11 @@ cfg_domain() done } -show_domain() -{ +function show_domain { [ "$net_ifmode" = "static" ] && echo $net_domain || echo "via DHCP" } -cfg_dns() -{ +function cfg_dns { if [ "$net_ifmode" != "static" ]; then pause "DNS servers will be retrieved via DHCP" return @@ -759,8 +736,7 @@ cfg_dns() done } -show_dns() -{ +function show_dns { [ "$net_ifmode" = "static" ] && echo $net_dns || echo "via DHCP" } @@ -799,8 +775,7 @@ network_menu=( \ ) \ ) -cfg_networking() -{ +function cfg_networking { load_networking while show_menu network_menu "network configuration"; do : @@ -810,8 +785,7 @@ cfg_networking() ############################################################################## # Create User -load_user() -{ +function load_user { user_uid= user_pass= user_pfexec= @@ -829,8 +803,7 @@ load_user() [ -z "$user_shell" ] && user_shell=/bin/ksh } -save_user() -{ +function save_user { remove_config USER [ -z "$user_uid" ] && return ( @@ -871,16 +844,14 @@ save_user() ) >> $INITIALBOOT } -remove_user() -{ +function remove_user { user_uid= remove_config USER [ -f $ALTROOT/etc/svc/profile/site/noautofs.xml ] \ && rm -f $ALTROOT/etc/svc/profile/site/noautofs.xml } -dcfg_user() -{ +function dcfg_user { load_user def=1 @@ -981,8 +952,7 @@ dcfg_user() d_msg "User $user_uid created successfully." } -cfg_user() -{ +function cfg_user { load_user if [ -n "$user_uid" ]; then @@ -1073,8 +1043,7 @@ cfg_user() save_user } -show_user() -{ +function show_user { load_user tag='' if [ -n "$user_uid" ]; then @@ -1088,8 +1057,7 @@ show_user() ############################################################################## # Set Root Password -cfg_rootpw() -{ +function cfg_rootpw { while :; do root_pass= while [ -z "$root_pass" ]; do @@ -1113,8 +1081,7 @@ cfg_rootpw() pause "The root password has been set" } -dcfg_rootpw() -{ +function dcfg_rootpw { while :; do dialog \ @@ -1144,8 +1111,7 @@ dcfg_rootpw() d_msg "The root password has been set." } -store_rootpw() -{ +function store_rootpw { typeset arg="$1" remove_config ROOTPW @@ -1158,8 +1124,7 @@ store_rootpw() } -show_rootpw() -{ +function show_rootpw { [ -f $INITIALBOOT ] && egrep -s ROOTPW $INITIALBOOT \ && echo "********" || echo "" } @@ -1167,8 +1132,7 @@ show_rootpw() ############################################################################## # Virtual Terminals -cfg_vtdaemon() -{ +function cfg_vtdaemon { if [ -f $INITIALBOOT ] && egrep -s vtdaemon $INITIALBOOT; then remove_config VTDAEMON else @@ -1188,8 +1152,7 @@ EOM fi } -show_vtdaemon() -{ +function show_vtdaemon { [ -f $INITIALBOOT ] && egrep -s VTDAEMON $INITIALBOOT \ && echo "Enabled" || echo "Disabled" } @@ -1197,8 +1160,7 @@ show_vtdaemon() ############################################################################## # Serial Console -load_console() -{ +function load_console { con_sconsole=Disabled con_baud=115200 con_dbits=8 @@ -1222,8 +1184,7 @@ load_console() fi } -save_console() -{ +function save_console { if [ "$con_sconsole" = "Disabled" ]; then rm -f $ALTROOT/boot/config rm -f $ALTROOT/boot/conf.d/serial @@ -1238,41 +1199,36 @@ save_console() return 0 } -show_sconsole() { +function show_sconsole { echo $con_sconsole } -show_console_param() { +function show_console_param { nameref param="con_$1" [ "$con_sconsole" != "Disabled" ] && echo $param || echo "---" } -show_baud() { show_console_param baud; } -show_dbits() { show_console_param dbits; } -show_parity() { show_console_param parity; } -show_sbits() { show_console_param sbits; } +function show_baud { show_console_param baud; } +function show_dbits { show_console_param dbits; } +function show_parity { show_console_param parity; } +function show_sbits { show_console_param sbits; } -cfg_sconsole() -{ +function cfg_sconsole { con_sconsole="`cycle "$con_sconsole" Disabled ttya ttyb`" } -cfg_baud() -{ +function cfg_baud { con_baud="`cycle "$con_baud" 9600 19200 38400 57600 115200`" } -cfg_dbits() -{ +function cfg_dbits { con_dbits="`cycle "$con_dbits" 7 8`" } -cfg_parity() -{ +function cfg_parity { con_parity="`cycle "$con_parity" none even odd`" } -cfg_sbits() -{ +function cfg_sbits { con_sbits="`cycle "$con_sbits" 1 2`" } @@ -1302,8 +1258,7 @@ console_menu=( \ ) \ ) -cfg_console() -{ +function cfg_console { load_console input= while show_menu console_menu "serial console configuration" $input; do @@ -1311,8 +1266,7 @@ cfg_console() done } -show_console() -{ +function show_console { if [ -f $ALTROOT/boot/conf.d/serial ]; then load_console parity=${con_parity:0:1} @@ -1325,8 +1279,7 @@ show_console() ############################################################################## # SSH Server -cfg_sshd() -{ +function cfg_sshd { if [ -f $ALTROOT/etc/svc/profile/site/nossh.xml ]; then rm -f $ALTROOT/etc/svc/profile/site/nossh.xml else @@ -1336,8 +1289,7 @@ cfg_sshd() fi } -show_sshd() -{ +function show_sshd { [ -f $ALTROOT/etc/svc/profile/site/nossh.xml ] \ && echo "Disabled" || echo "Enabled" } @@ -1345,8 +1297,7 @@ show_sshd() ############################################################################## # Extra Repo -cfg_extrarepo() -{ +function cfg_extrarepo { if egrep -s extra.omnios $ALTROOT/var/pkg/pkg5.image; then echo "Removing extra software repository..." extrarepo -off @@ -1356,8 +1307,7 @@ cfg_extrarepo() fi } -show_extrarepo() -{ +function show_extrarepo { egrep -s extra.omnios $ALTROOT/var/pkg/pkg5.image \ && echo "Enabled" || echo "Disabled" } diff --git a/installer/dialog-tzselect b/installer/dialog-tzselect index 948e1aa..281ae80 100755 --- a/installer/dialog-tzselect +++ b/installer/dialog-tzselect @@ -1,7 +1,7 @@ #!/usr/bin/ksh # # Copyright 2005 Sun Microsystems, Inc. All rights reserved. -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # # Ask the user about the time zone, and place the resulting TZ in a file # whose name is specified in the first argument. @@ -57,8 +57,7 @@ newline=' ' IFS=$newline -get_continent() -{ +function get_continent { dialog \ --colors \ --title "$INFO_LOCATION" \ @@ -89,8 +88,7 @@ get_continent() return 0 } -get_posix_tz() -{ +function get_posix_tz { # Ask the user for a POSIX TZ string. Check that it conforms. dialog \ --title "$INFO_ENTER_POSIX" \ @@ -120,8 +118,7 @@ get_posix_tz() return 0 } -get_country() -{ +function get_country { # Get list of names of countries in the continent or ocean. countries=$($AWK -F'\t' \ -v continent="$continent" \ @@ -156,7 +153,7 @@ get_country() ((c = c + 1)) done - if [[ $countries = *"$newline"* ]]; then + if [[ $countries == *"$newline"* ]]; then # If there's more than one country, ask the user which one. dialog \ --colors \ @@ -178,8 +175,7 @@ get_country() return 0 } -get_region() -{ +function get_region { # Get list of names of time zone rule regions in the country. regions=$($AWK -F'\t' \ -v country="$country" \ @@ -213,7 +209,7 @@ get_region() ((c = c + 1)) done - if [[ $regions = *"$newline"* ]]; then + if [[ $regions == *"$newline"* ]]; then # If there's one or more region, ask the user which one. dialog \ --colors \ @@ -235,8 +231,7 @@ get_region() return 0 } -build_tz() -{ +function build_tz { # Determine TZ from country and region. TZ=$($AWK -F'\t' \ -v country="$country" \ @@ -271,8 +266,7 @@ build_tz() return 0 } -check_tz() -{ +function check_tz { # Use the proposed TZ to output the current date relative to UTC. # Loop until they agree in seconds. # Give up after 8 unsuccessful tries. diff --git a/installer/kayak-menu b/installer/kayak-menu index 1d23e27..28ce94f 100755 --- a/installer/kayak-menu +++ b/installer/kayak-menu @@ -21,7 +21,7 @@ # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved. -# Copyright 2019 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # This started its life as the Caiman text-installer menu, hence the old # OpenSolaris CDDL statement. @@ -79,15 +79,13 @@ if [ -n "$USE_DIALOG" ]; then fi # Print a message if in debug mode -dmsg() -{ +function dmsg { [ $debug -eq 1 ] && echo "$@" } # If an installation has been completed, there will be a boot environment # and it will be mounted on /mnt -installed() -{ +function installed { [ -d /mnt/lib ] || return 1 beadm list -H > /dev/null 2>&1 } @@ -130,8 +128,7 @@ dmsg "klang = $klang" # Define the menu of commands and prompts -d_detecting() -{ +function d_detecting { d_info "Detecting disks, please wait..." } @@ -184,12 +181,9 @@ pi_menu_items=( \ msg_str="Halting system, please wait...") \ ) -display_text_menu() -{ +function display_text_menu { # Display the menu. stty sane - # Pick the right menu - installed && nameref menu=pi_menu_items || nameref menu=menu_items clear printf "Welcome to the OmniOS installation menu\n\n" @@ -207,10 +201,7 @@ display_text_menu() read input dummy 2>/dev/null } -display_dialog_menu() -{ - installed && nameref menu=pi_menu_items || nameref menu=menu_items - +function display_dialog_menu { typeset -a args=() for i in "${!menu[@]}"; do nameref item=menu[$i] @@ -238,16 +229,15 @@ display_dialog_menu() else input=err fi + rm -f $tmpf } -display_menu() -{ +function display_menu { [ -n "$USE_DIALOG" ] && display_dialog_menu || display_text_menu } -run_cmds() -{ +function run_cmds { if [ -n "$USE_DIALOG" -a -n "${item.dcmds}" ]; then for j in "${!item.dcmds[@]}"; do ${item.dcmds[$j]} @@ -260,6 +250,8 @@ run_cmds() } while :; do + # Pick the right menu + installed && nameref menu=pi_menu_items || nameref menu=menu_items display_menu # If no input was supplied, select the default option diff --git a/lib/dialog.sh b/lib/dialog.sh index 898e87e..5d2bae1 100644 --- a/lib/dialog.sh +++ b/lib/dialog.sh @@ -10,22 +10,20 @@ # http://www.illumos.org/license/CDDL. # }}} -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. if [ -x /kayak/bin/dialog ]; then export USE_DIALOG=1 export DIALOGRC=/kayak/etc/dialog.rc export DIALOGRELEASE="`head -1 /etc/release`" - dialog() - { + function dialog { /kayak/bin/dialog \ --backtitle "$DIALOGRELEASE" \ "$@" } - d_info() - { + function d_info { var="$*" typeset width=${#var} ((width += 5)) @@ -33,19 +31,17 @@ if [ -x /kayak/bin/dialog ]; then log "dialogue info: $@" } - d_msg() - { + function d_msg { var="$*" lines=5 - [[ "$var" = *\\n* ]] && lines=6 + [[ "$var" == *\\n* ]] && lines=6 typeset width=${#var} ((width += 5)) log "dialogue msg: $@" dialog --msgbox "$@" $lines $width } - d_centre() - { + function d_centre { line="$1" cols="${2:-79}" diff --git a/lib/disk_help.sh b/lib/disk_help.sh index 880bd7c..8143a3f 100644 --- a/lib/disk_help.sh +++ b/lib/disk_help.sh @@ -13,13 +13,13 @@ # # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved. -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # -ListDisks() { +function ListDisks { log "ListDisks starting - want '$*'" - declare -A disksize - declare -A diskname + typeset -A disksize + typeset -A diskname for rdsk in `prtconf -v | nawk -F= ' /dev_link=\/dev\/rdsk\/c.*p0/ { print $2 }'`; do disk="`echo $rdsk | sed -e 's/.*\///g; s/p0//;'`" @@ -77,7 +77,7 @@ ListDisks() { log "ListDisks ending" } -ListDisksAnd() { +function ListDisksAnd { num=`echo $1 | sed -e 's/[^,]//g;' | wc -c` ((EXPECT = num + 0)) for part in `echo $1 | sed -e 's/,/ /g;'`; do @@ -91,7 +91,7 @@ ListDisksUnique(){ done | sort | uniq | xargs } -BuildRpoolOnly() { +function BuildRpoolOnly { ztype= ztgt= disks="`ListDisksUnique $*`" @@ -110,31 +110,31 @@ BuildRpoolOnly() { || bomb "Failed to create root pool $RPOOL" } -BuildRpool() { +function BuildRpool { BuildRpoolOnly $* BuildBE } -GetTargetVolSize() { +function GetTargetVolSize { # Aim for 25% of physical memory (minimum 1G) # prtconf always reports in megabytes - local mem=`/usr/sbin/prtconf -m` - local vsize=1 + typeset mem=`/usr/sbin/prtconf -m` + typeset vsize=1 if [ "$mem" -ge 4096 ]; then - local quart=`echo "scale=1;$mem/4096" | /bin/bc` + typeset quart=`echo "scale=1;$mem/4096" | /bin/bc` vsize=`printf %0.f $quart` fi log "GetTargetVolSize: $vsize" echo $vsize } -GetRpoolFree() { - local zfsavail=`/sbin/zfs list -H -o avail $RPOOL` - local avail +function GetRpoolFree { + typeset zfsavail=`/sbin/zfs list -H -o avail $RPOOL` + typeset avail if [ "${zfsavail:(-1)}" = "G" ]; then avail=`printf %0.f ${zfsavail::-1}` elif [ "${zfsavail:(-1)}" = "T" ]; then - local gigs=`echo "scale=1;${zfsavail::-1}*1024" | /bin/bc` + typeset gigs=`echo "scale=1;${zfsavail::-1}*1024" | /bin/bc` avail=`printf %0.f $gigs` else # If we get here, there's too little space left to be usable @@ -144,12 +144,12 @@ GetRpoolFree() { echo $avail } -MakeSwapDump() { - local size=`GetTargetVolSize` - local free=`GetRpoolFree` - local totalvols= - local usable= - local savecore= +function MakeSwapDump { + typeset size=`GetTargetVolSize` + typeset free=`GetRpoolFree` + typeset totalvols= + typeset usable= + typeset savecore= slog "Creating swap and dump volumes" @@ -204,8 +204,8 @@ MakeSwapDump() { return 0 } -MakeExportHome() { - local _rpool=$1 +function MakeExportHome { + typeset _rpool=$1 slog "Creating /export/home dataset" diff --git a/lib/hvm_help.sh b/lib/hvm_help.sh index 722b730..d5d0a22 100755 --- a/lib/hvm_help.sh +++ b/lib/hvm_help.sh @@ -11,7 +11,7 @@ # http://www.illumos.org/license/CDDL. # }}} # -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # . $SRCDIR/../lib/install_help.sh 2>/dev/null @@ -19,12 +19,12 @@ . $SRCDIR/../lib/net_help.sh # Override the log function -log() { +function log { [ "$1" = "-o" ] && shift echo "$*" } -HVM_Create_Diskvol() { +function HVM_Create_Diskvol { typeset size=${1:-"8G"} typeset tag=${2:-$$} typeset root=${3:-"rpool/hvm-"} @@ -38,13 +38,13 @@ HVM_Create_Diskvol() { echo "$root$tag:$lofi" } -HVM_Destroy_Diskvol() { +function HVM_Destroy_Diskvol { typeset lofi=$1 lofiadm -d $lofi } -HVM_Build_Devtree() { +function HVM_Build_Devtree { typeset root=$1 typeset phys=$2 typeset base=$3 @@ -72,7 +72,7 @@ HVM_Build_Devtree() { } -find_zfssend() { +function find_zfssend { [ -z "$VERSION" ] && \ VERSION="`nawk 'NR == 1 { sub(/^r/, "", $3); print $3 }' \ /etc/release`" @@ -80,7 +80,7 @@ find_zfssend() { [ -f "$ZFSSEND" ] || ZFSSEND="omniosce-r$VERSION.zfs.xz" } -HVM_Image_Init() { +function HVM_Image_Init { typeset size="${1:?size}"; shift typeset rpool="${1:?rpool}"; shift typeset tag="${1:?tag}"; shift @@ -103,7 +103,7 @@ HVM_Image_Init() { SetupLog /tmp/kayak-$tag.log } -HVM_Image_Build() { +function HVM_Image_Build { typeset poolopts="${1:?poolopts}"; shift typeset zfssend="${1:?zfssend}"; shift typeset hostname="${1:-omnios}"; shift @@ -150,7 +150,7 @@ HVM_Image_Build() { Postboot "zpool reguid $RPOOL" } -HVM_Image_Finalise() { +function HVM_Image_Finalise { typeset slice="$1"; shift typeset blk="$1"; shift typeset phys="$1"; shift diff --git a/lib/install_help.sh b/lib/install_help.sh index 936f0e5..efc1356 100644 --- a/lib/install_help.sh +++ b/lib/install_help.sh @@ -15,7 +15,7 @@ # # Copyright 2017 OmniTI Computer Consulting, Inc. All rights reserved. -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # INSTALL_LOG= @@ -24,7 +24,7 @@ set -o pipefail # Open the kayak log file at the provided path and open file descriptor 4 # for output to it. -SetupLog() { +function SetupLog { [ -n "$INSTALL_LOG" ] && return INSTALL_LOG=$1 exec 4>>$INSTALL_LOG @@ -32,7 +32,7 @@ SetupLog() { # Set up logging so that log messages go to the console and that stdout/stderr # go to a log file at the provided path. -ConsoleLog() { +function ConsoleLog { [ -n "$INSTALL_LOG" ] && return exec 4>/dev/console exec 1>>$1 @@ -40,11 +40,11 @@ ConsoleLog() { INSTALL_LOG=$1 } -CopyInstallLog() { +function CopyInstallLog { [ -n "$INSTALL_LOG" ] && cp $INSTALL_LOG $ALTROOT/var/log/kayak.log } -SendInstallLog() { +function SendInstallLog { [ -n "$INSTALL_LOG" ] || return PUTURL=`echo $CONFIG | sed -e 's%/kayak/%/kayaklog/%g;'` PUTURL=`echo $PUTURL | sed -e 's%/kayak$%/kayaklog%g;'` @@ -54,23 +54,23 @@ SendInstallLog() { # Log a message to the log file. # Parameters: # -o Also output the log message to stderr -log() { +function log { [ -n "$INSTALL_LOG" ] || return - local oflag=0 + typeset -i oflag=0 [ "$1" = "-o" ] && shift && oflag=1 TS=`date +%Y/%m/%d-%H:%M:%S` echo "[$TS] $*" 1>&4 - [ $oflag -eq 1 ] && echo "[$TS] $*" 1>&2 + (( oflag == 1 )) && echo "[$TS] $*" 1>&2 } # Log a command and its output. # If you want to have the output preserved in a pipline, use pipelog() instead # Parameters: # -o Also output to stderr -logcmd() { +function logcmd { if [ "$1" = "-o" ]; then shift log -o "Running: $@" @@ -86,13 +86,13 @@ logcmd() { } # Copy stdout to the log file (for use in a pipeline) -pipelog() { +function pipelog { tee /dev/fd/4 } # Selective log. If in a dialogue environment, show the message in a popup # window, otherwise on stdout. -slog() { +function slog { if [ -n "$USE_DIALOG" ]; then log "$@" d_info "$@" @@ -101,7 +101,7 @@ slog() { fi } -bomb() { +function bomb { log -o "" log -o ====================================================== log -o "$*" @@ -120,24 +120,24 @@ bomb() { . /kayak/lib/disk_help.sh ICFILE=/tmp/_install_config -getvar() { +function getvar { log "getvar($1)" prtconf -v /devices | sed -n '/'$1'/{;n;p;}' | cut -f2 -d\' | pipelog } # Blank ROOTPW='$5$kr1VgdIt$OUiUAyZCDogH/uaxH71rMeQxvpDEY2yX.x0ZQRnmeb9' -RootPW() { +function RootPW { log "Setting root password hash to $1" ROOTPW="$1" } -SetRootPW(){ +function SetRootPW { log "Setting root password in shadow file" logcmd sed -i -e 's%^root::%root:'$ROOTPW':%' $ALTROOT/etc/shadow } -ForceDHCP(){ +function ForceDHCP { log "Forcing all interfaces into DHCP..." logcmd /sbin/ifconfig -a plumb # for the logs @@ -153,8 +153,8 @@ ForceDHCP(){ sleep 1 } -BE_Create_Root() { - local _rpool="${1:?rpool}" +function BE_Create_Root { + typeset _rpool="${1:?rpool}" log "Creating root BE" [ -z "$NO_COMPRESSION" ] && logcmd zfs set compression=on $_rpool @@ -163,12 +163,12 @@ BE_Create_Root() { logcmd zfs set mountpoint=legacy $_rpool/ROOT } -BE_Receive_Image() { - local _grab="${1:?grab}" - local _decomp="${2:?decomp}" - local _rpool="${3:?rpool}" - local _bename="${4:?bename}" - local _media="${5:?media}" +function BE_Receive_Image { + typeset _grab="${1:?grab}" + typeset _decomp="${2:?decomp}" + typeset _rpool="${3:?rpool}" + typeset _bename="${4:?bename}" + typeset _media="${5:?media}" slog "Preparing to install ZFS image" pv="pv -B 128m" @@ -186,11 +186,11 @@ BE_Receive_Image() { logcmd zfs set mountpoint=legacy $_rpool/ROOT/$_bename } -BE_Mount() { - local _rpool=${1:?rpool} - local _bename=${2:?bename} - local _root=${3:?root} - local _method${4:-beadm} +function BE_Mount { + typeset _rpool=${1:?rpool} + typeset _bename=${2:?bename} + typeset _root=${3:?root} + typeset _method${4:-beadm} slog "Mounting BE $_bename on $_root" @@ -202,10 +202,10 @@ BE_Mount() { export ALTROOT=$_root } -BE_Umount() { - local _bename=${1:?bename} - local _root=${2:?root} - local _method${3:-beadm} +function BE_Umount { + typeset _bename=${1:?bename} + typeset _root=${2:?root} + typeset _method${3:-beadm} slog "Unmounting BE $_bename" if [ "$_method" = beadm ]; then @@ -215,12 +215,12 @@ BE_Umount() { fi } -BE_SetUUID() { - local _rpool=${1:?rpool} - local _bename=${2:?bename} - local _root=${3:?root} +function BE_SetUUID { + typeset _rpool=${1:?rpool} + typeset _bename=${2:?bename} + typeset _root=${3:?root} - local uuid=`LD_LIBRARY_PATH=$_root/lib:$_root/usr/lib \ + typeset uuid=`LD_LIBRARY_PATH=$_root/lib:$_root/usr/lib \ $_root/usr/bin/uuidgen` slog "Setting BE $_bename UUID: $uuid" @@ -228,18 +228,18 @@ BE_SetUUID() { logcmd zfs set org.opensolaris.libbe:policy=static $_rpool/ROOT/$_bename } -BE_LinkMsglog() { - local _root=${1:?root} +function BE_LinkMsglog { + typeset _root=${1:?root} logcmd /usr/sbin/devfsadm -r $_root [ -L "$_root/dev/msglog" ] || \ logcmd ln -s ../devices/pseudo/sysmsg@0:msglog $_root/dev/msglog } -BuildBE() { +function BuildBE { RPOOL=${1:-rpool} - local MEDIA="$2" - local _bename=${3:-omnios} + typeset MEDIA="$2" + typeset _bename=${3:-omnios} if [ -z "$MEDIA" ]; then BOOTSRVA=`/sbin/dhcpinfo BootSrvA` @@ -268,7 +268,7 @@ BuildBE() { logcmd zfs destroy $RPOOL/ROOT/$_bename@kayak } -FetchConfig(){ +function FetchConfig { ETHER=`Ether` BOOTSRVA=`/sbin/dhcpinfo BootSrvA` CONFIG=`getvar install_config` @@ -293,9 +293,9 @@ FetchConfig(){ return 1 } -MakeBootable(){ - local _rpool=${1:-rpool} - local _bename=${2:-omnios} +function MakeBootable { + typeset _rpool=${1:-rpool} + typeset _bename=${2:-omnios} slog "Making boot environment bootable" logcmd zpool set bootfs=$_rpool/ROOT/$_bename $_rpool # Must do beadm activate first on the off chance we're bootstrapping from @@ -309,7 +309,7 @@ MakeBootable(){ return 0 } -SetHostname() { +function SetHostname { log "Setting hostname: $1" logcmd /bin/hostname "$1" echo "$1" > $ALTROOT/etc/nodename @@ -320,7 +320,7 @@ SetHostname() { EOM } -AutoHostname() { +function AutoHostname { suffix=$1 macaddr=`/sbin/ifconfig -a | /usr/bin/nawk ' /UP/ && $2 !~ /LOOPBACK/ { iface = $1 } @@ -332,17 +332,17 @@ AutoHostname() { SetHostname $macaddr$suffix } -SetTimezone() { +function SetTimezone { log "Setting timezone: $1" logcmd sed -i -e "s:^TZ=.*:TZ=$1:" $ALTROOT/etc/default/init } -SetLang() { +function SetLang { log "Setting language: $1" logcmd sed -i -e "s:^LANG=.*:LANG=$1:" $ALTROOT/etc/default/init } -SetKeyboardLayout() { +function SetKeyboardLayout { # Put the new keyboard layout ($1) in # "setprop keyboard-layout " in the newly-installed root's # /boot/solaris/bootenv.rc (aka. eeprom(1M) storage for amd64/i386). @@ -357,7 +357,7 @@ SetKeyboardLayout() { Postboot "/usr/sbin/svcadm restart system/keymap:default" } -ApplyChanges() { +function ApplyChanges { SetRootPW [ -L $ALTROOT/etc/svc/profile/generic.xml ] || \ logcmd ln -s generic_limited_net.xml \ @@ -381,13 +381,13 @@ ApplyChanges() { return 0 } -Postboot() { +function Postboot { [ -f $ALTROOT/.initialboot ] || touch $ALTROOT/.initialboot log "Postboot - '$*'" echo "$*" >> $ALTROOT/.initialboot } -Reboot() { +function Reboot { # This is an awful hack... we already setup bootadm # and we've likely deleted enough of the userspace that this # can't run successfully... The easiest way to skip it is to @@ -399,7 +399,7 @@ Reboot() { logcmd reboot } -RunInstall(){ +function RunInstall { FetchConfig || bomb "Could not fetch kayak config for target" # Set RPOOL if it wasn't done so already. We need it set. RPOOL=${RPOOL:-rpool} diff --git a/lib/net_help.sh b/lib/net_help.sh index 36f61cb..4ff0ad7 100644 --- a/lib/net_help.sh +++ b/lib/net_help.sh @@ -13,13 +13,13 @@ # }}} # # Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved. -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. # # Returns a mac address as 12 hex characters, upper-case, from the first # non-loopback interface in the system. -Ether() { - local mac="`/sbin/dladm show-phys -m -p -o ADDRESS | \ +function Ether { + typeset mac="`/sbin/dladm show-phys -m -p -o ADDRESS | \ /bin/tr '[:lower:]' '[:upper:]' | \ sed ' s/^/ 0/g @@ -33,7 +33,7 @@ Ether() { echo $mac } -UseDNS() { +function UseDNS { log "UseDNS: $*" server=$1; shift @@ -42,7 +42,7 @@ UseDNS() { SetDNS $server } -EnableDNS() { +function EnableDNS { log "EnableDNS: $*" domain=$1 @@ -55,7 +55,7 @@ EOF logcmd cp $ALTROOT/etc/nsswitch.{dns,conf} } -SetDNS() { +function SetDNS { log "SetDNS: $*" /usr/bin/egrep -s 'files dns' $ALTROOT/etc/nsswitch.conf || EnableDNS diff --git a/lib/utils.sh b/lib/utils.sh index 0ea0a8a..3f1a88b 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -10,13 +10,13 @@ # http://www.illumos.org/license/CDDL. # }}} -# Copyright 2019 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. -check_hostname() { +function check_hostname { echo $1 | egrep -s '^[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]$' } -t_prompt_hostname() { +function t_prompt_hostname { NEWHOST="$1" while [ -n "$NEWHOST" ]; do HOSTNAME="$NEWHOST" @@ -29,7 +29,7 @@ t_prompt_hostname() { done } -d_prompt_hostname() { +function d_prompt_hostname { HOSTNAME="$1" while :; do dialog \ @@ -44,30 +44,30 @@ d_prompt_hostname() { done } -prompt_hostname() { +function prompt_hostname { [ -n "$USE_DIALOG" ] && d_prompt_hostname "$@" || t_prompt_hostname "$@" log "Selected hostname: $HOSTNAME" } -t_prompt_timezone() { +function t_prompt_timezone { tzselect |& tee /tmp/tz.$$ TZ="`tail -1 /tmp/tz.$$`" rm -f /tmp/tz.$$ } -d_prompt_timezone() { +function d_prompt_timezone { # Select a timezone. /kayak/installer/dialog-tzselect /tmp/tz.$$ TZ="`tail -1 /tmp/tz.$$`" rm -f /tmp/tz.$$ } -prompt_timezone() { +function prompt_timezone { [ -n "$USE_DIALOG" ] && d_prompt_timezone "$@" || t_prompt_timezone "$@" log "Selected timezone: $TZ" } -runpkg() { +function runpkg { log "runpkg: $*" LD_LIBRARY_PATH=$ALTROOT/usr/lib/amd64 \ PYTHONPATH=$ALTROOT/usr/lib/python3.9/vendor-packages \ @@ -76,7 +76,7 @@ runpkg() { sed -i '/^last_uuid/d' $ALTROOT/var/pkg/pkg5.image } -extrarepo() { +function extrarepo { log "extrarepo $1" if [ "$1" = "-off" ]; then runpkg unset-publisher extra.omnios diff --git a/lib/vm.sh b/lib/vm.sh index e98c861..df04f97 100644 --- a/lib/vm.sh +++ b/lib/vm.sh @@ -10,27 +10,27 @@ # http://www.illumos.org/license/CDDL. # }}} -# Copyright 2020 OmniOS Community Edition (OmniOSce) Association. +# Copyright 2021 OmniOS Community Edition (OmniOSce) Association. -hypervisor() { +function hypervisor { cpuid | grep '^Hypervisor vendor string:' | cut -d"'" -f2 } -vm_vmware() { +function vm_vmware { log "Installing open-vm-tools package..." runpkg install --no-refresh --no-index \ -g /.cdrom/image/p5p/vmware.p5p open-vm-tools cp /kayak/etc/vmware.xml $ALTROOT/etc/svc/profile/site/ } -vm_azure() { +function vm_azure { log "Installing azure package..." runpkg install --no-refresh --no-index \ -g /.cdrom/image/p5p/azure.p5p azure-agent cp /kayak/etc/azure.xml $ALTROOT/etc/svc/profile/site/ } -setupvm() { +function setupvm { case `hypervisor` in bhyve*) ;; KVM*) ;;