a1e5cbe66f915a0aeb7e240da20f706cdf568e13
[openwrt/staging/wigyori.git] / include / shell.sh
1 var2file() {
2 local var
3 eval "var=\"\${$1}\""
4 if [ -n "$var" ]; then echo "$var" > "$2"; fi
5 }
6
7 isset() {
8 local var
9 eval "var=\"\${$1}\""
10 [ -n "$var" ]
11 }
12
13 trapret() {(
14 local retvals="$1"; shift
15 local cmd="$1"; shift
16 for retval in $(echo $retvals); do
17 local trap_$retval=1
18 done
19 "$cmd" "$@" || {
20 local retval="$?"
21 eval "trapped=\${trap_$retval}"
22 [ -n "$trapped" ] || {
23 return $retval
24 }
25 }
26 )}
27
28 md5s() {
29 cat "$@" | (
30 md5sum 2>/dev/null ||
31 md5
32 ) | awk '{print $1}'
33 }