Skip to content

Instantly share code, notes, and snippets.

@Youka
Created December 31, 2020 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Youka/808a31413c934e2b31c947968b83e380 to your computer and use it in GitHub Desktop.
Save Youka/808a31413c934e2b31c947968b83e380 to your computer and use it in GitHub Desktop.
Liferay 7 RHEL development server installation
#! /bin/bash
# HELPERS
# Variables
pkg_install="yum -y install"
pkg_installed="yum list installed"
pkg_clean="yum clean all"
pkg_update="yum -y update"
service_enable="systemctl enable"
service_start="systemctl start"
service_state="systemctl status"
#Functions
echo_info () {
# echo -e "\e[32m$@\e[0m"
echo INFO: $@
}
echo_error () {
# echo -e "\e[31m$@\e[0m"
echo ERROR: $@
}
service_installed() {
systemctl list-unit-files | grep "^$1.service"
}
env_var_add() {
if ! cat /etc/environment | grep "^$1=" &>/dev/null; then
echo "$1=$2" >> /etc/environment
source /etc/environment
fi
echo_info "$1=${!1}"
}
profile_script_add() {
if [ ! -f "/etc/profile.d/$1.sh" ]; then
echo "$2" > "/etc/profile.d/$1.sh"
eval "$2"
fi
cat "/etc/profile.d/$1.sh"
}
txt_repl() {
sed -i -e "s/$1/$2/g" "$3"
}
targz_download () {
curl -L "$1" | tar -xzf - -C "$2"
}
# ENVIRONMENT
# Check RHEL os (enterprise with yum)
if [ ! -f /etc/redhat-release ]; then
echo_error "Expected OS of redhat family!"
exit
else
echo_info "Redhat OS detected."
fi
# Must be root for further actions (like global installations)
if [ "$USER" != "root" ]; then
echo_error "Root privilege required!"
exit
else
echo_info "Has root privilege."
fi
# TOOLS
# SSH (remote control)
if ! service_installed sshd &>/dev/null; then
$pkg_install openssh-server
$service_enable sshd
$service_start sshd
$service_state sshd
else
echo_info "SSH service already installed."
fi
# Winbind (send hostname to Windows network)
if ! $pkg_installed samba-winbind &>/dev/null; then
$pkg_install samba-winbind
txt_repl "^hosts:\([[:space:]]*\)files dns" "hosts:\1files wins dns" /etc/nsswitch.conf
else
echo_info "Hostname for windows network enabled."
fi
# Curl (downloader)
$pkg_install curl
# Tar (zipper)
$pkg_install tar
# Nano (convenient text editor)
$pkg_install nano
# Htop (prettier resources monitoring)
if ! hash htop &>/dev/null; then
# Add Fedora extras repository
$pkg_install epel-release
# Disable slowing plugin (re-index for every yum install)
txt_repl "enabled=1" "enabled=0" /etc/yum/pluginconf.d/fastestmirror.conf
$pkg_clean
# Install from new repository
$pkg_update
$pkg_install htop
else
echo_info "Htop already installed."
fi
# SOFTWARE
# OpenJDK 8 (Java 8 Software-Development-Kit)
$pkg_install java-1.8.0-openjdk-devel
env_var_add JAVA_HOME $(readlink -ze /usr/bin/javac | xargs -0 dirname | xargs -0 dirname)
# Liferay 7.1.1 GA2 (portal server)
if [ ! -L /opt/liferay ]; then
# Download
targz_download "https://sourceforge.net/projects/lportal/files/Liferay%20Portal/7.1.1%20GA2/liferay-ce-portal-tomcat-7.1.1-ga2-20181112144637000.tar.gz/download" /opt
for liferay in /opt/liferay-ce-portal-*; do
echo_info "Found liferay version: $liferay"
for tomcat in $liferay/tomcat-*; do
echo_info "Found tomcat version: $tomcat"
# Create link to active version
ln -s $liferay /opt/liferay
ln -s $tomcat /opt/tomcat
env_var_add CATALINA_HOME /opt/tomcat
# Assign special user for process control
groupadd liferay
useradd -s /sbin/nologin -g liferay -d /opt/liferay liferay
# Permissions for non-root access
chown -R liferay:liferay $liferay
chmod -R a-rwx,a+rx,u+w,g+w $liferay
chmod a+w $liferay/deploy
# Add system service for liferay
echo "[Unit]
Description=Liferay CE Portal server
# Waits for system logging channels and network setup first
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=liferay
Group=liferay
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=liferay
[Install]
# Bound to after-boot process
WantedBy=multi-user.target" > /etc/systemd/system/liferay.service
$service_enable liferay
$service_start liferay
$service_state liferay
break
done
break
done
else
echo_info "Liferay already installed."
fi
# MSSQL 2017 (database)
if ! service_installed mssql-server &>/dev/null; then
# Install server (https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-environment-variables)
curl https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo -o /etc/yum.repos.d/mssql-server.repo
$pkg_install mssql-server
MSSQL_LCID=1033 ACCEPT_EULA='Y' MSSQL_PID='Developer' MSSQL_SA_PASSWORD='Liferay7-mssql' MSSQL_TCP_PORT=1433 /opt/mssql/bin/mssql-conf setup
# Install tools
curl https://packages.microsoft.com/config/rhel/7/prod.repo -o /etc/yum.repos.d/msprod.repo
ACCEPT_EULA=Y $pkg_install mssql-tools unixODBC-devel
profile_script_add mssql-tools "export PATH='$PATH:/opt/mssql-tools/bin'"
# Server status
$service_state mssql-server
else
echo_info "MSSQL service already installed."
fi
# Firewall (open HTTP & MSSQL ports)
if service_installed firewalld &>/dev/null; then
firewall-cmd --add-port=80/tcp --permanent && firewall-cmd --add-port=443/tcp --permanent && firewall-cmd --add-port=8080/tcp --permanent && firewall-cmd --add-port=8443/tcp --permanent && firewall-cmd --add-port=1433/tcp --permanent && firewall-cmd --reload
fi
# FEEDBACK
echo_info "All installed! Wait a few minutes for Liferay & mssql-server startup, then address $HOSTNAME:8080."
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment