X-Git-Url: http://git.ozo.com/?p=openwrt-10.03%2F.git;a=blobdiff_plain;f=include%2Fshell.sh;h=634beedcef3e17d351f440a765c251ae16f50737;hp=6ee0cf6030ac5e0a71d7be1c2438c58ee9724caf;hb=391eb6e69c09d9f107b8c30a91c63dce37820043;hpb=34dbf787c3fa13541abc9aadcf53c23016895382 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}' +}