diff --git a/AppendModule.sh b/AppendModule.sh new file mode 100644 index 0000000..ca1ac59 --- /dev/null +++ b/AppendModule.sh @@ -0,0 +1,254 @@ +##-----------------## +# Fetching Vars # +##-----------------## + +if [ ! -f "/etc/ICTM/selopts.list" ] || [ ! -f "/etc/ICTM/mainvar.list" ] ; then echo 'This system is not yet setup, pleas run the main installer first' && exit ; fi + + +##-----------------## +# Fetching Vars # +##-----------------## + +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 + +#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 "Title" --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 # +##-----------## + + +echo "Generating apt list for Options" +for val1 in ${option[*]}; do + echo "$val1" #TMP + modListed=$(wget -t7 -qO - "$repo"/raw/branch/master/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/branch/"$branch"/SubModules/"$val1"/apt.list; then + curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/SubModules/"$val1"/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"/SubModules/"$val1"/"$webserv"-apt.list; then + curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/SubModules/"$val1"/"$webserv"-apt.list >>/tmp/apt.list + printf " " >>/tmp/apt.list + fi + else + #Fetching from remote repo + if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed"apt.list; then + curl --retry 7 --retry-delay 5 -s "$modListed"apt.list >>/tmp/apt.list + printf " " >>/tmp/apt.list + fi + if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$modListed""$webserv"-apt.list; then + curl "$modListed""$webserv"-apt.list >>/tmp/apt.list + printf " " >>/tmp/apt.list + fi + fi +done + + +##-----------## +# Preconf # +##-----------## + +echo "Running preconf for Options" +for val1 in ${option[*]}; do + echo "$val1" #TMP + modListed=$(wget -t7 -qO - "$repo"/raw/branch/master/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/branch/"$branch"/SubModules/"$val1"/preconf.sh; then + source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/SubModules/"$val1"/preconf.sh) + fi + if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/SubModules/"$val1"/"$webserv"-preconf.sh; then + source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$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/PHPver/'$phpver'/g' /tmp/apt.list +cat /tmp/apt.list | xargs $PKGI + + +##---------------## +# Configuring # +##---------------## + +echo "Running conf for Options" +for val1 in ${option[*]}; do + echo "$val1" #TMP + modListed=$(wget -t7 -qO - "$repo"/raw/branch/master/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/branch/"$branch"/SubModules/"$val1"/conf.sh; then + source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$branch"/SubModules/"$val1"/conf.sh) + fi + if curl --retry 2 --retry-delay 1 --output /dev/null --silent --head --fail "$repo"/raw/branch/"$branch"/SubModules/"$val1"/"$webserv"-conf.sh; then + source <(curl --retry 7 --retry-delay 5 -s "$repo"/raw/branch/"$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