-
Notifications
You must be signed in to change notification settings - Fork 5
/
configure
executable file
·187 lines (166 loc) · 5.3 KB
/
configure
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# confgiure -- configure the dump_tool, web_root, vnstatsvg_dir directory and how to dump XML file(shell or c)
# author: falcon <zhangjinw@gmail.com>
# update: 2008-06-16
function usage
{
case $1 in
-e)
echo -e "\033[;31mError\033[0m: \033[;34m$2\033[0m\n"
STATUS=-1
;;
-h)
STATUS=0
;;
esac
echo "Usage: "
echo " $ ./configure -c /path/to/cgi-bin "
echo " -w /path/to/web-root"
echo " -b /path/to/usr-bin"
echo " -d a directory in web-root"
echo " -m [c|p|shell]"
echo " -h get help"
echo " "
echo " -c specify the cgi-bin directory"
echo " -w specify the web root directory"
echo " -b specify the usr bin directory"
echo " -d specify a directory in web root to store the index page of vnstatsvg"
echo " -m specify the method to dump XML data, there are three choices, one is "
echo " using vnStatXML(c), another is using (shell) script with the --dumpdb option"
echo " provided by vnStat. the third is using the --dumpxml option after patch vnStat"
echo " with vnStatXML."
echo " -h print this information"
echo " "
exit $STATUS
}
function check_command
{
echo -n "checking command: $1... "
which $1
ret=$?
if [ $ret -ne 0 ]; then
case $1 in
apache2)
for h in httpd httpd2 nginx
do
which $h
ret=$?
[ $ret -eq 0 ] && break
done
;;
gawk)
which awk
ret=$?
;;
cron)
which crontab
ret=$?
;;
esac
fi
[ $ret -ne 0 ] && echo "there is no command $1 installed in your system, if you want to continue, please install it firstly." && exit -1
}
# get user's input
while getopts "c:w:b:d:m:h" flag
do
case $flag in
c)
CGI_BIN_DIR=$OPTARG
;;
w)
WEB_ROOT=$OPTARG
;;
b)
USR_BIN_DIR=$OPTARG
;;
d)
VNSTATSVG_DIR=$OPTARG
;;
m)
XML_DUMP_METHOD=$OPTARG
;;
?|h)
usage -h
;;
*) echo "something wrong"
;;
esac
done
echo -e "\nYour Configuration: \n"
# if user not give any input, set them by default
if [ -z "$CGI_BIN_DIR" ]; then
[ -d /usr/lib/cgi-bin ] && CGI_BIN_DIR=/usr/lib/cgi-bin
[ -d /var/www/cgi-bin ] && CGI_BIN_DIR=/var/www/cgi-bin
[ -z "$CGI_BIN_DIR" ] && usage -e "no cgi-bin directory configured, you'd better configure one."
echo -e " cgi-bin directory : \033[;34m$CGI_BIN_DIR\033[0m"
else
[ ! -d "$CGI_BIN_DIR" ] && usage -e "$CGI_BIND_DIR is not a directory, you must create it firstly."
fi
if [ -z "$WEB_ROOT" ]; then
[ -d /var/www ] && WEB_ROOT=/var/www
[ -z "$WEB_ROOT" ] && usage -e "no web-root directory configured, you'd better configure one."
echo -e " web-root directory : \033[;34m$WEB_ROOT\033[0m"
else
[ ! -d "$WEB_ROOT" ] && usage -e "$WEB_ROOT is not a directory, you must create it firstly."
fi
if [ -z "$USR_BIN_DIR" ]; then
[ -d /usr/bin ] && USR_BIN_DIR=/usr/bin
[ -z "$USR_BIN_DIR" ] && usage -e "no user bin directory configured, you'd better configure one."
echo -e " usr-bin directory : \033[;34m$USR_BIN_DIR\033[0m"
else
[ ! -d "$USR_BIN_DIR" ] && usage -e "$USR_BIN_DIR is not a directory, you must create it firstly."
fi
VNSTATSVG_ROOT=$WEB_ROOT/$VNSTATSVG_DIR
if [ -z "$VNSTATSVG_DIR" ]; then
echo -e " vnstatsvg directory : \033[;34m$WEB_ROOT\033[0m"
else
if [ -d "$VNSTATSVG_ROOT" ]; then
echo -e " the index page will be installed in: \033[;34m$VNSTATSVG_ROOT\033[0m"
else
usage -e "$VNSTATSVG_ROOT is not a directory, you'd better create firstly."
fi
fi
if [ -z "$XML_DUMP_METHOD" ]; then
XML_DUMP_METHOD=shell
fi
case $XML_DUMP_METHOD in
c)
echo -e " XML dumping method: \033[;34mvnStatXML\033[0m"
;;
p)
echo -e " XML dumping method: \033[;34mvnStatXML patch to vnStat\033[0m"
;;
shell)
echo -e " XML dumping method: \033[;34ma shell script with the --dumpdb option provided by vnStat\033[0m"
# check dependent commands
echo ""
for i in vnstat cron gawk apache2 sort grep
do
check_command $i
done
;;
*) usage -e "not support this XML dumping method"
;;
esac
# check the arguments
CGI_BIN_DIR=$(echo $CGI_BIN_DIR"/" | tr -s '/' )
USR_BIN_DIR=$(echo $USR_BIN_DIR"/" | tr -s '/' )
VNSTATSVG_ROOT="$(echo $VNSTATSVG_ROOT"/" | tr -s '/')"
# configure the directories in Makefile
sed -i -e "s#CGI_BIN=\(.*\)#CGI_BIN=$CGI_BIN_DIR#g" \
-e "s#USR_BIN=\(.*\)#USR_BIN=$USR_BIN_DIR#g" \
-e "s#VNSTATSVG_ROOT=\(.*\)#VNSTATSVG_ROOT=$VNSTATSVG_ROOT#g" \
-e "s#XML_DUMP_METHOD=\(.*\)#XML_DUMP_METHOD=$XML_DUMP_METHOD#g" Makefile
# give some prompt
echo -e "\nFinish configuration: "
echo -e " CGI_BIN:\033[;34m $CGI_BIN_DIR\033[0m"
echo " <-- the files in cgi-bin directory of vnstatsvg will be installed here."
echo -e " USR_BIN:\033[;34m $USR_BIN_DIR\033[0m"
echo " <-- the vnstat binary will be installed here."
echo -e " VNSTATSVG_ROOT:\033[;34m $VNSTATSVG_ROOT\033[0m"
echo " <-- the files in admin directory of vnstatsvg will be installed here."
echo -e " XML_DUMP_METHOD:\033[;34m vnstat-$XML_DUMP_METHOD.sh\033[0m"
echo " <-- the xml dumping method will be used."
echo "The configuration have been saved in Makefile :-)"
echo -e "\nnow, you can compile and install vnStatSVG as following:"
echo -e " \033[;34m$ make; make install\033[0m "