-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.sh
executable file
·157 lines (117 loc) · 2.98 KB
/
setup.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
#
# lame script to install nullscan
BLUE='\033[1;34;10m'
RED='\033[1;31;10m'
YELLOW='\033[1;33;10m'
GREEN='\033[1;32;10m'
NORM='\033[0m'
SUCCESS=0
FAILURE=1
SHARE_PATH='/usr/share/nullscan'
CONF_PATH='/etc'
DOC_PATH='/usr/share/doc/nullscan'
LICENSE_PATH='/usr/share/licenses/nullscan'
MAN_PATH='/usr/share/man/man1'
msg()
{
eopt='-e'
# distros default shell without -e flag for echo
$(egrep 'debian|ubuntu|kali' /proc/version > /dev/null 2>&1)
other_distros=$?
if [ $other_distros -eq $SUCCESS ]
then
eopt=''
else
eopt='-e'
fi
if [ "$1" = 'job' ]
then
echo $eopt "${BLUE}[+]${NORM} ${2}"
elif [ "$1" = 'good' ]
then
echo $eopt "${GREEN}[*]${NORM} ${2}"
elif [ "$1" = 'warn' ]
then
echo $eopt "${YELLOW}[!]${NORM} ${2}"
elif [ "$1" = 'err' ]
then
echo $eopt "${RED}[-]${NORM} ${2}"
exit $FAILURE
else
echo "${2}"
fi
return $SUCCESS
}
usage()
{
msg "err" "usage: setup.sh install | uninstall"
return $SUCCESS
}
create_dirs()
{
mkdir -p $SHARE_PATH $DOC_PATH $LICENSE_PATH $MAN_PATH > /dev/null 2>&1 ||
return $FAILURE
return $SUCCESS
}
install_files()
{
# source
cp -a src "$SHARE_PATH/src" > /dev/null 2>&1 || return $FAILURE
# config
install -Dm 640 conf/nullscan.conf "$CONF_PATH/nullscan.conf" \
> /dev/null 2>&1 || return $FAILURE
# lists
cp -a lists "$SHARE_PATH/lists" > /dev/null 2>&1 || return $FAILURE
# docs - note: seems that dash shell cannot handle foo/{bar,baz} (!posix)
install -Dm 644 -t "$DOC_PATH/" docs/AUTHORS docs/ChangeLog docs/DESCR \
docs/*.txt docs/README docs/TESTED docs/THANKS docs/TODO > /dev/null 2>&1 ||
return $FAILURE
# man
install -Dm 644 docs/nullscan.1 "$MAN_PATH/nullscan.1"
# license
install -Dm 644 docs/LICENSE "$LICENSE_PATH/LICENSE" > /dev/null 2>&1 ||
return $FAILURE
return $SUCCESS
}
create_symlink()
{
ln -sf "$SHARE_PATH/src/nullscan.py" "$pkgdir/usr/bin/nullscan" ||
return $FAILURE
return $SUCCESS
}
uninstall()
{
rm -rf $SHARE_PATH $DOC_PATH $LICENSE_PATH /etc/nullscan.conf \
"$MAN_PATH/nullscan*" || return $FAILURE
return $SUCCESS
}
main()
{
if [ $# -ne 1 ]
then
usage
exit $FAILURE
fi
if [ "$1" = "install" ]
then
msg 'job' 'w00t w00t, installing nullscan'
msg 'job' 'creating necessary directories'
create_dirs || msg 'err' 'could not create directories - are you r00t?'
msg 'job' 'installing files'
install_files || msg 'err' 'could not install files - are you r00t?'
msg 'job' 'creating symlink to /usr/bin/nullscan'
create_symlink || msg 'err' 'could not create symlink - are you r00t?'
msg 'good' 'w00t w00t, install successfull'
msg 'warn' "don't forget to install all py deps from docs/requirements.txt"
elif [ "$1" = "uninstall" ]
then
msg 'job' 'uninstalling nullscan'
uninstall || msg 'err' 'could not uninstall - do it yourself'
msg 'good' 'uninstalled nullscan'
else
msg 'err' 'WHAT?'
fi
return $SUCCESS
}
main "${@}"