common.subr (247280) | common.subr (249746) |
---|---|
1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1 2# 3# Copyright (c) 2012 Ron McDowell 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 --- 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# | 1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1 2# 3# Copyright (c) 2012 Ron McDowell 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 --- 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 247280 2013-02-25 19:55:32Z dteske $ | 28# $FreeBSD: head/usr.sbin/bsdconfig/share/common.subr 249746 2013-04-22 05:02:34Z 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}} --- 20 unchanged lines hidden (view full) --- 57 58# 59# Operating environment details 60# 61export UNAME_S="$(uname -s)" # Operating System (i.e. FreeBSD) 62export UNAME_P="$(uname -p)" # Processor Architecture (i.e. i386) 63export UNAME_R="$(uname -r)" # Release Level (i.e. X.Y-RELEASE) 64 | 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}} --- 20 unchanged lines hidden (view full) --- 57 58# 59# Operating environment details 60# 61export UNAME_S="$(uname -s)" # Operating System (i.e. FreeBSD) 62export UNAME_P="$(uname -p)" # Processor Architecture (i.e. i386) 63export UNAME_R="$(uname -r)" # Release Level (i.e. X.Y-RELEASE) 64 |
65# 66# Default behavior is to call f_debug_init() automatically when loaded. 67# 68: ${DEBUG_SELF_INITIALIZE=1} 69 |
|
65############################################################ FUNCTIONS 66 67# f_dprintf $fmt [ $opts ... ] 68# 69# Sensible debug function. Override in ~/.bsdconfigrc if desired. 70# See /usr/share/examples/bsdconfig/bsdconfigrc for example. 71# 72# If $debug is set and non-NULL, prints DEBUG info using printf(1) syntax: --- 8 unchanged lines hidden (view full) --- 81 case "$debugFile" in ""|+*) 82 printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1} 83 esac 84 [ "${debugFile#+}" ] && 85 printf "DEBUG: $fmt${fmt:+\n}" "$@" >> "${debugFile#+}" 86 return $SUCCESS 87} 88 | 70############################################################ FUNCTIONS 71 72# f_dprintf $fmt [ $opts ... ] 73# 74# Sensible debug function. Override in ~/.bsdconfigrc if desired. 75# See /usr/share/examples/bsdconfig/bsdconfigrc for example. 76# 77# If $debug is set and non-NULL, prints DEBUG info using printf(1) syntax: --- 8 unchanged lines hidden (view full) --- 86 case "$debugFile" in ""|+*) 87 printf "DEBUG: $fmt${fmt:+\n}" "$@" >&${TERMINAL_STDOUT_PASSTHRU:-1} 88 esac 89 [ "${debugFile#+}" ] && 90 printf "DEBUG: $fmt${fmt:+\n}" "$@" >> "${debugFile#+}" 91 return $SUCCESS 92} 93 |
94# f_debug_init 95# 96# Initialize debugging. Truncates $debugFile to zero bytes if set. 97# 98f_debug_init() 99{ 100 # 101 # Process stored command-line arguments 102 # 103 ( set -- "$ARGV" 104 while getopts d flag > /dev/null; do 105 case "$flag" in 106 d) true; exit;; 107 \?) continue;; 108 esac 109 done 110 false 111 ) && debug=1 112 debugFile=$( set -- "$ARGV" 113 while getopts D flag > /dev/null; do 114 case "$flag" in 115 D) echo "$OPTARG";; 116 \?) continue;; 117 esac 118 done 119 ) 120 121 # 122 # Make debugging persistant if set 123 # 124 [ "$debug" ] && export debug 125 126 # 127 # Truncate the debug file upon. Note that we will trim a leading plus 128 # (`+') from the value of debugFile to support persistant meaning that 129 # f_dprintf() should print both to standard output and $debugFile 130 # (minus the leading plus, of course). 131 # 132 local _debug_file="${debugFile#+}" 133 if [ "$_debug_file" ]; then 134 if ( umask 022 && :> "$_debug_file" ); then 135 f_dprintf "Successfully initialized debugFile \`%s'" \ 136 "$_debug_file" 137 [ "${debug+set}" ] || 138 debug=1 # turn debugging on if not set 139 else 140 unset debugFile 141 f_dprintf "Unable to initialize debugFile \`%s'" \ 142 "$_debug_file" 143 fi 144 fi 145} 146 |
|
89# f_err $fmt [ $opts ... ] 90# 91# Print a message to stderr (fd=2). 92# 93f_err() 94{ 95 printf "$@" >&${TERMINAL_STDERR_PASSTHRU:-2} 96} --- 513 unchanged lines hidden (view full) --- 610 611# 612# Clone terminal stdout/stderr so we can redirect to it from within sub-shells 613# 614eval exec $TERMINAL_STDOUT_PASSTHRU\>\&1 615eval exec $TERMINAL_STDERR_PASSTHRU\>\&2 616 617# | 147# f_err $fmt [ $opts ... ] 148# 149# Print a message to stderr (fd=2). 150# 151f_err() 152{ 153 printf "$@" >&${TERMINAL_STDERR_PASSTHRU:-2} 154} --- 513 unchanged lines hidden (view full) --- 668 669# 670# Clone terminal stdout/stderr so we can redirect to it from within sub-shells 671# 672eval exec $TERMINAL_STDOUT_PASSTHRU\>\&1 673eval exec $TERMINAL_STDERR_PASSTHRU\>\&2 674 675# |
618# Make debugging persistant if set | 676# Self-initialize unless requested otherwise |
619# | 677# |
620[ "$debug" ] && export debug | 678f_dprintf "%s: DEBUG_SELF_INITIALIZE=[%s]" \ 679 dialog.subr "$DEBUG_SELF_INITIALIZE" 680case "$DEBUG_SELF_INITIALIZE" in 681""|0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;; 682*) f_debug_init 683esac |
621 622# | 684 685# |
623# Truncate the debug file upon initialization (now). Note that we will trim a 624# leading plus (`+') from the value of debugFile to support persistant meaning 625# that f_dprintf() should print both to standard output and $debugFile (minus 626# the leading plus, of course). 627# 628_debug_file="${debugFile#+}" 629if [ "$_debug_file" ]; then 630 if ( umask 022 && :> "$_debug_file" ); then 631 f_dprintf "Successfully initialized debugFile \`%s'" \ 632 "$_debug_file" 633 else 634 unset debugFile 635 f_dprintf "Unable to initialize debugFile \`%s'" \ 636 "$_debug_file" 637 fi 638fi 639unset _debug_file 640 641# | |
642# Log our operating environment for debugging purposes 643# 644f_dprintf "UNAME_S=[%s] UNAME_P=[%s] UNAME_R=[%s]" \ 645 "$UNAME_S" "$UNAME_P" "$UNAME_R" 646 647f_dprintf "%s: Successfully loaded." common.subr 648 649fi # ! $_COMMON_SUBR | 686# Log our operating environment for debugging purposes 687# 688f_dprintf "UNAME_S=[%s] UNAME_P=[%s] UNAME_R=[%s]" \ 689 "$UNAME_S" "$UNAME_P" "$UNAME_R" 690 691f_dprintf "%s: Successfully loaded." common.subr 692 693fi # ! $_COMMON_SUBR |