Debian Codegraph @

as400/connector.as400.install/install.sh

raw
1 #!/bin/bash
2
3 #################################################
4 ##Functions and vars for actions results printing
5 #################################################
6
7 RES_COL=80
8 MOVE_TO_COL="echo -en \\033[${RES_COL}G"
9 SETCOLOR_INFO="echo -en \\033[1;38m"
10 SETCOLOR_SUCCESS="echo -en \\033[1;32m"
11 SETCOLOR_FAILURE="echo -en \\033[1;31m"
12 SETCOLOR_NORMAL="echo -en \\033[0;39m"
13 SETCOLOR_WARNING="echo -en \\033[1;33m"
14
15 function echo_success() {
16 echo -n "$1"
17 $MOVE_TO_COL
18 $SETCOLOR_SUCCESS
19 echo -n "$2"
20 $SETCOLOR_NORMAL
21 echo -e "\r"
22 echo ""
23 }
24
25 function echo_failure() {
26 echo -n "$1"
27 $MOVE_TO_COL
28 $SETCOLOR_FAILURE
29 echo -n "$2"
30 $SETCOLOR_NORMAL
31 echo -e "\r"
32 echo ""
33 }
34
35 function echo_passed() {
36 echo -n "$1"
37 $MOVE_TO_COL
38 $SETCOLOR_WARNING
39 echo -n "$2"
40 $SETCOLOR_NORMAL
41 echo -e "\r"
42 echo ""
43 }
44
45 ##################
46 ##Static variables
47 ##################
48
49 INIT_FOLDER="init-script/"
50 INIT_FILE="centreon-as400.service"
51 SYSCONFIG_FILE="centreon-as400-sysconfig"
52
53 CONNECTOR_VERSION=2.0.0
54 CONNECTOR_HOME="/usr/share/centreon-as400/"
55 CONNECTOR_LOG="/var/log/centreon-as400/"
56 CONNECTOR_ETC="/etc/centreon-as400/"
57 LOG_ETC_FILE="log4j.xml"
58
59 CONNECTOR_USER="centreon-as400"
60 CONNECTOR_GROUP="centreon-as400"
61
62 JAVA_BIN=""
63
64 ETC_PASSWD="/etc/passwd"
65 ETC_GROUP="/etc/group"
66 ETC_INITD="/etc/systemd/system/"
67 ETC_SYSCONFIG="/etc/sysconfig/"
68
69 ######
70 ##INIT
71 ######
72
73 $SETCOLOR_WARNING
74 echo "Starting setup..."
75 $SETCOLOR_NORMAL
76 echo ""
77
78 ##############################
79 ##Getting modules install path
80 ##############################
81 DONE="no"
82 CREATE_HOME="no"
83 temp_folder="$CONNECTOR_HOME"
84 while [ "$DONE" = "no" ]; do
85 echo "Centreon AS400 home Directory [$CONNECTOR_HOME]? "
86 echo -n ">"
87 read temp_folder
88 if [ -z "$temp_folder" ]; then
89 temp_folder="$CONNECTOR_HOME"
90 fi
91 temp_folder=`echo "$temp_folder" | sed "s/$/\//"`
92
93 if [ -d "$temp_folder" ]; then
94 DONE="yes"
95 else
96 echo_failure "$temp does not exists" "CRITICAL"
97 echo "Specified path does not exists, do you want to create it ?[Y/n]"
98 echo -n ">"
99 read temp
100 if [ -z "$temp" ]; then
101 temp="Y"
102 fi
103 while [ "$temp" != "Y" ] && [ "$temp" != "y" ] && [ "$temp" != "n" ] && [ "$temp" != "N" ]; do
104 echo "Specified path does not exists, do you want to create it ?[Y/n]"
105 echo -n ">"
106 read temp
107 if [ -z "$temp" ]; then
108 temp="Y"
109 fi
110 done
111 if [ "$temp" = "Y" ] || [ "$temp" = "y" ]; then
112 DONE="yes"
113 CREATE_HOME="yes"
114 fi
115 fi
116 done
117 temp_folder=$(echo $temp_folder | sed "s/\/\/$/\//")
118 CONNECTOR_HOME=${temp_folder}
119 echo_success "Centreon AS400 home directory" "$CONNECTOR_HOME"
120
121 #############################
122 ##Getting java home directory
123 #############################
124
125 JAVA_HOME="/usr/"
126 temp=$JAVA_HOME
127 while [ ! -x "$temp/bin/java" ]; do
128 echo_failure "Cannot find java binary" "FAILURE"
129 echo "Java home directory?"
130 echo -n ">"
131 read temp
132 if [ -z "$temp" ]; then
133 temp="$JAVA_HOME"
134 fi
135 done
136 temp=`echo "$temp" | sed "s/$/\//"`
137 JAVA_BIN=`echo $temp | sed "s/\/\/$/\//"`"bin/java"
138 echo_success "Java bin path :" "$JAVA_BIN"
139
140 ###################
141 # CONNECTOR INIT SCRIPT
142 ###################
143
144 echo "Do you want to install AS400 systemd script [y/N]?"
145 echo -n ">"
146 read response
147 if [ -z "$response" ]; then
148 response="N"
149 fi
150 while [ "$response" != "Y" ] && [ "$response" != "y" ] && [ "$response" != "N" ] && [ "$response" != "n" ]; do
151 echo "Do you want to install AS400 systemd script [y/N]?"
152 echo -n ">"
153 read response
154 if [ -z "$response" ]; then
155 response="N"
156 fi
157 done
158 INSTALL_CONNECTOR_INIT=$response
159 echo_success "CONNECTOR systemd script :" "$ETC_INITD/$INIT_FILE"
160
161 ########################
162 ## Centreon BI user and Group
163 ########################
164 exists=`cat $ETC_PASSWD | grep "^$CONNECTOR_USER:"`
165 if [ -z "$exists" ]; then
166 useradd -m $CONNECTOR_USER -d $CONNECTOR_HOME
167 fi
168 echo_success "CONNECTOR run user :" "$CONNECTOR_USER"
169
170 exists=`cat $ETC_GROUP | grep "^$CONNECTOR_GROUP:"`
171 if [ -z "$exists" ]; then
172 groupadd $CONNECTOR_GROUP
173 fi
174 echo_success "CONNECTOR run group :" "$CONNECTOR_GROUP"
175
176 #######################
177 # DEPLOYING CENTREON BI
178 #######################
179 echo ""
180 echo_success "Creating directories and moving binaries..." "OK"
181 if [ ! -d "${CONNECTOR_HOME}" ]; then
182 mkdir -p $CONNECTOR_HOME
183 fi
184 if [ ! -d "${CONNECTOR_HOME}/bin" ]; then
185 mkdir ${CONNECTOR_HOME}/bin
186 fi
187
188 if [ -d bin/ ] ; then
189 cp -f bin/*.jar ${CONNECTOR_HOME}/bin/
190 fi
191
192 if [ ! -d "${CONNECTOR_LOG}" ]; then
193 mkdir -p ${CONNECTOR_LOG}
194 fi
195 if [ ! -d "${CONNECTOR_ETC}" ]; then
196 mkdir -p ${CONNECTOR_ETC}
197 fi
198
199 cp etc/log4j.xml ${CONNECTOR_ETC}
200 cp etc/config.properties ${CONNECTOR_ETC}
201
202 ###################
203 ##Macro replacement
204 ###################
205
206 ETC_FILE=${CONNECTOR_ETC}${CONNECTOR_ETC_FILE}
207
208 if [ "$INSTALL_CONNECTOR_INIT" = "y" ] || [ "$INSTALL_CONNECTOR_INIT" = "Y" ]; then
209 echo_success "Copying CONNECTOR init script..." "OK"
210 sed -e 's|@JAVA_BIN@|'"$JAVA_BIN"'|g' \
211 $INIT_FOLDER/$INIT_FILE > $ETC_INITD/$INIT_FILE
212 chmod 644 $ETC_INITD/$INIT_FILE
213 sed -e 's|@CONNECTOR_HOME@|'"$CONNECTOR_HOME"'|g' \
214 -e 's|@JAVA_BIN@|'"$JAVA_BIN"'|g' \
215 -e 's|@CONNECTOR_USER@|'"$CONNECTOR_USER"'|g' \
216 -e 's|@CONNECTOR_ETC@|'"${CONNECTOR_ETC}"'|g' \
217 -e 's|@CONNECTOR_LOG@|'"${CONNECTOR_LOG}"'|g' \
218 -e 's|@CONNECTOR_VERSION@|'"${CONNECTOR_VERSION}"'|g' \
219 $INIT_FOLDER/$SYSCONFIG_FILE > $ETC_SYSCONFIG/centreon-as400
220 fi
221 echo_success "Deploying Centreon-AS400..." "OK"
222
223 ###################################################
224 ##Rights settings on install directory and binaries
225 ###################################################
226
227 chown -R $CONNECTOR_USER.$CONNECTOR_GROUP $CONNECTOR_HOME
228 chown -R $CONNECTOR_USER.$CONNECTOR_GROUP $CONNECTOR_LOG
229 chown -R $CONNECTOR_USER.$CONNECTOR_GROUP $CONNECTOR_ETC
230 chmod -R 775 $CONNECTOR_HOME
231
232 echo_success "Rights settings..." "OK"
233
234 systemctl enable $INIT_FILE
235
236 #########
237 # THE END
238 #########
239
240 echo ""
241 $SETCOLOR_WARNING
242 echo "Setup finished."
243 echo ""