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