-
Notifications
You must be signed in to change notification settings - Fork 19
/
installer.sh
executable file
·201 lines (190 loc) · 7.13 KB
/
installer.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
INSTALL_LOG_FILE=/var/log/htx_install_log
if [ "$(id -u)" != "0" ]; then
echo -e "\nThis script must be run as root..exiting."
exit 1;
fi
>${INSTALL_LOG_FILE}
usage()
{
echo -e "Usage: ./installer.sh\n"
echo -e "./installer.sh -p <installation_path> [-f]\n"
echo -e "\t-f Force installation"
echo -e "\n\tEg. ./installer.sh -p /home/"
echo -e "\n\tEg. ./installer.sh -p /home/ -f"
}
while getopts ":p:f" opt
do
case $opt in
p)
INSTALL_PATH=$OPTARG;
FORCE=0;
LOCATION=1;
;;
f)
FORCE=1;
;;
\?)
echo -e "Invalid option: -$OPTARG"
usage
exit 1;
;;
:)
echo -e "Option -$OPTARG requires an argument"
usage
exit 1;
;;
esac
done
if [ "$LOCATION" == "" ];
then
INSTALL_PATH=/usr/lpp;
fi
if [ "$INSTALL_PATH" == "" ];
then
echo -e "Option: -p is missing"
usage
exit 1;
fi
mkdir -p /var/log >/dev/null 2>/dev/null
echo "HTX intall started on `date` >>>>>>>>>>>>" >> ${INSTALL_LOG_FILE}
if type "lsb_release" >> ${INSTALL_LOG_FILE} 2>&1; then
echo -e "\nYour Install System:"
if [ -f /etc/redhat-release ] ; then
OS="RedHat"
elif [ -f /etc/SuSE-release ] ; then
OS="SUSE"
elif [ -f /etc/debian_version ] ; then
OS="Ubuntu"
fi
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
VER=$(lsb_release -sr)
echo -e "Distro:$OS"
echo -e "Version:$VER"
echo -e "Arch:$ARCH"
else
echo -e "\nYour Install System:"
if [ -f /etc/redhat-release ] ; then
OS="RedHat"
elif [ -f /etc/SuSE-release ] ; then
OS="SUSE"
elif [ -f /etc/debian_version ] ; then
OS="Ubuntu"
fi
ARCH=$(uname -m)
echo -e "Distro:$OS"
echo -e "Arch:$ARCH"
fi
CURRENT_OS="Compiledon:$OS"
if [ $CURRENT_OS != $(cat os_build | grep Compiledon) ];
then
echo -e "\nWarning:It is observed that HTX is $(cat os_build | grep Compiledon) and you are trying to install on top of $OS..." | tee -a ${INSTALL_LOG_FILE}
fi
if [ -f /var/log/htx_install_path ]; then
HTX_INSTALL=$(cat /var/log/htx_install_path)
echo -e "\nHTX already installed in: $HTX_INSTALL" | tee -a ${INSTALL_LOG_FILE}
if [ "$FORCE" == "" ];
then
echo -e "Exiting..."
exit 0;
fi
if [ $FORCE -eq 1 ];
then
echo -ne "\nRemoving installed HTX..." | tee -a ${INSTALL_LOG_FILE}
./uninstaller.sh >> ${INSTALL_LOG_FILE}
if [ $? -eq 0 ]; then
echo -e "[OK]" | tee -a ${INSTALL_LOG_FILE}
else
echo -e "[FAILED]" | tee -a ${INSTALL_LOG_FILE}
echo -e "\n Uninstall failed..Please uninstall manually and restart installation. Refer '${INSTALL_LOG_FILE}' file for logs" | tee -a ${INSTALL_LOG_FILE}
exit 1;
fi
else
exit 0;
fi
fi
if [ "$LOCATION" == "" ];
then
echo -e "\nInstalling HTX in default path:/usr/lpp/htx..." | tee -a ${INSTALL_LOG_FILE}
else
echo -e "\nInstalling HTX in $INSTALL_PATH/htx..." | tee -a ${INSTALL_LOG_FILE}
fi
echo -ne "\nCreating 'htx' user..." | tee -a ${INSTALL_LOG_FILE}
if ! id -g htx > /dev/null 2>&1 ; then groupadd htx -o -g 0 > /dev/null 2>&1 ; fi
if [ $? -ne 0 ]; then
groupdel htx > /dev/null 2>&1 ;
groupadd htx -o -g 0 > /dev/null 2>&1 ;
fi
sync
sleep 1
if ! id htx > /dev/null 2>&1 ; then mkdir -p $INSTALL_PATH/htx; useradd -g htx -d $INSTALL_PATH/htx -s /bin/bash -u 0 -o htx > /dev/null 2>&1 ; fi
rm -rf $INSTALL_PATH/htx
echo -e "[OK]" | tee -a ${INSTALL_LOG_FILE}
mkdir -p /var/log
mkdir -p $INSTALL_PATH
echo -ne "\nExtracting htx.tar.gz to $INSTALL_PATH..." | tee -a ${INSTALL_LOG_FILE}
tar xvzf htx.tar.gz -C $INSTALL_PATH > /dev/null 2>&1
echo -e "[OK]" | tee -a ${INSTALL_LOG_FILE}
INSTALL_PATH_HTX=$INSTALL_PATH/htx
echo $INSTALL_PATH_HTX > /var/log/htx_install_path
echo -ne "\nFinishing Installation..." | tee -a ${INSTALL_LOG_FILE}
[[ -f $INSTALL_PATH/htx/etc/scripts/htx.d ]] && cp -f $INSTALL_PATH/htx/etc/scripts/htx.d /etc/init.d
echo -e "[OK]" | tee -a ${INSTALL_LOG_FILE}
echo -ne "\nCopying HTX Binaries..." | tee -a ${INSTALL_LOG_FILE}
ln -sf /usr/bin/perl /bin/perl >> ${INSTALL_LOG_FILE} 2>&1
if [ "$OS" != "RedHat" ];
then
ln -sf /usr/bin/awk /bin/awk >> ${INSTALL_LOG_FILE} 2>&1
fi
ln -sf $INSTALL_PATH/htx/bin/htxcmdline /bin/htxcmdline
ln -sf $INSTALL_PATH/htx/bin/htxcmdline /bin/hcl
ln -sf $INSTALL_PATH/htx/bin/htxscreen /bin/htxscreen
ln -sf $INSTALL_PATH/htx/bin/htxscreen /bin/htxmenu
ln -sf $INSTALL_PATH/htx/etc/scripts/ver /bin/ver
cp $INSTALL_PATH/htx/htx_binaries/bin/* /usr/bin/
cp $INSTALL_PATH/htx/htx_binaries/sbin/* /usr/sbin/
echo -e "[OK]" | tee -a ${INSTALL_LOG_FILE}
if [ "$OS" != "Ubuntu" ];
then
echo -ne "\nCreating htx.d.service file..." | tee -a ${INSTALL_LOG_FILE}
echo "[Unit]" > /usr/lib/systemd/system/htx.d.service
echo -e "Description=htx Daemon\n" >> /usr/lib/systemd/system/htx.d.service
echo "[Service]" >> /usr/lib/systemd/system/htx.d.service
echo "Type=forking" >> /usr/lib/systemd/system/htx.d.service
echo -e "ExecStart=${INSTALL_PATH}/htx/etc/scripts/htxd_run" >> /usr/lib/systemd/system/htx.d.service
echo -e "ExecStop=${INSTALL_PATH}/htx/etc/scripts/htxd_shutdown" >> /usr/lib/systemd/system/htx.d.service
echo -e "TasksMax=infinity\n" >> /usr/lib/systemd/system/htx.d.service
echo "[Install]" >> /usr/lib/systemd/system/htx.d.service
echo "WantedBy=multi-user.target" >> /usr/lib/systemd/system/htx.d.service
echo -e " [OK]" | tee -a ${INSTALL_LOG_FILE}
fi
echo -ne "\nAdding HTX Daemon(htxd) as service..." | tee -a ${INSTALL_LOG_FILE}
echo -e "${INSTALL_PATH}/htx/etc/scripts/htx_setup.sh" > ${INSTALL_PATH}/htx/.bash_profile
nimesis_present=`ps -ef | grep nimesis | grep -v grep | wc -l`
if [ $nimesis_present -eq 0 ] && [ ! "$DONTSTARTHTXD" = 1 ]
then
if [ "$OS" == "Ubuntu" ];
then
update-rc.d htx.d defaults >> ${INSTALL_LOG_FILE} 2>&1
/etc/init.d/htx.d start >> ${INSTALL_LOG_FILE} 2>&1
else
systemctl enable htx.d >> ${INSTALL_LOG_FILE} 2>&1
systemctl start htx.d >> ${INSTALL_LOG_FILE} 2>&1
systemctl status htx.d >> ${INSTALL_LOG_FILE} 2>&1
fi
fi
echo -e "[OK]" | tee -a ${INSTALL_LOG_FILE}
echo -ne "\nChecking HTX daemon status..." | tee -a ${INSTALL_LOG_FILE}
if pgrep -x "htxd" >> ${INSTALL_LOG_FILE} 2>&1
then
echo -e "[Running]" | tee -a ${INSTALL_LOG_FILE}
echo -e "\nHTX install completed..Now exiting." | tee -a ${INSTALL_LOG_FILE}
echo -e "HTX install completed on `date` <<<<<<<<<<<<" >> ${INSTALL_LOG_FILE} 2>&1
echo -e "\nHTX Installed version\n" >> ${INSTALL_LOG_FILE} 2>&1
ver >> ${INSTALL_LOG_FILE} 2>&1
exit 0;
else
echo -e "[Not Running]" | tee -a ${INSTALL_LOG_FILE}
echo -e "\nHTX Install failed..Please check log file '${INSTALL_LOG_FILE}'."
exit 1;
fi