Files
VPS-scripts_Web-V2/AppendCMS.sh
2020-07-09 14:31:28 +02:00

199 lines
6.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
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 "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
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 #
##-----------##
echo "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
echo "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 #
##---------------##
echo "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
echo "Setting up SSL"
if [ $sslenable = 1 ]; then
if [ $domainwww = 1 ]; then
certbot --"$webserv" -n -d "$domain" -d "www.$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos
elif [ $domainwww = 0 ]; then
certbot --"$webserv" -n -d "$domain" -m "$email" --hsts --redirect --no-eff-email --agree-tos
fi
fi
wget -q -t7 "$repo"/raw/branch/"$branch"/Scripts/EnableSSL.sh -O ~/activateSSL-$domain.sh
sed -i -e 's/DOMAINname/'$domain'/' -e 's/CONFname/'$domain'/' -e 's/DomainWWW/'$domainwww'/' -e 's/Email/'$email'/' -e 's/WebServer/'$webserv'/' ~/activateSSL-$domain.sh
echo "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