259 lines
8.7 KiB
Bash
259 lines
8.7 KiB
Bash
##-----------------##
|
|
# Fetching Vars #
|
|
##-----------------##
|
|
|
|
if [ ! -f "/etc/ICTM/selopts.list" ] || [ ! -f "/etc/ICTM/mainvar.list" ] ; then echo 'This system is not yet setup, please run the main installer first' && exit ; fi
|
|
|
|
|
|
source /etc/ICTM/selopts.list
|
|
source /etc/ICTM/mainvar.list
|
|
rm /tmp/apt.list
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/ModulesMenu.list)
|
|
|
|
#Setting Menulist to webserver
|
|
if [[ $webserv = "apache" ]]; then
|
|
#Apache Menulist
|
|
CMSL=("${apacheCMSL[@]}")
|
|
options=("${apacheOptions[@]}")
|
|
fi
|
|
if [[ $webserv = "nginx" ]]; then
|
|
#Nginx Menulist
|
|
CMSL=("${nginxCMSL[@]}")
|
|
options=("${nginxOptions[@]}")
|
|
fi
|
|
|
|
|
|
##----------------##
|
|
# Static-Vars #
|
|
##----------------##
|
|
|
|
ignphpcms=1
|
|
|
|
|
|
##---------------##
|
|
# Functions #
|
|
##---------------##
|
|
|
|
msg () {
|
|
if [ $IMODE = n ]; then
|
|
TERM=ansi whiptail --title "Info" --infobox "$1" 8 52
|
|
fi
|
|
if [ $IMODE = l ]; then
|
|
echo "$1"
|
|
fi
|
|
}
|
|
|
|
function PasswordQuest {
|
|
passdia=$(whiptail --nocancel --passwordbox "Please enter your password (Must be the same as the mysql/root password)" 11 91 --title "Config" 3>&1 1>&2 2>&3)
|
|
if [ -z $passdia ]; then PasswordQuest; fi
|
|
mysql -uroot -p"$passdia" -e "" > /dev/null 2>&1
|
|
if [ $? = 0 ]; then
|
|
password="$passdia"
|
|
unset passdia
|
|
else
|
|
whiptail --ok-button Done --msgbox " Password is incorrect!" 10 30
|
|
unset passdia
|
|
PasswordQuest
|
|
fi
|
|
}
|
|
|
|
function LegacyPasswordQuest {
|
|
echo "Enter password (Must be the same as the mysql/root password)"
|
|
read -s passdia
|
|
if [ -z $passdia ]; then LegacyPasswordQuest; fi
|
|
mysql -uroot -p"$passdia" -e "" > /dev/null 2>&1
|
|
if [ $? = 0 ]; then
|
|
password="$passdia"
|
|
unset passdia
|
|
else
|
|
echo "Password is incorrect!"
|
|
unset passdia
|
|
LegacyPasswordQuest
|
|
fi
|
|
}
|
|
|
|
|
|
##--------##
|
|
# Menu #
|
|
##--------##
|
|
|
|
if [ $IMODE = n ]; then
|
|
domain=$(whiptail --nocancel --inputbox " Enter the domain without WWW " 11 82 --title "Config" 3>&1 1>&2 2>&3)
|
|
[[ -d "/var/www/"$domain"/html" ]] && msg " This domain already exists on this server, Exiting" 8 78 && exit;
|
|
if (whiptail --title "Config" --yesno " Does www.${domain} exist in DNS" 8 78); then domainwww=1; else domainwww=0; fi
|
|
if (whiptail --title "Set sitename?" --yesno "Set sitename to ${domain//./_} ?" 8 78); then
|
|
sitename=${domain//./_}
|
|
else
|
|
while true; do
|
|
sitename=$(whiptail --nocancel --inputbox "Enter sitename, Must NOT contain special characters, except: _" 8 78 --title "Sitename" 3>&1 1>&2 2>&3)
|
|
if [[ $sitename == *['!'@#\$%^\&*()+,.]* ]] || [ -z "$sitename" ]
|
|
then
|
|
whiptail --msgbox " Site can't be empty, or contain a special character except for: _" 11 78
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
if (whiptail --title "Config" --yesno " Enable SSL on installation?" 11 78); then sslenable=1; else sslenable=0; fi
|
|
PasswordQuest
|
|
CMS=$(whiptail --title "What CMS should be installed?" --radiolist "Features" 11 118 5 "${CMSL[@]}" 3>&1 1>&2 2>&3)
|
|
[[ "$?" = 1 ]] && msg " Quiting installer" 8 78 && exit;
|
|
fi
|
|
|
|
if [ $IMODE = l ]; then
|
|
echo "" >/dev/null
|
|
echo "Enter the domain without WWW:"
|
|
read domain
|
|
[[ -d "/var/www/"$domain"/html" ]] && echo " This domain already exists on this server, Exiting" && exit;
|
|
while true; do
|
|
read -p "Does www.${domain} exist in DNS -> yes/no?" yn
|
|
case $yn in
|
|
[Yy]* ) domainwww=1
|
|
break;;
|
|
[Nn]* ) domainwww=0
|
|
break;;
|
|
* ) echo "Choose yes of no.";;
|
|
esac
|
|
done
|
|
read -p "Set sitename to ${domain//./_}? (y/n)" choice
|
|
case "$choice" in
|
|
y|Y ) sitename=${domain//./_};;
|
|
n|N ) echo "";
|
|
while true; do
|
|
echo "Please enter sitename, Must NOT contain special characters, except: _";read sitename
|
|
if [[ $sitename == *['!'@#\$%^\&*()+,.]* ]] || [ -z "$sitename" ]
|
|
then
|
|
echo "Site can't be empty, or contain a special character except for: _"
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
;;
|
|
* ) echo "invalid";;
|
|
esac
|
|
|
|
while true; do
|
|
read -p "Enable SSL on installation? -> yes/no?" yn
|
|
case $yn in
|
|
[Yy]* ) sslenable=1
|
|
break;;
|
|
[Nn]* ) sslenable=0
|
|
break;;
|
|
* ) echo "Choose yes of no.";;
|
|
esac
|
|
done
|
|
LegacyPasswordQuest
|
|
echo "What CMS should be installed?"
|
|
#CMSPromt
|
|
select CMS in "${CMSL[@]}"; do
|
|
case CMS in
|
|
"") echo 'Invalid choice' >&2 ;;
|
|
*) break
|
|
esac
|
|
done
|
|
fi
|
|
|
|
#Cleaning options from menu
|
|
CMS="${CMS//:}" && CMS="${CMS,,}"
|
|
|
|
|
|
##-----------##
|
|
# AptList #
|
|
##-----------##
|
|
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CMS/"$CMS"/apt.list >>/tmp/apt.list; then
|
|
curl "$repo"/raw/branch/"$branch"/CMS/"$CMS"/apt.list >>/tmp/apt.list
|
|
printf " " >>/tmp/apt.list
|
|
fi
|
|
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CMS/"$CMS"/"$webserv"-apt.list; then
|
|
curl "$repo"/raw/branch/"$branch"/CMS/"$CMS"/"$webserv"-apt.list >>/tmp/apt.list
|
|
printf " " >>/tmp/apt.list
|
|
fi
|
|
|
|
|
|
##-----------##
|
|
# Preconf #
|
|
##-----------##
|
|
|
|
msg " Running preconf for Webserv"
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CoreModules/"$webserv"/appendCMS-preconf.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CoreModules/"$webserv"/appendCMS-preconf.sh)
|
|
fi
|
|
|
|
msg " Running preconf for CMS"
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CMS/"$CMS"/preconf.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CMS/"$CMS"/preconf.sh)
|
|
fi
|
|
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CMS/"$CMS"/"$webserv"-preconf.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CMS/"$CMS"/"$webserv"-preconf.sh)
|
|
fi
|
|
|
|
|
|
##-------------##
|
|
# Installer #
|
|
##-------------##
|
|
|
|
$PKGM update
|
|
sed -i 's/PHPver/'$phpver'/g' /tmp/apt.list
|
|
cat /tmp/apt.list | xargs $PKGI
|
|
|
|
|
|
##---------------##
|
|
# Configuring #
|
|
##---------------##
|
|
|
|
msg " Running conf for Webserv"
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CoreModules/"$webserv"/appendCMS-conf.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CoreModules/"$webserv"/appendCMS-conf.sh)
|
|
fi
|
|
|
|
if [ $sslenable = 1 ]; then
|
|
msg " Setting up SSL"
|
|
site_ext=ssl
|
|
if [ $domainwww = 1 ]; then
|
|
certbot --"$webserv" certonly -n -d "$domain" -d "www.$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos
|
|
elif [ $domainwww = 0 ]; then
|
|
certbot --"$webserv" certonly -n -d "$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos
|
|
fi
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CoreModules/"$webserv"/ssl-handler.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CoreModules/"$webserv"/ssl-handler.sh)
|
|
fi
|
|
elif [ $sslenable = 0 ]; then
|
|
site_ext=nossl
|
|
fi
|
|
|
|
wget -q -t7 "$repo"/raw/branch/"$branch"/Scripts/EnableSSL.sh -O ~/activateSSL-$domain.sh
|
|
sed -i -e 's/DOMAINname/'$domain'/' -e 's/CONFname/'$sitename'/' -e 's/DomainWWW/'$domainwww'/' -e 's/Email/'$email'/' -e 's/WebServer/'$webserv'/' ~/activateSSL-$domain.sh
|
|
|
|
msg " Running conf for CMS"
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CMS/"$CMS"/conf.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CMS/"$CMS"/conf.sh)
|
|
fi
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/CMS/"$CMS"/"$webserv"-conf.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/CMS/"$CMS"/"$webserv"-conf.sh)
|
|
fi
|
|
|
|
##--------------------------##
|
|
# Backup-util Site Setup #
|
|
##--------------------------##
|
|
|
|
repobckutil=https://git.ictmaatwerk.com/VPS-scripts/Backup-Util
|
|
branchbckutil=master
|
|
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repobckutil"/raw/branch/"$branchbckutil"/cms-handeler.sh; then
|
|
source <(curl --retry 7 --retry-delay 5 -s "$repobckutil"/raw/branch/"$branchbckutil"/cms-handeler.sh)
|
|
fi
|
|
|
|
##------------##
|
|
# Services #
|
|
##------------##
|
|
|
|
systemctl reload fail2ban
|
|
|
|
##-------##
|
|
# Done #
|
|
##-------##
|
|
|
|
msg " Added CMS!"
|
|
for f in /etc/update-motd.d/51*; do bash $f; done |