X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/34dbf787c3fa13541abc9aadcf53c23016895382..a9a07e375b798688dfe9d693577106a0c32b30c8:/include/shell.sh?ds=inline diff --git a/include/shell.sh b/include/shell.sh index 6ee0cf603..f6be6c526 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 "$@" +}