-
Notifications
You must be signed in to change notification settings - Fork 14
/
install
executable file
·157 lines (126 loc) · 3.62 KB
/
install
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
#!/bin/bash
# if you change the following CONF_DIR value you must
# change it in pmacct-to-elasticsearch too.
CONF_DIR=/etc/p2es
BIN_DIR=/usr/local/bin
if [ ! -e "$BIN_DIR/pmacct-to-elasticsearch" ]; then
echo "ERROR: pmacct-to-elasticsearch not found in $BIN_DIR."
echo ""
echo "If it is not installed, please install it using "
echo ""
echo " pip install pmacct-to-elasticsearch"
echo ""
echo "otherwise please consider editing this installation script"
echo "to set the BIN_DIR variable to the directory where "
echo "pmacct-to-elasticsearch is currently installed."
exit 1
fi
FORCE="no"
while getopts "F" opt; do
case $opt in
F) FORCE="yes" ;;
esac
done
echo ""
echo "pmacct-to-elasticsearch installation script"
echo ""
echo "The following directory will be used for the installation:"
echo " - $CONF_DIR: configuration files"
echo ""
echo "With -F option, Replace all files without confirmation"
echo ""
if [ "$FORCE" != "yes" ]; then
read -p "Proceed [yes|NO]: " PROCEED
else
PROCEED="yes"
fi
if [ "$PROCEED" != "yes" ]; then
echo "Installation aborted"
exit 0
fi
# -----------------------------------------------------------
echo -n "Creating configuration directory ($CONF_DIR)... "
if [ ! -d $CONF_DIR ]; then
mkdir -p $CONF_DIR &>/dev/null
if [ $? -ne 0 ]; then
echo "ERROR - exit code $?"
exit 1
else
mkdir $CONF_DIR/triggers &>/dev/null
if [ $? -ne 0 ]; then
echo "ERROR creating triggers subdirectory - exit code $?"
exit 1
else
echo "OK"
fi
fi
else
echo "OK (already exists)"
fi
# -----------------------------------------------------------
echo -n "Copying default configuration files in $CONF_DIR... "
if [ "$FORCE" != "yes" ]; then
cp -i distrib/new-index-template.json $CONF_DIR
else
cp distrib/new-index-template.json $CONF_DIR
fi
if [ $? -ne 0 ]; then
echo "ERROR - exit code $?"
exit 1
else
echo "OK"
fi
# -----------------------------------------------------------
echo -n "Copying default trigger in $CONF_DIR/triggers... "
if [ -f $CONF_DIR/triggers/default_trigger ]; then
echo ""
if [ "$FORCE" != "yes" ]; then
read -p "- Default trigger already exists at $CONF_DIR/triggers/default_trigger: overwrite it? [yes|NO] " PROCEED
else
PROCEED="yes"
fi
else
PROCEED="yes"
fi
if [ "$PROCEED" == "yes" ]; then
BIN_DIR_SED="${BIN_DIR//\//\\/}"
sed -e "s/<P2ES_BIN_DIR>/$BIN_DIR_SED/" distrib/default_trigger > $CONF_DIR/triggers/default_trigger
if [ $? -ne 0 ]; then
echo "ERROR - exit code $?"
exit 1
else
echo "OK"
chmod u+x $CONF_DIR/triggers/default_trigger
fi
else
echo "Skipped"
fi
# -----------------------------------------------------------
echo -n "Copying crontab job fragment to /etc/cron.d... "
if [ -d /etc/cron.d ]; then
if [ ! -f /etc/cron.d/pmacct-to-elasticsearch ]; then
BIN_DIR_SED="${BIN_DIR//\//\\/}"
sed -e "s/<P2ES_BIN_DIR>/$BIN_DIR_SED/" distrib/cron > /etc/cron.d/pmacct-to-elasticsearch
if [ $? -ne 0 ]; then
echo "ERROR - exit code $?"
exit 1
else
echo "OK"
fi
else
echo "skipped (/etc/cron.d/pmacct-to-elasticsearch already exists)"
fi
else
echo "ERROR - /etc/cron.d does not exist"
exit 1
fi
# -----------------------------------------------------------
echo "====================="
echo "Installation complete"
echo "====================="
echo ""
if [ "$CONF_DIR" != "/etc/p2es" ]; then
echo "WARNING: the default configuration directory (CONF_DIR) has been changed from /etc/p2es to $CONF_DIR: please change the CONF_DIR variable in pmacct-to-elasticsearch too."
fi
echo "Some configurations are needed now. Read the CONFIGURATION.md file for more details."
echo ""