
#!/bin/sh
# File	: snapcenter_install.sh
# By	: Maarten.deBoer@Atos.net, 260511
# Subject	: Script to install SnapCenter on linux
PGM=`basename $0|cut -d\. -f1`
VER="0.1"
LOG="${HOME}/log/${PGM}.log"

INSTALL_PKGS=""
SELINUX=1

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}

if [ ${INSTALL_PKGS} ]; then
# NGINX (Webserver)
  dnf install -y nginx
# PAM-devl
  dnf install -y pam-devel
# aspnetcore
  cd /appl/netapp/RPMs
  yum install -y aspnetcore-runtime-8.0-8.0.12-1.el8_10.x86_64.rpm
# powershell
  yum install -y packages-microsoft-prod.rpm
  yum --disablerepo=* --enablerepo=packages-microsoft-com-prod install powershell-7.4.2
fi  # INSTALL_PKGS

rpm -qa | grep nginx
rpm -qa | grep pam-devel
rpm -qa | grep aspnetcore
rpm -qa | grep powershell

sestatus

sleep 2

# p.45
# If SElinux, then config
if [ ${SELINUX} ]; then
# Check the secure Linux status by running the command sestatus. If the SELinux status is "enabled" and the Current mode is "enforcing", perform the following:
# ◦Run the command: sudo semanage port -a -t http_port_t -p tcp <WEBAPP_EXTERNAL_PORT_>
#The default value of WEBAPP_EXTERNAL_PORT is 8146

  semanage port -a -t http_port_t -p tcp 8146

#◦ If the firewall blocks the port, run sudo firewall-cmd --add-port
<WEBAPP_EXTERNAL_PORT_>/tcp
#The default value of WEBAPP_EXTERNAL_PORT is 8146

#◦Run the following commands from the directory where you have read and write permission:
# ▪sudo ausearch -c 'nginx' --raw | audit2allow -M my-nginx
ausearch -c 'nginx' --raw | audit2allow -M my-nginx

# If the command return "nothing to do", rerun the command after installing SnapCenter Server.
# ▪ If the command creates my-nginx.pp, run the command to make the policy package active: sudo semodule -i my-nginx.pp


# ◦ The path used for MySQL PID directory is /var/opt/mysqld. Run the following commands to set the permissions for MySQL installation.
#▪ mkdir /var/opt/mysqld
#▪ sudo semanage fcontext -a -t mysqld_var_run_t "/var/opt/mysqld(/.*)?"
#▪ sudo restorecon -Rv /var/opt/mysqld
  mkdir /var/opt/mysqld
  semanage fcontext -a -t mysqld_var_run_t "/var/opt/mysqld(/.*)?"
  restorecon -Rv /var/opt/mysqld

#◦ The path used for MySQL Data directory is /INSTALL_DIR/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL/. Run the following commands to set the permissions for MySQL data directory.
#▪ mkdir -p /INSTALL_DIR/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL
#▪ sudo semanage fcontext -a -t mysqld_db_t "/INSTALL_DIR/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL(/.*)?"
#▪ sudo restorecon -Rv /INSTALL_DIR/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL
#
  mkdir -p /appl/netapp/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL
  semanage fcontext -a -t mysqld_db_t "/appl/netapp/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL(/.*)?"
  restorecon -Rv /appl/netapp/NetApp/snapcenter/SnapManagerWeb/Repository/MySQL

fi  # SElinux
# -------------------------------------------------------

firewall-cmd --add-port 8146/tcp --permanent
# Added too:
firewall-cmd --add-port 8145/tcp --permanent 
firewall-cmd --add-port 8154/tcp --permanent
firewall-cmd --add-port 8147/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all

# -------------------------------------------------------

# sudo ./snapcenter-linux-server (el8/el9/sles15).bin -i silent
# -DWEBAPP_EXTERNAL_PORT=<port>
#-DWEBAPP_INTERNAL_PORT=<port>
#-DSMCORE_PORT=<port>
#-DSCHEDULER_PORT=<port>
#-DSNAPCENTER_SERVER_USER=<user>
#-DUSER_INSTALL_DIR=<dir>
#-DINSTALL_LOG_NAME=<filename

# DWEBAPP_EXTERNAL_PORT=8146
# DSNAPCENTER_SERVER_USER=root
# DUSER_INSTALL_DIR=/appl/netapp

cd /appl/netapp/
./snapcenter-linux-server-el8.bin | tee -a snapcenter-linux-server-el8.log

ausearch -c 'nginx' --raw | audit2allow -M my-nginx
semodule -i my-nginx.pp


echo "`date` ${PGM} v${VER} finished."|tee -a ${LOG}
exit 0

