-
Notifications
You must be signed in to change notification settings - Fork 26
/
DOT.zshrc.DOAS.SUDO
56 lines (51 loc) · 1002 Bytes
/
DOT.zshrc.DOAS.SUDO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
SUDO_WHICH=0
SUDO=0
DOAS_WHICH=0
DOAS=1
ROOT=0
# CHECK doas(8) WITH which(1)
if which doas 1> /dev/null 2> /dev/null
then
DOAS_WHICH=1
else
DOAS_WHICH=0
fi
# CHECK sudo(8) WITH which(1)
if which sudo 1> /dev/null 2> /dev/null
then
SUDO_WHICH=1
else
SUDO_WHICH=0
fi
# CHECK USER WITH whoami(1)
if [ "$( whoami )" = "root" ]
then
ROOT=1
fi
# CHOOSE ONE FROM doas(8) AND sudo(8)
if [ ${DOAS_WHICH} -eq 1 -o ${SUDO_WHICH} -eq 1 ]
then
if [ ${DOAS} -eq 0 -a ${SUDO} -eq 1 -a ${SUDO_WHICH} -eq 1 ]
then
CMD=sudo
alias doas=sudo
elif [ ${DOAS} -eq 1 -a ${SUDO} -eq 0 -a ${DOAS_WHICH} -eq 1 ]
then
CMD=doas
alias sudo=doas
elif [ ${DOAS} -eq 1 -a ${SUDO} -eq 1 -a ${DOAS_WHICH} -eq 1 ]
then
CMD=doas
alias sudo=doas
fi
elif [ ${ROOT} -eq 1 ]
then
CMD=''
else
echo "NOPE: This script needs doas(1) or sudo(8) to work properly."
echo "INFO: Install 'security/doas' or 'security/sudo' package."
exit 1
fi
unset SUDO_WHICH
unset DOAS_WHICH
unset ROOT