184 lines
8.3 KiB
Bash
184 lines
8.3 KiB
Bash
#!/bin/bash
|
|
# core/argument.sh - version/help/argument parsing
|
|
# Migrated verbatim from install.sh (lines 38-41,43-74,75-213,215-234).
|
|
version() {
|
|
echo "version: 2.6"
|
|
echo "updated date: 2022-09-03"
|
|
}
|
|
Show_Help() {
|
|
version
|
|
echo "Usage: $0 command ...[parameters]....
|
|
--help, -h Show this help message, More: https://oneinstack.com/auto
|
|
--version, -v Show version info
|
|
--nginx_option [1-2] Install Nginx server version
|
|
--php_option [1-3] Install PHP version
|
|
--mphp_ver [74/80/81] Install another PHP version (PATH: ${php_install_dir}\${mphp_ver})
|
|
--mphp_addons Only install another PHP addons
|
|
--phpcache_option [1-4] Install PHP opcode cache, default: 1 opcache
|
|
--php_extensions [ext name] Install PHP extensions, include zendguardloader,ioncube,
|
|
sourceguardian,imagick,gmagick,fileinfo,imap,ldap,calendar,phalcon,
|
|
yaf,yar,redis,mongodb,swoole,xdebug
|
|
--nodejs Install Nodejs
|
|
--db_option [1-9] Install DB version
|
|
--dbinstallmethod [1-2] DB install method, default: 1 binary install
|
|
--dbrootpwd [password] DB super password
|
|
--pureftpd Install Pure-Ftpd
|
|
--redis Install Redis
|
|
--phpmyadmin Install phpMyAdmin
|
|
--python Install Python (PATH: ${python_install_dir})
|
|
--ssh_port [No.] SSH port
|
|
--iptables Enable iptables (enabled by default on all systems)
|
|
--reboot Restart the server after installation
|
|
"
|
|
}
|
|
# core/argument.sh (cont) - parse_arguments (getopt)
|
|
# Migrated verbatim from install.sh (lines 75-213); calls handle_ssh_port.
|
|
parse_arguments() {
|
|
ARG_NUM=$#
|
|
TEMP=`getopt -o hvV --long help,version,nginx_option:,php_option:,mphp_ver:,mphp_addons,phpcache_option:,php_extensions:,nodejs,db_option:,dbrootpwd:,dbinstallmethod:,pureftpd,redis,phpmyadmin,python,ssh_port:,iptables,reboot -- "$@" 2>/dev/null`
|
|
[ $? != 0 ] && echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
|
eval set -- "${TEMP}"
|
|
while :; do
|
|
[ -z "$1" ] && break;
|
|
case "$1" in
|
|
-h|--help)
|
|
Show_Help; exit 0
|
|
;;
|
|
-v|-V|--version)
|
|
version; exit 0
|
|
;;
|
|
--nginx_option)
|
|
nginx_option=$2; shift 2
|
|
[[ ! ${nginx_option} =~ ^[1-2]$ ]] && { echo "${CWARNING}nginx_option input error! Please only input number 1~2${CEND}"; exit 1; }
|
|
[ -e "${nginx_install_dir}/sbin/nginx" ] && { echo "${CWARNING}Nginx already installed! ${CEND}"; unset nginx_option; }
|
|
;;
|
|
--php_option)
|
|
php_option=$2; shift 2
|
|
[[ ! ${php_option} =~ ^[1-3]$ ]] && { echo "${CWARNING}php_option input error! Please only input number 1~3${CEND}"; exit 1; }
|
|
[ -e "${php_install_dir}/bin/phpize" ] && { echo "${CWARNING}PHP already installed! ${CEND}"; unset php_option; }
|
|
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ] && [ "${php_option}" == '1' ]; then
|
|
echo "${CWARNING}PHP 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please choose PHP 8.x (php_option 2 or 3)${CEND}"; exit 1;
|
|
fi
|
|
;;
|
|
--mphp_ver)
|
|
mphp_ver=$2; mphp_flag=y; shift 2
|
|
[[ ! "${mphp_ver}" =~ ^(74|80|81)$ ]] && { echo "${CWARNING}mphp_ver input error! Please only input number 74/80/81${CEND}"; exit 1; }
|
|
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ] && [ "${mphp_ver}" == '74' ]; then
|
|
echo "${CWARNING}mphp 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please choose 80 or 81${CEND}"; exit 1;
|
|
fi
|
|
;;
|
|
--mphp_addons)
|
|
mphp_addons_flag=y; shift 1
|
|
;;
|
|
--phpcache_option)
|
|
phpcache_option=$2; shift 2
|
|
;;
|
|
--php_extensions)
|
|
php_extensions=$2; shift 2
|
|
[ -n "`echo ${php_extensions} | grep -w zendguardloader`" ] && pecl_zendguardloader=1
|
|
[ -n "`echo ${php_extensions} | grep -w ioncube`" ] && pecl_ioncube=1
|
|
[ -n "`echo ${php_extensions} | grep -w sourceguardian`" ] && pecl_sourceguardian=1
|
|
[ -n "`echo ${php_extensions} | grep -w imagick`" ] && pecl_imagick=1
|
|
[ -n "`echo ${php_extensions} | grep -w gmagick`" ] && pecl_gmagick=1
|
|
[ -n "`echo ${php_extensions} | grep -w fileinfo`" ] && pecl_fileinfo=1
|
|
[ -n "`echo ${php_extensions} | grep -w imap`" ] && pecl_imap=1
|
|
[ -n "`echo ${php_extensions} | grep -w ldap`" ] && pecl_ldap=1
|
|
[ -n "`echo ${php_extensions} | grep -w calendar`" ] && pecl_calendar=1
|
|
[ -n "`echo ${php_extensions} | grep -w phalcon`" ] && pecl_phalcon=1
|
|
[ -n "`echo ${php_extensions} | grep -w yaf`" ] && pecl_yaf=1
|
|
[ -n "`echo ${php_extensions} | grep -w yar`" ] && pecl_yar=1
|
|
[ -n "`echo ${php_extensions} | grep -w redis`" ] && pecl_redis=1
|
|
[ -n "`echo ${php_extensions} | grep -w mongodb`" ] && pecl_mongodb=1
|
|
[ -n "`echo ${php_extensions} | grep -w swoole`" ] && pecl_swoole=1
|
|
[ -n "`echo ${php_extensions} | grep -w xdebug`" ] && pecl_xdebug=1
|
|
;;
|
|
--nodejs)
|
|
nodejs_flag=y; shift 1
|
|
[ -e "${nodejs_install_dir}/bin/node" ] && { echo "${CWARNING}Nodejs already installed! ${CEND}"; unset nodejs_flag; }
|
|
;;
|
|
--db_option)
|
|
db_option=$2; shift 2
|
|
if [[ "${db_option}" =~ ^[1-5]$ ]]; then
|
|
[ -d "${db_install_dir}/support-files" ] && { echo "${CWARNING}MySQL/MariaDB already installed! ${CEND}"; unset db_option; }
|
|
elif [[ "${db_option}" =~ ^[6-8]$ ]]; then
|
|
[ -e "${pgsql_install_dir}/bin/psql" ] && { echo "${CWARNING}PostgreSQL already installed! ${CEND}"; unset db_option; }
|
|
elif [ "${db_option}" == '9' ]; then
|
|
[ -e "${mongo_install_dir}/bin/mongo" ] && { echo "${CWARNING}MongoDB already installed! ${CEND}"; unset db_option; }
|
|
else
|
|
echo "${CWARNING}db_option input error! Please only input number 1~9${CEND}"
|
|
exit 1
|
|
fi
|
|
;;
|
|
--dbrootpwd)
|
|
dbrootpwd=$2; shift 2
|
|
dbpostgrespwd="${dbrootpwd}"
|
|
dbmongopwd="${dbrootpwd}"
|
|
;;
|
|
--dbinstallmethod)
|
|
dbinstallmethod=$2; shift 2
|
|
[[ ! ${dbinstallmethod} =~ ^[1-2]$ ]] && { echo "${CWARNING}dbinstallmethod input error! Please only input number 1~2${CEND}"; exit 1; }
|
|
;;
|
|
--pureftpd)
|
|
pureftpd_flag=y; shift 1
|
|
[ -e "${pureftpd_install_dir}/sbin/pure-ftpwho" ] && { echo "${CWARNING}Pure-FTPd already installed! ${CEND}"; unset pureftpd_flag; }
|
|
;;
|
|
--redis)
|
|
redis_flag=y; shift 1
|
|
[ -e "${redis_install_dir}/bin/redis-server" ] && { echo "${CWARNING}redis-server already installed! ${CEND}"; unset redis_flag; }
|
|
;;
|
|
--phpmyadmin)
|
|
phpmyadmin_flag=y; shift 1
|
|
[ -d "${wwwroot_dir}/default/phpMyAdmin" ] && { echo "${CWARNING}phpMyAdmin already installed! ${CEND}"; unset phpmyadmin_flag; }
|
|
;;
|
|
--python)
|
|
python_flag=y; shift 1
|
|
;;
|
|
--ssh_port)
|
|
ssh_port=$2; shift 2
|
|
;;
|
|
--iptables)
|
|
iptables_flag=y; shift 1
|
|
;;
|
|
--reboot)
|
|
reboot_flag=y; shift 1
|
|
;;
|
|
--)
|
|
shift
|
|
;;
|
|
*)
|
|
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
|
;;
|
|
esac
|
|
done
|
|
# Default-enable iptables for every supported system. ServerStack only
|
|
# supports Debian/Ubuntu (firewalld/ufw removed), so iptables is the sole
|
|
# firewall; non-interactive installs that omit --iptables still get it. A
|
|
# user can still answer 'n' in the interactive menu to opt out.
|
|
iptables_flag=${iptables_flag:-y}
|
|
# SSH port handling (migrated verbatim, lines 215-234)
|
|
handle_ssh_port
|
|
}
|
|
|
|
handle_ssh_port() {
|
|
# Use default SSH port 22. If you use another SSH port on your server
|
|
if [ -e "/etc/ssh/sshd_config" ]; then
|
|
[ -z "`grep ^Port /etc/ssh/sshd_config`" ] && now_ssh_port=22 || now_ssh_port=`grep ^Port /etc/ssh/sshd_config | awk '{print $2}' | head -1`
|
|
while :; do echo
|
|
[ ${ARG_NUM} == 0 ] && read -e -p "Please input SSH port(Default: ${now_ssh_port}): " ssh_port
|
|
ssh_port=${ssh_port:-${now_ssh_port}}
|
|
if [ ${ssh_port} -eq 22 >/dev/null 2>&1 -o ${ssh_port} -gt 1024 >/dev/null 2>&1 -a ${ssh_port} -lt 65535 >/dev/null 2>&1 ]; then
|
|
break
|
|
else
|
|
echo "${CWARNING}input error! Input range: 22,1025~65534${CEND}"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
if [ -z "`grep ^Port /etc/ssh/sshd_config`" -a "${ssh_port}" != '22' ]; then
|
|
sed -i "s@^#Port.*@&\nPort ${ssh_port}@" /etc/ssh/sshd_config
|
|
elif [ -n "`grep ^Port /etc/ssh/sshd_config`" ]; then
|
|
sed -i "s@^Port.*@Port ${ssh_port}@" /etc/ssh/sshd_config
|
|
fi
|
|
fi
|
|
}
|