Files
condor 679e0b4184 init
2026-07-24 18:54:53 +08:00

298 lines
13 KiB
Bash

#!/bin/bash
# core/menu.sh - interactive menu
# Migrated verbatim from install.sh (lines 236-691). Logic unchanged.
show_menu() {
if [ ${ARG_NUM} == 0 ]; then
if [ ! -e ~/.oneinstack ]; then
# check iptables
# Default to 'y': ServerStack only supports Debian/Ubuntu (firewalld/ufw
# were removed), so iptables is the firewall for every supported system.
# The user can still answer 'n' to opt out.
while :; do echo
read -e -p "Do you want to enable iptables? [y/n] (default y):" iptables_flag
[ -z "${iptables_flag}" ] && iptables_flag=y
if [[ ! ${iptables_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
break
fi
done
fi
# check Web server
while :; do echo
read -e -p "Do you want to install Web server? [y/n]: " web_flag
if [[ ! ${web_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
if [ "${web_flag}" == 'y' ]; then
# Nginx
while :; do echo
echo 'Please select Nginx server:'
echo -e "\t${CMSG}1${CEND}. Install Nginx"
echo -e "\t${CMSG}2${CEND}. Do not install"
read -e -p "Please input a number:(Default 1 press Enter)" nginx_option
nginx_option=${nginx_option:-1}
if [[ ! ${nginx_option} =~ ^[1-2]$ ]]; then
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
else
[ "${nginx_option}" != '2' -a -e "${nginx_install_dir}/sbin/nginx" ] && { echo "${CWARNING}Nginx already installed! ${CEND}"; unset nginx_option; }
break
fi
done
fi
break
fi
done
# choice database
while :; do echo
read -e -p "Do you want to install Database? [y/n]: " db_flag
if [[ ! ${db_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
if [ "${db_flag}" == 'y' ]; then
while :; do echo
echo 'Please select a version of the Database:'
echo -e "\t${CMSG} 1${CEND}. Install MySQL-8.0"
echo -e "\t${CMSG} 2${CEND}. Install MySQL-5.7"
echo -e "\t${CMSG} 3${CEND}. Install MariaDB-10.11"
echo -e "\t${CMSG} 4${CEND}. Install MariaDB-11.8"
echo -e "\t${CMSG} 5${CEND}. Install MariaDB-12.3"
echo -e "\t${CMSG} 6${CEND}. Install PostgreSQL-15.14"
echo -e "\t${CMSG} 7${CEND}. Install PostgreSQL-16.10"
echo -e "\t${CMSG} 8${CEND}. Install PostgreSQL-17.6"
echo -e "\t${CMSG} 9${CEND}. Install MongoDB"
read -e -p "Please input a number:(Default 3 press Enter) " db_option
db_option=${db_option:-3}
if [[ "${db_option}" =~ ^[1-9]$ ]]; then
if [[ "${db_option}" =~ ^[6-8]$ ]]; then
[ -e "${pgsql_install_dir}/bin/psql" ] && { echo "${CWARNING}PostgreSQL already installed! ${CEND}"; unset db_option; break; }
elif [ "${db_option}" == '9' ]; then
[ -e "${mongo_install_dir}/bin/mongo" ] && { echo "${CWARNING}MongoDB already installed! ${CEND}"; unset db_option; break; }
else
[ -d "${db_install_dir}/support-files" ] && { echo "${CWARNING}MySQL/MariaDB already installed! ${CEND}"; unset db_option; break; }
fi
while :; do
if [[ "${db_option}" =~ ^[6-8]$ ]]; then
read -e -p "Please input the postgres password of PostgreSQL(default: ${dbpostgrespwd}): " dbpwd
dbpwd=${dbpwd:-${dbpostgrespwd}}
elif [ "${db_option}" == '9' ]; then
read -e -p "Please input the root password of MongoDB(default: ${dbmongopwd}): " dbpwd
dbpwd=${dbpwd:-${dbmongopwd}}
else
read -e -p "Please input the root password of MySQL/MariaDB(default: ${dbrootpwd}): " dbpwd
dbpwd=${dbpwd:-${dbrootpwd}}
fi
[ -n "`echo ${dbpwd} | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and & ${CEND}"; continue; }
if (( ${#dbpwd} >= 5 )); then
if [[ "${db_option}" =~ ^[6-8]$ ]]; then
dbpostgrespwd=${dbpwd}
elif [ "${db_option}" == '9' ]; then
dbmongopwd=${dbpwd}
else
dbrootpwd=${dbpwd}
fi
break
else
echo "${CWARNING}password least 5 characters! ${CEND}"
fi
done
# choose install methods
if [[ "${db_option}" =~ ^[1-5]$ ]]; then
while :; do echo
echo "Please choose installation of the database:"
echo -e "\t${CMSG}1${CEND}. Install database from binary package."
echo -e "\t${CMSG}2${CEND}. Install database from source package."
read -e -p "Please input a number:(Default 1 press Enter) " dbinstallmethod
dbinstallmethod=${dbinstallmethod:-1}
if [[ ! ${dbinstallmethod} =~ ^[1-2]$ ]]; then
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
else
break
fi
done
fi
break
else
echo "${CWARNING}input error! Please only input number 1~9${CEND}"
fi
done
fi
break
fi
done
# choice php
while :; do echo
read -e -p "Do you want to install PHP? [y/n]: " php_flag
if [[ ! ${php_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
if [ "${php_flag}" == 'y' ]; then
[ -e "${php_install_dir}/bin/phpize" ] && { echo "${CWARNING}PHP already installed! ${CEND}"; unset php_option; break; }
while :; do echo
echo 'Please select a version of the PHP:'
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ]; then
echo -e "\t${CMSG} 1${CEND}. Install php-7.4 ${CWARNING}(unavailable on Ubuntu ${Ubuntu_ver}+, only PHP 8.x is supported)${CEND}"
echo -e "\t${CMSG} 2${CEND}. Install php-8.0"
echo -e "\t${CMSG} 3${CEND}. Install php-8.1"
else
echo -e "\t${CMSG} 1${CEND}. Install php-7.4"
echo -e "\t${CMSG} 2${CEND}. Install php-8.0"
echo -e "\t${CMSG} 3${CEND}. Install php-8.1"
fi
read -e -p "Please input a number:(Default 1 press Enter) " php_option
php_option=${php_option:-1}
if [[ ! ${php_option} =~ ^[1-3]$ ]]; then
echo "${CWARNING}input error! Please only input number 1~3${CEND}"
elif [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ] && [ "${php_option}" == '1' ]; then
echo "${CWARNING}PHP 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please select PHP 8.x (option 2 or 3)${CEND}"
else
break
fi
done
fi
break
fi
done
# check php ver
if [ -e "${php_install_dir}/bin/phpize" ]; then
PHP_detail_ver=$(${php_install_dir}/bin/php-config --version)
PHP_main_ver=${PHP_detail_ver%.*}
fi
# PHP opcode cache and extensions
if [[ ${php_option} =~ ^[1-3]$ ]] || [ -e "${php_install_dir}/bin/phpize" ]; then
while :; do echo
read -e -p "Do you want to install opcode cache of the PHP? [y/n]: " phpcache_flag
if [[ ! ${phpcache_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
if [ "${phpcache_flag}" == 'y' ]; then
if [[ ${php_option} =~ ^[1-3]$ ]] || [[ "${PHP_main_ver}" =~ ^7.[0-4]$|^8.[0-1]$ ]]; then
while :; do
echo 'Please select a opcode cache of the PHP:'
echo -e "\t${CMSG}1${CEND}. Install Zend OPcache"
echo -e "\t${CMSG}2${CEND}. Install APCU"
read -e -p "Please input a number:(Default 1 press Enter) " phpcache_option
phpcache_option=${phpcache_option:-1}
if [[ ! ${phpcache_option} =~ ^[1-2]$ ]]; then
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
else
break
fi
done
fi
fi
break
fi
done
# set xcache passwd
if [ "${phpcache_option}" == '3' ]; then
while :; do
read -e -p "Please input xcache admin password: " xcachepwd
(( ${#xcachepwd} >= 5 )) && { xcachepwd_md5=$(echo -n "${xcachepwd}" | md5sum | awk '{print $1}') ; break ; } || echo "${CFAILURE}xcache admin password least 5 characters! ${CEND}"
done
fi
# PHP extension
while :; do
echo
echo 'Please select PHP extensions:'
echo -e "\t${CMSG} 0${CEND}. Do not install"
echo -e "\t${CMSG} 1${CEND}. Install zendguardloader(PHP<=5.6)"
echo -e "\t${CMSG} 2${CEND}. Install ioncube"
echo -e "\t${CMSG} 3${CEND}. Install sourceguardian(PHP<=7.2)"
echo -e "\t${CMSG} 4${CEND}. Install imagick"
echo -e "\t${CMSG} 5${CEND}. Install gmagick"
echo -e "\t${CMSG} 6${CEND}. Install fileinfo"
echo -e "\t${CMSG} 7${CEND}. Install imap"
echo -e "\t${CMSG} 8${CEND}. Install ldap"
echo -e "\t${CMSG} 9${CEND}. Install phalcon(PHP>=5.5)"
echo -e "\t${CMSG}10${CEND}. Install yaf(PHP>=7.0)"
echo -e "\t${CMSG}11${CEND}. Install redis"
echo -e "\t${CMSG}12${CEND}. Install mongodb"
echo -e "\t${CMSG}13${CEND}. Install swoole"
echo -e "\t${CMSG}14${CEND}. Install xdebug(PHP>=5.5)"
read -e -p "Please input numbers:(Default '4 6 11 12' press Enter) " phpext_option
phpext_option=${phpext_option:-'4 6 11 12'}
[ "${phpext_option}" == '0' ] && break
array_phpext=(${phpext_option})
array_all=(1 2 3 4 5 6 7 8 9 10 11 12 13 14)
for v in ${array_phpext[@]}
do
[ -z "`echo ${array_all[@]} | grep -w ${v}`" ] && phpext_flag=1
done
if [ "${phpext_flag}" == '1' ]; then
unset phpext_flag
echo; echo "${CWARNING}input error! Please only input number 4 11 12 and so on${CEND}"; echo
continue
else
[ -n "`echo ${array_phpext[@]} | grep -w 1`" ] && pecl_zendguardloader=1
[ -n "`echo ${array_phpext[@]} | grep -w 2`" ] && pecl_ioncube=1
[ -n "`echo ${array_phpext[@]} | grep -w 3`" ] && pecl_sourceguardian=1
[ -n "`echo ${array_phpext[@]} | grep -w 4`" ] && pecl_imagick=1
[ -n "`echo ${array_phpext[@]} | grep -w 5`" ] && pecl_gmagick=1
[ -n "`echo ${array_phpext[@]} | grep -w 6`" ] && pecl_fileinfo=1
[ -n "`echo ${array_phpext[@]} | grep -w 7`" ] && pecl_imap=1
[ -n "`echo ${array_phpext[@]} | grep -w 8`" ] && pecl_ldap=1
[ -n "`echo ${array_phpext[@]} | grep -w 9`" ] && pecl_phalcon=1
[ -n "`echo ${array_phpext[@]} | grep -w 10`" ] && pecl_yaf=1
[ -n "`echo ${array_phpext[@]} | grep -w 11`" ] && pecl_redis=1
[ -n "`echo ${array_phpext[@]} | grep -w 12`" ] && pecl_mongodb=1
[ -n "`echo ${array_phpext[@]} | grep -w 13`" ] && pecl_swoole=1
[ -n "`echo ${array_phpext[@]} | grep -w 14`" ] && pecl_xdebug=1
break
fi
done
fi
# check Nodejs
while :; do echo
read -e -p "Do you want to install Nodejs? [y/n]: " nodejs_flag
if [[ ! ${nodejs_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
[ "${nodejs_flag}" == 'y' -a -e "${nodejs_install_dir}/bin/node" ] && { echo "${CWARNING}Nodejs already installed! ${CEND}"; unset nodejs_flag; }
break
fi
done
# check Pureftpd
while :; do echo
read -e -p "Do you want to install Pure-FTPd? [y/n]: " pureftpd_flag
if [[ ! ${pureftpd_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
[ "${pureftpd_flag}" == 'y' -a -e "${pureftpd_install_dir}/sbin/pure-ftpwho" ] && { echo "${CWARNING}Pure-FTPd already installed! ${CEND}"; unset pureftpd_flag; }
break
fi
done
# check phpMyAdmin
if [[ ${php_option} =~ ^[1-3]$ ]] || [ -e "${php_install_dir}/bin/phpize" ]; then
while :; do echo
read -e -p "Do you want to install phpMyAdmin? [y/n]: " phpmyadmin_flag
if [[ ! ${phpmyadmin_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
[ "${phpmyadmin_flag}" == 'y' -a -d "${wwwroot_dir}/default/phpMyAdmin" ] && { echo "${CWARNING}phpMyAdmin already installed! ${CEND}"; unset phpmyadmin_flag; }
break
fi
done
fi
# check redis
while :; do echo
read -e -p "Do you want to install redis-server? [y/n]: " redis_flag
if [[ ! ${redis_flag} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
[ "${redis_flag}" == 'y' -a -e "${redis_install_dir}/bin/redis-server" ] && { echo "${CWARNING}redis-server already installed! ${CEND}"; unset redis_flag; }
break
fi
done
fi
}