X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=include%2Fshell.sh;h=f6be6c526f26fb489cc660d7201bce3c3a1117b7;hp=6ee0cf6030ac5e0a71d7be1c2438c58ee9724caf;hb=065091e0152a13dab298f115973aebdf589d724f;hpb=60c1f0f64d23003a19a07d6b9638542130f6641d diff --git a/include/shell.sh b/include/shell.sh index 6ee0cf6030..f6be6c526f 100644 --- a/include/shell.sh +++ b/include/shell.sh @@ -13,3 +13,22 @@ isset() { eval "var=\"\${$1}\"" [ -n "$var" ] } + +trapret() {( + local retvals="$1"; shift + local cmd="$1"; shift + for retval in $(echo $retvals); do + local trap_$retval=1 + done + "$cmd" "$@" || { + local retval="$?" + eval "trapped=\${trap_$retval}" + [ -n "$trapped" ] || { + return $retval + } + } +)} + +md5s() { + which md5sum 2>&1 >/dev/null && md5sum "$@" | awk '{print $1}' || md5 "$@" +}