LAMP

by tkelso
87 deployments · 5 still active · last rev. 1 year ago

Dev script for ubuntu 16.04 and CentOS 7 LAMP

Compatible with: CentOS 7, Ubuntu 16.04 LTS
						#!/bin/bash

# v1.0.1

# <UDF name="sys_hostname" Label="Hostname" />
# <UDF name="sys_username" Label="Non-Root User" example="Required" />
# <UDF name="sys_user_password" Label="Non-Root User Password" example="Required" />
# <UDF name="pubkey" Label="Public RSA Key" default="" />
# <UDF name="db_password" Label="MySQL root Password" example="Required" />
# <UDF name="db_nonroot_user" Label="MySQL Non-Root User" default="" />
# <UDF name="db_user_password" Label="MySQL Non-Root Password" default="" />
# <UDF name="db_name" Label="MySQL Database" default="" />
# <UDF name="fqdn" Label="FQDN" default="" example="example.com" />
# <UDF name="root_login" Label="Disable SSH Root Login?" oneof="Yes,No" default="Yes" />
# <UDF name="cron" Label="Enable Auto-Update?" oneof="Yes,No" default="Yes" />


# Sets source library script
source <ssinclude StackScriptID="65504">

# Runs lsb_release -si to detect distribution.
DISTRO=$(lsb_release -si)
if [ $DISTRO = "Ubuntu" ]; then

# Ubuntu 16.04 LTS Installation

systemctl stop ssh
ubuntu_update
ubuntu_set_hostname "$SYS_HOSTNAME"
ubuntu_install_lamp "$DB_PASSWORD"
ubuntu_install_additional
ubuntu_user_add_sudo "$SYS_USERNAME" "$SYS_USER_PASSWORD"

if [ -z "PUBKEY" ]; then
	echo "No Public Key set. Not Creating authorized_keys file."
else
	ubuntu_key_user "$SYS_USERNAME" "$PUBKEY"
fi

if [ "$ROOT_LOGIN" == "Yes" ]; then
	ubuntu_ssh_disable_root
else
	echo "SSH Root Login Enabled."
fi

if [ -z "$FQDN"]; then
	echo "No FQDN Set. Not Creating VirtualHost."
else
	apache2_create_virtualhost "$FQDN"
fi

apache2_tune
ubuntu_php_tune
ubuntu_restart_lamp
ubuntu_iptables_lamp
config_fail2ban

if [ -z "$DB_NAME"]; then
	echo "No Database Name Set. Not Creating Database."
else
	mysql_create_database "$DB_PASSWORD" "$DB_NAME"
	mysql_create_user "$DB_PASSWORD" "$DB_NONROOT_USER" "$DB_USER_PASSWORD"
	mysql_grant_user "$DB_PASSWORD" "$DB_NONROOT_USER" "$DB_NAME"
fi

ubuntu_mysql_secure_installation "$DB_PASSWORD"

if [ "$CRON" == "Yes" ]; then
	ubuntu_update_cron
else
	echo "No Update Cron Created."
fi

systemctl start ssh

else

# CentOS 7 Installation
systemctl stop sshd
centos_update
centos_set_hostname "$SYS_HOSTNAME"
centos_install_lamp
centos_install_additional
centos_user_add_sudo "$SYS_USERNAME" "$SYS_USER_PASSWORD"

if [ -z "PUBKEY" ]; then
	echo "No Public Key set. Not Creating authorized_keys file."
else
	centos_key_user "$SYS_USERNAME" "$PUBKEY"
fi

if [ "$ROOT_LOGIN" == "Yes" ]; then
	centos_ssh_disable_root
else
	echo "SSH Root Login Enabled."
fi

if [ -z "$FQDN"]; then
	echo "No FQDN Set. Not Creating VirtualHost."
else
	httpd_create_virtualhost "$FQDN"
fi

httpd_tune
centos_php_tune
centos_restart_lamp
centos_iptables_lamp
config_fail2ban
centos_mysql_setpass "$DB_PASSWORD"

if [ -z "$DB_NAME"]; then
	echo "No Database Name Set. Not Creating Database."
else
	mysql_create_database "$DB_PASSWORD" "$DB_NAME"
	mysql_create_user "$DB_PASSWORD" "$DB_NONROOT_USER" "$DB_USER_PASSWORD"
	mysql_grant_user "$DB_PASSWORD" "$DB_NONROOT_USER" "$DB_NAME"
fi

centos_mysql_secure_installation "$DB_PASSWORD"

if [ "$CRON" == "Yes" ]; then
	centos_update_cron
else
	echo "No Update Cron Created."
fi

systemctl start sshd

fi

# Clean Up
##########

# Deletes Library Script
rm /root/ssinclude-65504

# Removes Executed Script
rm -- "$0"