X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/f52d66ff00b24111f87c274d3d7085ef2e1d27b1..c9909eaed1e1cc3dc4fa1d657feef1edc535029e:/include/shell.sh?ds=sidebyside diff --git a/include/shell.sh b/include/shell.sh index 6ee0cf603..634beedce 100644 --- a/include/shell.sh +++ b/include/shell.sh @@ -13,3 +13,25 @@ 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() { + cat "$@" | ( + md5sum 2>/dev/null || + md5 + ) | awk '{print $1}' +}