Deleted Added
full compact
common.subr (245402) common.subr (247280)
1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1
2#
3# Copyright (c) 2012 Ron McDowell
1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1
2#
3# Copyright (c) 2012 Ron McDowell
4# Copyright (c) 2012 Devin Teske
4# Copyright (c) 2012-2013 Devin Teske
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# $FreeBSD: head/usr.sbin/bsdconfig/share/common.subr 245402 2013-01-14 01:15:25Z dteske $
28# $FreeBSD: head/usr.sbin/bsdconfig/share/common.subr 247280 2013-02-25 19:55:32Z dteske $
29#
30############################################################ CONFIGURATION
31
32#
33# Default file descriptors to link to stdout/stderr for passthru allowing
34# redirection within a sub-shell to bypass directly to the terminal.
35#
36: ${TERMINAL_STDOUT_PASSTHRU:=3}}

--- 85 unchanged lines hidden (view full) ---

122# Returns error status if the requested variable ($var_to_get) is not set.
123#
124# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
125# standard output for capturing in a sub-shell (which is less-recommended
126# because of performance degredation; for example, when called in a loop).
127#
128f_getvar()
129{
29#
30############################################################ CONFIGURATION
31
32#
33# Default file descriptors to link to stdout/stderr for passthru allowing
34# redirection within a sub-shell to bypass directly to the terminal.
35#
36: ${TERMINAL_STDOUT_PASSTHRU:=3}}

--- 85 unchanged lines hidden (view full) ---

122# Returns error status if the requested variable ($var_to_get) is not set.
123#
124# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
125# standard output for capturing in a sub-shell (which is less-recommended
126# because of performance degredation; for example, when called in a loop).
127#
128f_getvar()
129{
130 local var_to_get="$1" var_to_set="$2"
131 [ "$var_to_set" ] || local value
132 eval ${var_to_set:-value}=\"\${$var_to_get}\"
133 eval [ \"\${$var_to_get+set}\" ]
134 local retval=$?
130 local __var_to_get="$1" __var_to_set="$2"
131 [ "$__var_to_set" ] || local value
132 eval ${__var_to_set:-value}=\"\${$__var_to_get}\"
133 eval [ \"\${$__var_to_get+set}\" ]
134 local __retval=$?
135 eval f_dprintf '"f_getvar: var=[%s] value=[%s] r=%u"' \
135 eval f_dprintf '"f_getvar: var=[%s] value=[%s] r=%u"' \
136 \"\$var_to_get\" \"\$${var_to_set:-value}\" \$retval
137 [ "$var_to_set" ] || { [ "$value" ] && echo "$value"; }
138 return $retval
136 \"\$__var_to_get\" \"\$${__var_to_set:-value}\" \$__retval
137 [ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; }
138 return $__retval
139}
140
141# f_die [ $status [ $fmt [ $opts ... ]]]
142#
143# Abruptly terminate due to an error optionally displaying a message in a
144# dialog box using printf(1) syntax.
145#
146f_die()

--- 422 unchanged lines hidden (view full) ---

569 local indexdir="${indexfile%/*}"
570 [ "$indexdir" != "$indexfile" ] || indexdir="."
571 command="$indexdir/$command"
572 esac
573
574 echo "$command"
575}
576
139}
140
141# f_die [ $status [ $fmt [ $opts ... ]]]
142#
143# Abruptly terminate due to an error optionally displaying a message in a
144# dialog box using printf(1) syntax.
145#
146f_die()

--- 422 unchanged lines hidden (view full) ---

569 local indexdir="${indexfile%/*}"
570 [ "$indexdir" != "$indexfile" ] || indexdir="."
571 command="$indexdir/$command"
572 esac
573
574 echo "$command"
575}
576
577# f_running_as_init
578#
579# Returns true if running as init(1).
580#
581f_running_as_init()
582{
583 #
584 # When a custom init(8) performs an exec(3) to invoke a shell script,
585 # PID 1 becomes sh(1) and $PPID is set to 1 in the executed script.
586 #
587 [ ${PPID:-0} -eq 1 ] # Return status
588}
589
590# f_mounted $local_directory
591#
592# Return success if a filesystem is mounted on a particular directory.
593#
594f_mounted()
595{
596 local dir="$1"
597 [ -d "$dir" ] || return $FAILURE
598 mount | grep -Eq " on $dir \([^)]+\)$"
599}
600
577############################################################ MAIN
578
579#
580# Trap signals so we can recover gracefully
581#
582trap 'f_interrupt' SIGINT
583trap 'f_die' SIGTERM SIGPIPE SIGXCPU SIGXFSZ \
584 SIGFPE SIGTRAP SIGABRT SIGSEGV

--- 41 unchanged lines hidden ---
601############################################################ MAIN
602
603#
604# Trap signals so we can recover gracefully
605#
606trap 'f_interrupt' SIGINT
607trap 'f_die' SIGTERM SIGPIPE SIGXCPU SIGXFSZ \
608 SIGFPE SIGTRAP SIGABRT SIGSEGV

--- 41 unchanged lines hidden ---