Files
VPS-scripts_Web-V2/AppendModule.sh
Bram Prieshof be8d75bcab Replaced references php With vars
Done because differences between distros is quite big,
and this was the beter solution then using alot of if statements

List of changes:
* Replaced service names php"$phpver"-fpm with $phpFPMService
* Replaced PHPver in package list with phpPkgName
* Replaced full php config path with $phpMainConf
* Replaced php pool path with $phpPoolDir
2020-12-03 17:10:47 +01:00

271 lines
9.4 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
if [ ! -f "/etc/ICTM/phpvar.list" ] ; then echo 'Php var list missing,Please run /Scipts/GeneratePhplist from the repo ' && exit ; fi
##-----------------##
# Fetching Vars #
##-----------------##
source /etc/ICTM/selopts.list
source /etc/ICTM/mainvar.list
source /etc/ICTM/phpvar.list
rm /tmp/pkg.list
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/ModulesMenu.list)
#Setting Menulist to webserver
declare -n CMSL="$webserv"CMSL
declare -n options="$webserv"Options
#Filtering already installed modules
for target in "${SelectedOptions[@]}"; do
for i in "${!options[@]}"; do
if [[ ${options[i]} = $target ]]; then
unset 'options[i]'
if [ $IMODE = n ]; then
((i=i+1))
unset 'options[i]'
((i=i+1))
unset 'options[i]'
fi
fi
done
done
if [[ -z ${options[@]} ]]; then echo 'No new modules available' && exit ; fi
##---------------##
# 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
echo "Password is correct"
password="$passdia"
unset passdia
else
echo "Password is incorrect!"
unset passdia
LegacyPasswordQuest
fi
}
##--------##
# Menu #
##--------##
if [ $IMODE = n ]; then
PasswordQuest
option=$(whiptail --title "Config" --checklist "Features" 11 110 5 "${options[@]}" 3>&1 1>&2 2>&3)
[[ "$?" = 1 ]] && msg " Quiting installer" 8 78 && exit;
fi
if [ $IMODE = l ]; then
echo "" >/dev/null
LegacyPasswordQuest
choice () {
local choice=$1
if [[ ${opts[choice]} ]] # toggle
then
opts[choice]=
topt=${opt//+/}
topt="${topt%"${topt##*[![:space:]]}"}"
topt=\"$topt\"
option=${option//"$topt"/}
unset $topt
else
opts[choice]=+
opt="${opt%"${opt##*[![:space:]]}"}"
option+="\"$opt\" "
fi
}
echo "The first selection will always return a invalid option, please enter the first option twice"
PS3='Which addons should be installed?'
while :
do
echo ""
unset options2
unset OPTcounter
for E in "${options[@]}"; do
((OPTcounter++))
options2+=("${E} ${opts["$OPTcounter"]}")
done
options2+=("Done")
select opt in "${options2[@]}"
do
case $opt in
"Done") break 2;;
"") printf '%s\n' 'invalid option';;
*) choice $REPLY
break
;;
esac
done
done
option="${option%"${option##*[![:space:]]}"}"
fi
echo 'SelectedOptions+=('$option')' >> /etc/ICTM/selopts.list
#Cleaning options from menu
option="${option,,}" && option="${option// /}" && option="${option//:/ }" && option="${option//'"'}"
#Combining selected option with always-on options
option="$option""$aonoption"
##-----------##
# AptList #
##-----------##
msg " Generating apt list for Options"
for val1 in ${option[*]}; do
modListed=$(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/extModules.list|grep "$val1")
#Checking
if test -z "$modListed"
then
#Fetching from local repo
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/generic.pkg.list; then
curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/generic.pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-generic.pkg.list; then
curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-generic.pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$PKGLIST".pkg.list; then
curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$PKGLIST".pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-"$PKGLIST".pkg.list; then
curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-"$PKGLIST".pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
else
#Fetching from remote repo
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed"generic.pkg.list; then
curl --retry 7 --retry-delay 5 -s "$modListed"generic.pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed""$webserv"-generic.pkg.list; then
curl "$modListed""$webserv"-generic.pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed""$PKGLIST".pkg.list; then
curl --retry 7 --retry-delay 5 -s "$modListed""$PKGLIST".pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed""$webserv"-"$PKGLIST".pkg.list; then
curl "$modListed""$webserv"-"$PKGLIST".pkg.list >>/tmp/pkg.list
printf " " >>/tmp/pkg.list
fi
fi
done
##-----------##
# Preconf #
##-----------##
msg " Running preconf for Options"
for val1 in ${option[*]}; do
msg "Pre-configuring $val1"
modListed=$(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/extModules.list|grep "$val1")
#Checking
if test -z "$modListed"
then
#Fetching from local repo
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/preconf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/preconf.sh)
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-preconf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-preconf.sh)
fi
else
#Fetching from remote repo
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed"preconf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$modListed"preconf.sh)
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed""$webserv"-preconf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$modListed""$webserv"-preconf.sh)
fi
fi
done
##-------------##
# Installer #
##-------------##
$PKGM update
sed -i 's/PHPprefix/'$phpPkgName'/g' /tmp/pkg.list
cat /tmp/pkg.list | xargs $PKGI
##---------------##
# Configuring #
##---------------##
msg " Running conf for Options"
for val1 in ${option[*]}; do
msg "Configuring $val1"
modListed=$(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/extModules.list|grep "$val1")
#Checking
if test -z "$modListed"
then
#Fetching from local repo
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/conf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/conf.sh)
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-conf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/"$branchtype"/"$branch"/SubModules/"$val1"/"$webserv"-conf.sh)
fi
else
#Fetching from remote repo
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed"conf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$modListed"conf.sh)
fi
if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed""$webserv"-conf.sh; then
source <(curl --retry 7 --retry-delay 5 -s "$modListed""$webserv"-conf.sh)
fi
fi
done
##-------##
# Done #
##-------##
msg " Added Module!"
if stat --printf='' /etc/update-motd.d/51* 2>/dev/null; then for f in /etc/update-motd.d/51*; do bash $f; done; fi