#!/bin/bash

export CLODIOS_HOME=/clodios
groupadd clodios
useradd -g clodios clodios
yum -y install epel-release
yum -y install firewalld python3 python3-devel gcc liberation-narrow-fonts postgresql-server libpq-devel
yum -y install mesa-libGL
yum -y install wget zip unzip sshpass
pip3 install --upgrade pip
pip3 install psycopg2
pip3 install xlsxwriter xlwt xlrd
pip3 install reportlab
pip3 install opencv-python==4.6.0.66 websocket_client
pip3 install func-timeout psutil pydes python-docx docx-mailmerge
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=81/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --add-port=8443/tcp --permanent
firewall-cmd --reload
service postgresql initdb
systemctl enable postgresql
mkdir $CLODIOS_HOME
cd $CLODIOS_HOME
chown -R clodios:clodios $CLODIOS_HOME
wget --no-check-certificate https://www.clodios.com/ins/clodios.6.17.cts_84.p36m.tar.gz
tar -xvf clodios.6.17.cts_84.p36m.tar.gz
chown -R clodios:clodios $CLODIOS_HOME
chmod -R 755 $CLODIOS_HOME
sed -i "s|/clodios|$CLODIOS_HOME|g" $CLODIOS_HOME/bin/odmserverp
sed -i "s|/clodios|$CLODIOS_HOME|g" $CLODIOS_HOME/bin/odm
service postgresql start
su -l postgres -c "sh $CLODIOS_HOME/bin/scr.sh"
sed -i 's/peer/md5/g' /var/lib/pgsql/data/pg_hba.conf
sed -i 's/ident/md5/g' /var/lib/pgsql/data/pg_hba.conf
service postgresql restart
cd $CLODIOS_HOME
wget --no-check-certificate https://www.clodios.com/ins/RETAIL.dat
cd $CLODIOS_HOME/bin
./deploy -w auto -f $CLODIOS_HOME/RETAIL.dat -s RETAIL
chown -R clodios:clodios $CLODIOS_HOME
cp $CLODIOS_HOME/bin/odmserverp /etc/init.d/
setcap CAP_NET_BIND_SERVICE=+eip $CLODIOS_HOME/bin/OdmServer
chkconfig odmserverp on
service odmserverp start
