blob: 8ddc4baf6f344a9c7e14986d8f1f0c97c651b4e2 [file] [log] [blame]
Junxiao Shi439d9722015-03-20 15:08:44 -07001has() {
Davide Pesavento956ac312016-09-20 19:11:30 +02002 local saved_xtrace
3 [[ $- == *x* ]] && saved_xtrace=-x || saved_xtrace=+x
4 set +x
5
Junxiao Shi439d9722015-03-20 15:08:44 -07006 local p=$1
7 shift
Davide Pesavento956ac312016-09-20 19:11:30 +02008 local i ret=1
9 for i in "$@"; do
10 if [[ "${i}" == "${p}" ]]; then
11 ret=0
12 break
13 fi
Junxiao Shi439d9722015-03-20 15:08:44 -070014 done
Davide Pesavento956ac312016-09-20 19:11:30 +020015
16 set ${saved_xtrace}
17 return ${ret}
Junxiao Shi439d9722015-03-20 15:08:44 -070018}
Davide Pesavento3f2f4862018-09-11 17:56:55 -040019
20sudo_preserve_env() {
21 local saved_xtrace
22 [[ $- == *x* ]] && saved_xtrace=-x || saved_xtrace=+x
23 set +x
24
25 local vars=()
26 while [[ $# -gt 0 ]]; do
27 local arg=$1
28 shift
29 case ${arg} in
30 --) break ;;
31 *) vars+=("${arg}=${!arg}") ;;
32 esac
33 done
34
35 set ${saved_xtrace}
36 sudo env "${vars[@]}" "$@"
37}