1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1
2#
3# Copyright (c) 2012 Ron McDowell
4# Copyright (c) 2012-2014 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
--- 11 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 264840 2014-04-23 22:04:04Z 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}}
--- 111 unchanged lines hidden (view full) ---
148# Initialize debugging. Truncates $debugFile to zero bytes if set.
149#
150f_debug_init()
151{
152 #
153 # Process stored command-line arguments
154 #
155 set -- $ARGV
156 local OPTIND OPTARG flag
157 f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
158 "$ARGV" "$GETOPTS_STDARGS"
159 while getopts "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" flag \
160 > /dev/null; do
161 case "$flag" in
162 d) debug=1 ;;
163 D) debugFile="$OPTARG" ;;
164 esac
--- 628 unchanged lines hidden (view full) ---
793 #
794 # When a custom init(8) performs an exec(3) to invoke a shell script,
795 # PID 1 becomes sh(1) and $PPID is set to 1 in the executed script.
796 #
797 [ ${PPID:-0} -eq 1 ] # Return status
798}
799
800# f_mounted $local_directory
801# f_mounted -b $device
802#
803# Return success if a filesystem is mounted on a particular directory. If `-b'
804# is present, instead check that the block device (or a partition thereof) is
805# mounted.
806#
807f_mounted()
808{
809 local OPTIND OPTARG flag use_device=
810 while getopts b flag; do
811 case "$flag" in
812 b) use_device=1 ;;
813 esac
814 done
815 shift $(( $OPTIND - 1 ))
816 if [ "$use_device" ]; then
817 local device="$1"
818 mount | grep -Eq \
819 "^$device([[:space:]]|p[0-9]|s[0-9]|\.nop|\.eli)"
820 else
821 [ -d "$dir" ] || return $FAILURE
822 mount | grep -Eq " on $dir \([^)]+\)$"
823 fi
824 # Return status is that of last grep(1)
825}
826
827# f_eval_catch [-de] [-k $var_to_set] $funcname $utility \
828# $format [$arguments ...]
829#
830# Silently evaluate a command in a sub-shell and test for error. If debugging
831# is enabled a copy of the command and its output is sent to debug (either
832# stdout or file depending on environment). If an error occurs, output of the
--- 68 unchanged lines hidden (view full) ---
901#
902f_eval_catch()
903{
904 local __no_dialog= __show_err= __var_to_set=
905
906 #
907 # Process local function arguments
908 #
909 local OPTIND OPTARG __flag
910 while getopts "dek:" __flag > /dev/null; do
911 case "$__flag" in
912 d) __no_dialog=1 ;;
913 e) __show_err=1 ;;
914 k) __var_to_set="$OPTARG" ;;
915 esac
916 done
917 shift $(( $OPTIND - 1 ))
--- 106 unchanged lines hidden ---
2#
3# Copyright (c) 2012 Ron McDowell
4# Copyright (c) 2012-2014 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
--- 11 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 264840 2014-04-23 22:04:04Z 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}}
--- 111 unchanged lines hidden (view full) ---
148# Initialize debugging. Truncates $debugFile to zero bytes if set.
149#
150f_debug_init()
151{
152 #
153 # Process stored command-line arguments
154 #
155 set -- $ARGV
156 local OPTIND OPTARG flag
157 f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
158 "$ARGV" "$GETOPTS_STDARGS"
159 while getopts "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" flag \
160 > /dev/null; do
161 case "$flag" in
162 d) debug=1 ;;
163 D) debugFile="$OPTARG" ;;
164 esac
--- 628 unchanged lines hidden (view full) ---
793 #
794 # When a custom init(8) performs an exec(3) to invoke a shell script,
795 # PID 1 becomes sh(1) and $PPID is set to 1 in the executed script.
796 #
797 [ ${PPID:-0} -eq 1 ] # Return status
798}
799
800# f_mounted $local_directory
801# f_mounted -b $device
802#
803# Return success if a filesystem is mounted on a particular directory. If `-b'
804# is present, instead check that the block device (or a partition thereof) is
805# mounted.
806#
807f_mounted()
808{
809 local OPTIND OPTARG flag use_device=
810 while getopts b flag; do
811 case "$flag" in
812 b) use_device=1 ;;
813 esac
814 done
815 shift $(( $OPTIND - 1 ))
816 if [ "$use_device" ]; then
817 local device="$1"
818 mount | grep -Eq \
819 "^$device([[:space:]]|p[0-9]|s[0-9]|\.nop|\.eli)"
820 else
821 [ -d "$dir" ] || return $FAILURE
822 mount | grep -Eq " on $dir \([^)]+\)$"
823 fi
824 # Return status is that of last grep(1)
825}
826
827# f_eval_catch [-de] [-k $var_to_set] $funcname $utility \
828# $format [$arguments ...]
829#
830# Silently evaluate a command in a sub-shell and test for error. If debugging
831# is enabled a copy of the command and its output is sent to debug (either
832# stdout or file depending on environment). If an error occurs, output of the
--- 68 unchanged lines hidden (view full) ---
901#
902f_eval_catch()
903{
904 local __no_dialog= __show_err= __var_to_set=
905
906 #
907 # Process local function arguments
908 #
909 local OPTIND OPTARG __flag
910 while getopts "dek:" __flag > /dev/null; do
911 case "$__flag" in
912 d) __no_dialog=1 ;;
913 e) __show_err=1 ;;
914 k) __var_to_set="$OPTARG" ;;
915 esac
916 done
917 shift $(( $OPTIND - 1 ))
--- 106 unchanged lines hidden ---