Skip to content

Commit

Permalink
Remove more bashisms in favour of POSIX constructs
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Mar 14, 2021
1 parent 0a961e4 commit 8aafb55
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 263 deletions.
170 changes: 60 additions & 110 deletions installer/config-menu

Large diffs are not rendered by default.

24 changes: 9 additions & 15 deletions installer/dialog-tzselect
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -57,8 +57,7 @@ newline='
'
IFS=$newline

get_continent()
{
function get_continent {
dialog \
--colors \
--title "$INFO_LOCATION" \
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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" \
Expand Down Expand Up @@ -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 \
Expand All @@ -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" \
Expand Down Expand Up @@ -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 \
Expand All @@ -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" \
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 11 additions & 19 deletions installer/kayak-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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..."
}

Expand Down Expand Up @@ -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"
Expand All @@ -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]
Expand Down Expand Up @@ -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]}
Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions lib/dialog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,38 @@
# 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))
dialog --infobox "$@" 3 $width
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}"

Expand Down
46 changes: 23 additions & 23 deletions lib/disk_help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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//;'`"
Expand Down Expand Up @@ -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
Expand All @@ -91,7 +91,7 @@ ListDisksUnique(){
done | sort | uniq | xargs
}

BuildRpoolOnly() {
function BuildRpoolOnly {
ztype=
ztgt=
disks="`ListDisksUnique $*`"
Expand All @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -204,8 +204,8 @@ MakeSwapDump() {
return 0
}

MakeExportHome() {
local _rpool=$1
function MakeExportHome {
typeset _rpool=$1

slog "Creating /export/home dataset"

Expand Down
Loading

0 comments on commit 8aafb55

Please sign in to comment.