Skip to content

Instantly share code, notes, and snippets.

@katesclau
Last active July 31, 2021 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save katesclau/1817b7ec31c6c12343b9febf94efef44 to your computer and use it in GitHub Desktop.
Save katesclau/1817b7ec31c6c12343b9febf94efef44 to your computer and use it in GitHub Desktop.
ScadaBR service configuration script for Debian
#!/bin/bash
echo -e \
"############################################# \n \
# SCADABR / SCADALTS SERVICE CONFIGURATION \n \
# Installs prerequisits and ScadaBR/LTS \n \
# as service for Debian like environments \n \
# \n \
# Tested on: \n \
# - Debian 4.19.67 \n \
#############################################"
SCADABR=/tmp/ScadaBR
SCADABR_CONF=/tmp/ScadaBR.sql
# Ensure running as root
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# Ensure ScadaBR is provided
if [ ! -f "$SCADABR/index.jsp" ]
then echo "Could not find ScadaBR webapp folder on /tmp. Please provide a valid copy"
exit
fi
# Ensure backup is provided
if [ ! -f $SCADABR_CONF ]
then echo "Backup was not provided!"
exit
fi
echo "# Installing packages..."
# Required repositories
echo "# oldstable debian" | tee /etc/apt/sources.list.d/oldstable.list
echo "deb http://ftp.br.debian.org/debian/ oldstable main contrib non-free" | tee -a /etc/apt/sources.list.d/oldstable.list
echo "deb-src http://ftp.br.debian.org/debian/ oldstable main contrib non-free" | tee -a /etc/apt/sources.list.d/oldstable.list
# Install prerequisits
apt update
## Java 8
apt install -y openjdk-8-jre
## MySQL/MariaDB
apt install -y mariadb-server-10.3
## MySQL connector
apt install -y libmariadb-java
## RXTX
# if not available in PM, try http://neophob.com/files/rxtx-2.2pre5-src.zip
apt install -y librxtx-java
## Tomcat
apt install -y tomcat9
echo "# Securing MySQL DB..."
## DB configuration
# Refs: https://mariadb.com/kb/en/library/mysql_secure_installation/
mysql_secure_installation
echo "# Deploying ScadaBR..."
# Unpack WAR files into webapps
# ScadaBR
cd /var/lib/tomcat9/webapps
cp -rf $SCADABR .
# Grant permission
chown -R tomcat.tomcat /var/log/tomcat9
chown -R root.tomcat /etc/tomcat9 # Security concern, as webapps may alter tomcat configuration otherwise
# create database scadabr if not exist
mysql -uroot -p -e "create user 'scadabr'@'localhost' identified by 'scadabr'; \
create database if not exists scadabr; \
grant all privileges on scadabr.* to 'scadabr'@'localhost'; \
flush privileges;"
# Start the tomcat server to deploy ScadaBR
service tomcat9 restart
sleep 30
# Restore previous configuration
echo "# Restore previous configuration..."
mysql -pscadabr -uscadabr scadabr < $SCADABR_CONF
echo "# ScadaBR will start in SAFE mode!"
touch /var/lib/tomcat9/webapps/ScadaBR/SAFE
# Start the tomcat server
service tomcat9 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment