script.subr (252987) | script.subr (262895) |
---|---|
1if [ ! "$_SCRIPT_SUBR" ]; then _SCRIPT_SUBR=1 2# | 1if [ ! "$_SCRIPT_SUBR" ]; then _SCRIPT_SUBR=1 2# |
3# Copyright (c) 2012-2013 Devin Teske | 3# Copyright (c) 2012-2014 Devin Teske |
4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# | 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright --- 7 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/usr.sbin/bsdconfig/share/script.subr 252987 2013-07-07 18:51:44Z dteske $ | 27# $FreeBSD: head/usr.sbin/bsdconfig/share/script.subr 262895 2014-03-07 20:12:59Z dteske $ |
28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." script.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/media/any.subr --- 9 unchanged lines hidden (view full) --- 45 46############################################################ FUNCTIONS 47 48# f_resword_new $resword $function 49# 50# Create a new `reserved' word for scripting purposes. Reswords call pre- 51# defined functions but differ from those functions in the following ways: 52# | 28# 29############################################################ INCLUDES 30 31BSDCFG_SHARE="/usr/share/bsdconfig" 32. $BSDCFG_SHARE/common.subr || exit 1 33f_dprintf "%s: loading includes..." script.subr 34f_include $BSDCFG_SHARE/device.subr 35f_include $BSDCFG_SHARE/media/any.subr --- 9 unchanged lines hidden (view full) --- 45 46############################################################ FUNCTIONS 47 48# f_resword_new $resword $function 49# 50# Create a new `reserved' word for scripting purposes. Reswords call pre- 51# defined functions but differ from those functions in the following ways: 52# |
53# + Reswords do not take arguments but instead get all their data from 54# the environment variable namespace. | |
55# + Unless noError is set (must be non-NULL), if calling the resword 56# results in failure, the application will terminate prematurely. 57# + noError is unset after each/every resword is called. 58# 59# Reswords should not be used in bsdconfig itself (hence the name `reserved | 53# + Unless noError is set (must be non-NULL), if calling the resword 54# results in failure, the application will terminate prematurely. 55# + noError is unset after each/every resword is called. 56# 57# Reswords should not be used in bsdconfig itself (hence the name `reserved |
60# word') but instead only in scripts loaded through f_script_load()). | 58# word') but instead only in scripts loaded through f_script_load(). |
61# 62f_resword_new() 63{ 64 local resword="$1" func="$2" 65 [ "$resword" ] || return $FAILURE 66 f_dprintf "script.subr: New resWord %s -> %s" "$resword" "$func" | 59# 60f_resword_new() 61{ 62 local resword="$1" func="$2" 63 [ "$resword" ] || return $FAILURE 64 f_dprintf "script.subr: New resWord %s -> %s" "$resword" "$func" |
67 eval $resword\(\){ f_dispatch $func $resword\; } | 65 eval $resword\(\){ f_dispatch $func $resword \"\$@\"\; } |
68 RESWORDS="$RESWORDS${RESWORDS:+ }$resword" 69} 70 | 66 RESWORDS="$RESWORDS${RESWORDS:+ }$resword" 67} 68 |
71# f_dispatch $func [$resword] | 69# f_dispatch $func $resword |
72# 73# Wrapper function used by `reserved words' (reswords) to call other functions. 74# If $noError is set and non-NULL, a failure result from $func is ignored, 75# otherwise the application is prematurely terminated using f_die(). 76# 77# NOTE: $noError is unset after every call. 78# 79f_dispatch() 80{ | 70# 71# Wrapper function used by `reserved words' (reswords) to call other functions. 72# If $noError is set and non-NULL, a failure result from $func is ignored, 73# otherwise the application is prematurely terminated using f_die(). 74# 75# NOTE: $noError is unset after every call. 76# 77f_dispatch() 78{ |
81 local func="$1" resword="${2:-$1}" | 79 local func="$1" resword="$2" 80 shift 2 # func resword |
82 f_dprintf "f_dispatch: calling resword \`%s'" "$resword" | 81 f_dprintf "f_dispatch: calling resword \`%s'" "$resword" |
83 eval $func | 82 eval $func "$@" |
84 local retval=$? 85 if [ $retval -ne $SUCCESS ]; then 86 local _ignore_this_error 87 f_getvar $VAR_NO_ERROR _ignore_this_error 88 [ "$_ignore_this_error" ] || f_die $retval \ 89 "$msg_command_failed_rest_of_script_aborted" "$resword" 90 fi 91 unset $VAR_NO_ERROR --- 116 unchanged lines hidden --- | 83 local retval=$? 84 if [ $retval -ne $SUCCESS ]; then 85 local _ignore_this_error 86 f_getvar $VAR_NO_ERROR _ignore_this_error 87 [ "$_ignore_this_error" ] || f_die $retval \ 88 "$msg_command_failed_rest_of_script_aborted" "$resword" 89 fi 90 unset $VAR_NO_ERROR --- 116 unchanged lines hidden --- |