This commit is contained in:
condor
2026-07-24 18:54:53 +08:00
parent 43c2a411b9
commit 679e0b4184
128 changed files with 13855 additions and 1 deletions
+183
View File
@@ -0,0 +1,183 @@
#!/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
}
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
DEMO() {
pushd ${oneinstack_dir}/src > /dev/null
if [ ! -e ${wwwroot_dir}/default/index.html ]; then
[ "${IPADDR_COUNTRY}"x == "CN"x ] && /bin/cp ${oneinstack_dir}/config/index_cn.html ${wwwroot_dir}/default/index.html || /bin/cp ${oneinstack_dir}/config/index.html ${wwwroot_dir}/default
fi
if [ -e "${php_install_dir}/bin/php" ]; then
src_url=http://mirrors.linuxeye.com/oneinstack/src/xprober.php && Download_src
/bin/cp xprober.php ${wwwroot_dir}/default
echo "<?php phpinfo() ?>" > ${wwwroot_dir}/default/phpinfo.php
case "${phpcache_option}" in
1)
src_url=http://mirrors.linuxeye.com/oneinstack/src/ocp.php && Download_src
/bin/cp ocp.php ${wwwroot_dir}/default
;;
2)
sed -i 's@<a href="/ocp.php" target="_blank" class="links">Opcache</a>@<a href="/apc.php" target="_blank" class="links">APC</a>@' ${wwwroot_dir}/default/index.html
;;
3)
sed -i 's@<a href="/ocp.php" target="_blank" class="links">Opcache</a>@<a href="/xcache" target="_blank" class="links">xcache</a>@' ${wwwroot_dir}/default/index.html
;;
4)
/bin/cp eaccelerator-*/control.php ${wwwroot_dir}/default
sed -i 's@<a href="/ocp.php" target="_blank" class="links">Opcache</a>@<a href="/control.php" target="_blank" class="links">eAccelerator</a>@' ${wwwroot_dir}/default/index.html
;;
*)
sed -i 's@<a href="/ocp.php" target="_blank" class="links">Opcache</a>@@' ${wwwroot_dir}/default/index.html
;;
esac
fi
chown -R ${run_user}:${run_group} ${wwwroot_dir}/default
[ -e /bin/systemctl ] && systemctl daemon-reload
popd > /dev/null
}
+121
View File
@@ -0,0 +1,121 @@
#!/bin/bash
# core/environment.sh - environment init, OS check, pre-install prep
# Migrated verbatim from install.sh (lines 12-20,22-23,32-36,693-697,699-713,715-725).
init_environment() {
clear
printf "
#######################################################################
# ServerStack for Debian 9+ and Ubuntu 16+ #
# For more information please visit https://oneinstack.com #
#######################################################################
"
# Check if user is root
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
# bin/install.sh already sets oneinstack_dir to the project root and cd's there.
# Derive it robustly from THIS script's own location only as a fallback, so the
# relative sources (./lib, ./config, ./modules) always resolve to the project
# root instead of breaking into bin/ when $0 points at bin/install.sh.
if [ -z "${oneinstack_dir}" ] || [ ! -d "${oneinstack_dir}/lib" ]; then
oneinstack_dir="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)"
fi
cd "${oneinstack_dir}" || exit 1
}
# init_variables: generate random credentials. Runs AFTER load_configs so the
# fresh random values intentionally override any dbrootpwd stored in
# config/options.conf (matches the original install.sh ordering: lines 32-36 run
# after the config/options.conf source at lines 24-30).
init_variables() {
dbrootpwd=`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`
dbpostgrespwd=`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`
dbmongopwd=`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`
xcachepwd=`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`
dbinstallmethod=1
}
# get_local_ipaddr: resolve the server's primary (outbound) IPv4 address with pure
# shell, so the install summary never ends up with an EMPTY IP that produces broken
# URLs like "http:///ocp.php". The legacy ./lib/py/get_ipaddr.py relied on a `python`
# interpreter (via its shebang) which is absent on Ubuntu 22.04+ (only `python3`
# exists); when that script silently failed, IPADDR came back empty. This shell
# implementation is interpreter-independent and falls back through several methods.
get_local_ipaddr() {
local ip=""
# 1) Source address the kernel would use to reach the public Internet.
if command -v ip >/dev/null 2>&1; then
ip=$(ip route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="src"){print $(i+1); exit}}')
fi
# 2) First address reported by `hostname -I` (already skips 127.0.0.1 normally).
if [ -z "$ip" ] && command -v hostname >/dev/null 2>&1; then
ip=$(hostname -I 2>/dev/null | awk '{print $1}')
fi
# 3) First global (non-loopback) IPv4 from `ip addr`.
if [ -z "$ip" ] && command -v ip >/dev/null 2>&1; then
ip=$(ip -o -4 addr show scope global 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -n1)
fi
# 4) Last resort.
[ -z "$ip" ] && ip="127.0.0.1"
# On a VPC / private-network instance the local IP is an RFC1918 address that
# is NOT reachable from outside the VPC. When we already resolved the public IP
# (PUBLIC_IPADDR, used for mirror selection) prefer it for the control-panel
# URLs so they are actually clickable from the Internet. If the public IP is
# unavailable (no egress, etc.) we keep the private IP as a safe fallback.
case "$ip" in
10.*|172.1[6-9].*|172.2[0-9].*|172.3[01].*|192.168.*)
[ -n "${PUBLIC_IPADDR}" ] && ip="${PUBLIC_IPADDR}" ;;
esac
echo "$ip"
}
# core/environment.sh (cont) - prepare_install
# Migrated verbatim from install.sh (lines 693-697,699-713,715-725).
prepare_install() {
if [[ ${nginx_option} =~ ^[1-2]$ ]]; then
[ ! -d ${wwwroot_dir}/default ] && mkdir -p ${wwwroot_dir}/default
[ ! -d ${wwwlogs_dir} ] && mkdir -p ${wwwlogs_dir}
fi
[ -d /data ] && chmod 755 /data
# install wget gcc curl python3
if [ ! -e ~/.oneinstack ]; then
downloadDepsSrc=1
echo "${CMSG}Updating apt package lists (this may take a few minutes)...${CEND}"
apt-get -y update 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
echo "${CMSG}Installing base tools (wget gcc curl python3)...${CEND}"
${PM} -y install wget gcc curl python3 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
clear
fi
# Make sure a `python` interpreter is available for the legacy *.py helpers
# (get_public_ipaddr.py / get_ipaddr_state.py) regardless of whether the OS ships
# `python` (Ubuntu 22.04+ only provides `python3`). Create the symlink UNCONDITIONALLY
# here (not gated by the first-install ~/.oneinstack check) so those scripts keep
# working on every run and on re-installs.
if [ ! -e "/usr/bin/python" ] && command -v python3 >/dev/null 2>&1; then
ln -s "$(command -v python3)" /usr/bin/python
fi
# get the IP information
# Resolve the PUBLIC IP first so get_local_ipaddr() can prefer it on private /
# VPC networks (where the local IP is not externally reachable). Then the local
# IP for the summary URLs, then the country code from the public IP.
PUBLIC_IPADDR=$(./lib/py/get_public_ipaddr.py)
IPADDR=$(get_local_ipaddr)
IPADDR_COUNTRY=$(./lib/py/get_ipaddr_state.py ${PUBLIC_IPADDR})
# openSSL
. ./lib/openssl.sh
# Check download source packages
. ./lib/check_download.sh
[ "${armplatform}" == "y" ] && dbinstallmethod=2
checkDownload 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
# get OS Memory
. ./lib/memory.sh
}
# check_environment: lightweight guard that the OS was detected.
# (check_os.sh already hard-exits on unsupported OS during load_configs.)
check_environment() {
if [ -z "${PM}" ] || [ -z "${Family}" ]; then
error_exit "Unsupported operating system or system detection failed."
fi
}
+34
View File
@@ -0,0 +1,34 @@
#!/bin/bash
# core/init.sh - OS hardening + base dependency install
# Migrated verbatim from install.sh (lines 727-746). tee overwrite fixed to tee -a.
init_os() {
# Check binary dependencies packages
. ./lib/check_sw.sh
case "${Family}" in
"debian")
installDepsDebian 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
. core/os/init_Debian.sh 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
;;
"ubuntu")
installDepsUbuntu 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
. core/os/init_Ubuntu.sh 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
;;
esac
# Install dependencies from source package
installDepsBySrc 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
}
# core/init.sh (cont) - prereqs: OpenSSL + Jemalloc
# Migrated verbatim from install.sh (lines 748-758).
install_prereqs() {
# start Time
startTime=`date +%s`
# openSSL
Install_openSSL | tee -a ${oneinstack_dir}/runtime/install.log
# Jemalloc
if [[ ${nginx_option} =~ ^[1-3]$ ]] || [[ "${db_option}" =~ ^[1-9]$|^1[0-2]$ ]]; then
. modules/web/jemalloc.sh
Install_Jemalloc | tee -a ${oneinstack_dir}/runtime/install.log
fi
}
+219
View File
@@ -0,0 +1,219 @@
#!/bin/bash
# core/installer.sh - install orchestration (logic unchanged)
# Migrated verbatim from install.sh.
PHP_addons() {
# PHP opcode cache
case "${phpcache_option}" in
1)
run_install "modules/php-addons/zendopcache.sh" "Install_ZendOPcache"
;;
2)
run_install "modules/php-addons/apcu.sh" "Install_APCU"
;;
3)
run_install "modules/php-addons/xcache.sh" "Install_XCache"
;;
4)
run_install "modules/php-addons/eaccelerator.sh" "Install_eAccelerator"
;;
esac
# ZendGuardLoader
if [ "${pecl_zendguardloader}" == '1' ]; then
run_install "modules/php-addons/ZendGuardLoader.sh" "Install_ZendGuardLoader"
fi
# ioncube
if [ "${pecl_ioncube}" == '1' ]; then
run_install "modules/php-addons/ioncube.sh" "Install_ionCube"
fi
# SourceGuardian
if [ "${pecl_sourceguardian}" == '1' ]; then
run_install "modules/php-addons/sourceguardian.sh" "Install_SourceGuardian"
fi
# imagick
if [ "${pecl_imagick}" == '1' ]; then
run_install "modules/image/ImageMagick.sh" "Install_ImageMagick"
Install_pecl_imagick 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
fi
# gmagick
if [ "${pecl_gmagick}" == '1' ]; then
run_install "modules/image/GraphicsMagick.sh" "Install_GraphicsMagick"
Install_pecl_gmagick 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
fi
# fileinfo
if [ "${pecl_fileinfo}" == '1' ]; then
run_install "modules/php-addons/pecl_fileinfo.sh" "Install_pecl_fileinfo"
fi
# imap
if [ "${pecl_imap}" == '1' ]; then
run_install "modules/php-addons/pecl_imap.sh" "Install_pecl_imap"
fi
# ldap
if [ "${pecl_ldap}" == '1' ]; then
run_install "modules/php-addons/pecl_ldap.sh" "Install_pecl_ldap"
fi
# calendar
if [ "${pecl_calendar}" == '1' ]; then
run_install "modules/php-addons/pecl_calendar.sh" "Install_pecl_calendar"
fi
# phalcon
if [ "${pecl_phalcon}" == '1' ]; then
run_install "modules/php-addons/pecl_phalcon.sh" "Install_pecl_phalcon"
fi
# yaf
if [ "${pecl_yaf}" == '1' ]; then
run_install "modules/php-addons/pecl_yaf.sh" "Install_pecl_yaf"
fi
# yar
if [ "${pecl_yar}" == '1' ]; then
run_install "modules/php-addons/pecl_yar.sh" "Install_pecl_yar"
fi
# pecl_redis
if [ "${pecl_redis}" == '1' ]; then
run_install "modules/cache/redis.sh" "Install_pecl_redis"
fi
# pecl_mongodb
if [ "${pecl_mongodb}" == '1' ]; then
run_install "modules/php-addons/pecl_mongodb.sh" "Install_pecl_mongodb"
fi
# swoole
if [ "${pecl_swoole}" == '1' ]; then
run_install "modules/php-addons/pecl_swoole.sh" "Install_pecl_swoole"
fi
# xdebug
if [ "${pecl_xdebug}" == '1' ]; then
run_install "modules/php-addons/pecl_xdebug.sh" "Install_pecl_xdebug"
fi
# pecl_pgsql
if [ -e "${pgsql_install_dir}/bin/psql" ]; then
run_install "modules/php-addons/pecl_pgsql.sh" "Install_pecl_pgsql"
fi
}
install_modules() {
# Database
case "${db_option}" in
1)
run_install "modules/db/mysql-8.0.sh" "Install_MySQL80"
;;
2)
run_install "modules/db/mysql-5.7.sh" "Install_MySQL57"
;;
3)
run_install "modules/db/mariadb-10.11.sh" "Install_MariaDB1011"
;;
4)
run_install "modules/db/mariadb-11.8.sh" "Install_MariaDB118"
;;
5)
run_install "modules/db/mariadb-12.3.sh" "Install_MariaDB123"
;;
6)
pgsql_ver=${pgsql1514_ver}
run_install "modules/db/postgresql.sh" "Install_PostgreSQL"
;;
7)
pgsql_ver=${pgsql1610_ver}
run_install "modules/db/postgresql.sh" "Install_PostgreSQL"
;;
8)
pgsql_ver=${pgsql176_ver}
run_install "modules/db/postgresql.sh" "Install_PostgreSQL"
;;
9)
run_install "modules/db/mongodb.sh" "Install_MongoDB"
;;
esac
# Nginx server
case "${nginx_option}" in
1)
run_install "modules/web/nginx.sh" "Install_Nginx"
;;
esac
# PHP
case "${php_option}" in
1)
# On Ubuntu 24+ PHP 7.4 does not compile against the system libicu; the
# guard here is a last-resort safety net in case validation was bypassed.
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ]; then
echo "${CWARNING}Skipping PHP 7.4: not supported on Ubuntu ${Ubuntu_ver}+. Use PHP 8.x.${CEND}"
else
run_install "modules/php/php-7.4.sh" "Install_PHP74"
fi
;;
2)
run_install "modules/php/php-8.0.sh" "Install_PHP80"
;;
3)
run_install "modules/php/php-8.1.sh" "Install_PHP81"
;;
esac
[ "${mphp_addons_flag}" != 'y' ] && PHP_addons
if [ "${mphp_flag}" == 'y' ]; then
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ] && [ "${mphp_ver}" == '74' ]; then
echo "${CWARNING}Skipping mphp 7.4: not supported on Ubuntu ${Ubuntu_ver}+. Use 80 or 81.${CEND}"
else
run_install "modules/php/mphp.sh" "Install_MPHP"
php_install_dir=${php_install_dir}${mphp_ver}
PHP_addons
fi
fi
# Nodejs
if [ "${nodejs_flag}" == 'y' ]; then
run_install "modules/lang/nodejs.sh" "Install_Nodejs"
fi
# Pure-FTPd
if [ "${pureftpd_flag}" == 'y' ]; then
run_install "modules/ftp/pureftpd.sh" "Install_PureFTPd"
fi
# phpMyAdmin
if [ "${phpmyadmin_flag}" == 'y' ]; then
run_install "modules/app/phpmyadmin.sh" "Install_phpMyAdmin"
fi
# redis
if [ "${redis_flag}" == 'y' ]; then
run_install "modules/cache/redis.sh" "Install_redis_server"
fi
# Python
if [ "${python_flag}" == 'y' ]; then
run_install "modules/lang/python.sh" "Install_Python"
fi
}
# configure_modules: deploy default demo site and re-read install dirs.
# Migrated verbatim from install.sh (lines 1102-1109).
configure_modules() {
# index example
if [ -d "${wwwroot_dir}/default" ]; then
. core/demo.sh
DEMO 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
fi
# get web_install_dir and db_install_dir
. lib/check_dir.sh
}
+297
View File
@@ -0,0 +1,297 @@
#!/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
}
+137
View File
@@ -0,0 +1,137 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
# Custom profile
cat > /etc/profile.d/oneinstack.sh << EOF
HISTSIZE=10000
PS1='\${debian_chroot:+(\$debian_chroot)}\\[\\e[1;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '
HISTTIMEFORMAT="%F %T \$(whoami) "
alias l='ls -AFhlt --color=auto'
alias lh='l | head'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi=vim
GREP_OPTIONS="--color=auto"
alias grep='grep --color'
alias egrep='egrep --color'
alias fgrep='fgrep --color'
EOF
sed -i 's@^"syntax on@syntax on@' /etc/vim/vimrc
# history
[ -z "$(grep history-timestamp ~/.bashrc)" ] && echo "PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });user=\$(whoami); echo \$(date \"+%Y-%m-%d %H:%M:%S\"):\$user:\`pwd\`/:\$msg ---- \$(who am i); } >> /tmp/\`hostname\`.\`whoami\`.history-timestamp'" >> ~/.bashrc
# /etc/security/limits.conf
[ -e /etc/security/limits.d/*nproc.conf ] && rename nproc.conf nproc.conf_bk /etc/security/limits.d/*nproc.conf
[ -z "$(grep 'session required pam_limits.so' /etc/pam.d/common-session)" ] && echo "session required pam_limits.so" >> /etc/pam.d/common-session
sed -i '/^# End of file/,$d' /etc/security/limits.conf
cat >> /etc/security/limits.conf <<EOF
# End of file
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
EOF
# /etc/hosts
[ "$(hostname -i | awk '{print $1}')" != "127.0.0.1" ] && sed -i "s@127.0.0.1.*localhost@&\n127.0.0.1 $(hostname)@g" /etc/hosts
# Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/${timezone} /etc/localtime
# Set DNS
#cat > /etc/resolv.conf << EOF
#nameserver 114.114.114.114
#nameserver 8.8.8.8
#EOF
# /etc/sysctl.conf
[ -z "$(grep 'fs.file-max' /etc/sysctl.conf)" ] && cat >> /etc/sysctl.conf << EOF
fs.file-max = 1000000
fs.inotify.max_user_instances = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 32768
net.core.netdev_max_backlog = 32768
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_max_orphans = 32768
EOF
sysctl -p
sed -i 's@^ACTIVE_CONSOLES.*@ACTIVE_CONSOLES="/dev/tty[1-2]"@' /etc/default/console-setup
sed -i 's@^# en_US.UTF-8@en_US.UTF-8@' /etc/locale.gen
init q
# Update time
if [ -e "$(which ntpdate)" ]; then
ntpdate -u pool.ntp.org
[ ! -e "/var/spool/cron/crontabs/root" -o -z "$(grep ntpdate /var/spool/cron/crontabs/root 2>/dev/null)" ] && { echo "*/20 * * * * $(which ntpdate) -u pool.ntp.org > /dev/null 2>&1" >> /var/spool/cron/crontabs/root;chmod 600 /var/spool/cron/crontabs/root; }
fi
# iptables
if [ "${iptables_flag}" == 'y' ]; then
echo "${CMSG}Installing iptables firewall tooling...${CEND}"
apt-get -y install debconf-utils
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | debconf-set-selections
apt-get -y install iptables-persistent
if [ -e "/etc/iptables/rules.v4" ] && [ -n "$(grep '^:INPUT DROP' /etc/iptables/rules.v4)" -a -n "$(grep 'NEW -m tcp --dport 22 -j ACCEPT' /etc/iptables/rules.v4)" -a -n "$(grep 'NEW -m tcp --dport 80 -j ACCEPT' /etc/iptables/rules.v4)" ]; then
IPTABLES_STATUS=yes
else
IPTABLES_STATUS=no
fi
if [ "${IPTABLES_STATUS}" == "no" ]; then
cat > /etc/iptables/rules.v4 << EOF
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:syn-flood - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
COMMIT
EOF
fi
FW_PORT_FLAG=$(grep -ow "dport ${ssh_port}" /etc/iptables/rules.v4)
[ -z "${FW_PORT_FLAG}" -a "${ssh_port}" != "22" ] && sed -i "s@dport 22 -j ACCEPT@&\n-A INPUT -p tcp -m state --state NEW -m tcp --dport ${ssh_port} -j ACCEPT@" /etc/iptables/rules.v4
iptables-restore < /etc/iptables/rules.v4
/bin/cp /etc/iptables/rules.v{4,6}
sed -i 's@icmp@icmpv6@g' /etc/iptables/rules.v6
ip6tables-restore < /etc/iptables/rules.v6
ip6tables-save > /etc/iptables/rules.v6
fi
service rsyslog restart
service ssh restart
. /etc/profile
. ~/.bashrc
+137
View File
@@ -0,0 +1,137 @@
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://linuxeye.com
#
# Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://oneinstack.com
# https://github.com/oneinstack/oneinstack
# Custom profile
cat > /etc/profile.d/oneinstack.sh << EOF
HISTSIZE=10000
HISTTIMEFORMAT="%F %T \$(whoami) "
alias l='ls -AFhlt --color=auto'
alias lh='l | head'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias vi=vim
GREP_OPTIONS="--color=auto"
alias grep='grep --color'
alias egrep='egrep --color'
alias fgrep='fgrep --color'
EOF
sed -i 's@^"syntax on@syntax on@' /etc/vim/vimrc
# PS1
[ -z "$(grep ^PS1 ~/.bashrc)" ] && echo "PS1='\${debian_chroot:+(\$debian_chroot)}\\[\\e[1;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" >> ~/.bashrc
# history
[ -z "$(grep history-timestamp ~/.bashrc)" ] && echo "PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });user=\$(whoami); echo \$(date \"+%Y-%m-%d %H:%M:%S\"):\$user:\`pwd\`/:\$msg ---- \$(who am i); } >> /tmp/\`hostname\`.\`whoami\`.history-timestamp'" >> ~/.bashrc
# /etc/security/limits.conf
[ -e /etc/security/limits.d/*nproc.conf ] && rename nproc.conf nproc.conf_bk /etc/security/limits.d/*nproc.conf
[ -z "$(grep 'session required pam_limits.so' /etc/pam.d/common-session)" ] && echo "session required pam_limits.so" >> /etc/pam.d/common-session
sed -i '/^# End of file/,$d' /etc/security/limits.conf
cat >> /etc/security/limits.conf <<EOF
# End of file
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
EOF
# /etc/hosts
[ "$(hostname -i | awk '{print $1}')" != "127.0.0.1" ] && sed -i "s@127.0.0.1.*localhost@&\n127.0.0.1 $(hostname)@g" /etc/hosts
# Set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/${timezone} /etc/localtime
# Set DNS
#cat > /etc/resolv.conf << EOF
#nameserver 114.114.114.114
#nameserver 8.8.8.8
#EOF
# /etc/sysctl.conf
[ -z "$(grep 'fs.file-max' /etc/sysctl.conf)" ] && cat >> /etc/sysctl.conf << EOF
fs.file-max = 1000000
fs.inotify.max_user_instances = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 32768
net.core.netdev_max_backlog = 32768
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_max_orphans = 32768
EOF
sysctl -p
sed -i 's@^ACTIVE_CONSOLES.*@ACTIVE_CONSOLES="/dev/tty[1-2]"@' /etc/default/console-setup
locale-gen en_US.UTF-8
[ -d "/var/lib/locales/supported.d" ] && echo "en_US.UTF-8 UTF-8" > /var/lib/locales/supported.d/local
cat > /etc/default/locale << EOF
LANG=en_US.UTF-8
LANGUAGE=en_US:en
EOF
# iptables
if [ "${iptables_flag}" == 'y' ]; then
echo "${CMSG}Installing iptables firewall tooling...${CEND}"
apt-get -y install debconf-utils
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | debconf-set-selections
apt-get -y install iptables-persistent
if [ -e "/etc/iptables/rules.v4" ] && [ -n "$(grep '^:INPUT DROP' /etc/iptables/rules.v4)" -a -n "$(grep 'NEW -m tcp --dport 22 -j ACCEPT' /etc/iptables/rules.v4)" -a -n "$(grep 'NEW -m tcp --dport 80 -j ACCEPT' /etc/iptables/rules.v4)" ]; then
IPTABLES_STATUS=yes
else
IPTABLES_STATUS=no
fi
if [ "${IPTABLES_STATUS}" == "no" ]; then
cat > /etc/iptables/rules.v4 << EOF
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:syn-flood - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
COMMIT
EOF
fi
FW_PORT_FLAG=$(grep -ow "dport ${ssh_port}" /etc/iptables/rules.v4)
[ -z "${FW_PORT_FLAG}" -a "${ssh_port}" != "22" ] && sed -i "s@dport 22 -j ACCEPT@&\n-A INPUT -p tcp -m state --state NEW -m tcp --dport ${ssh_port} -j ACCEPT@" /etc/iptables/rules.v4
iptables-restore < /etc/iptables/rules.v4
/bin/cp /etc/iptables/rules.v{4,6}
sed -i 's@icmp@icmpv6@g' /etc/iptables/rules.v6
ip6tables-restore < /etc/iptables/rules.v6
ip6tables-save > /etc/iptables/rules.v6
fi
service rsyslog restart
service ssh restart
. /etc/profile
. ~/.bashrc
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
# core/service.sh - start services after install
# Migrated verbatim from install.sh (lines 1117-1124).
start_services() {
# Starting DB
[ -d "/etc/mysql" ] && /bin/mv /etc/mysql{,_bk}
[ -d "${db_install_dir}/support-files" ] && [ -z "`ps -ef | grep mysqld_safe | grep -v grep`" ] && service mysqld start
# reload php
[ -e "${php_install_dir}/sbin/php-fpm" ] && start_service php-fpm reload
[ -n "${mphp_ver}" -a -e "${php_install_dir}${mphp_ver}/sbin/php-fpm" ] && start_service php${mphp_ver}-fpm reload
}
# start_service: unified systemctl|service dispatcher (de-dup of dual-path lines).
start_service() {
local name="$1" action="$2"
[ -e /bin/systemctl ] && systemctl "${action}" "${name}" || service "${name}" "${action}"
}
+51
View File
@@ -0,0 +1,51 @@
#!/bin/bash
# core/summary.sh - installation summary + reboot prompt
# Migrated verbatim from install.sh (lines 1126-1174). Logic unchanged.
print_summary() {
endTime=`date +%s`
((installTime=($endTime-$startTime)/60))
echo "####################Congratulations########################"
echo "Total OneinStack Install Time: ${CQUESTION}${installTime}${CEND} minutes"
[[ "${nginx_option}" =~ ^[1-2]$ ]] && echo -e "\n$(printf "%-32s" "Nginx install dir":)${CMSG}${web_install_dir}${CEND}"
[[ "${db_option}" =~ ^[1-5]$ ]] && echo -e "\n$(printf "%-32s" "Database install dir:")${CMSG}${db_install_dir}${CEND}"
[[ "${db_option}" =~ ^[1-5]$ ]] && echo "$(printf "%-32s" "Database data dir:")${CMSG}${db_data_dir}${CEND}"
[[ "${db_option}" =~ ^[1-5]$ ]] && echo "$(printf "%-32s" "Database user:")${CMSG}root${CEND}"
[[ "${db_option}" =~ ^[1-5]$ ]] && echo "$(printf "%-32s" "Database password:")${CMSG}${dbrootpwd}${CEND}"
[[ "${db_option}" =~ ^[6-8]$ ]] && echo -e "\n$(printf "%-32s" "PostgreSQL install dir:")${CMSG}${pgsql_install_dir}${CEND}"
[[ "${db_option}" =~ ^[6-8]$ ]] && echo "$(printf "%-32s" "PostgreSQL data dir:")${CMSG}${pgsql_data_dir}${CEND}"
[[ "${db_option}" =~ ^[6-8]$ ]] && echo "$(printf "%-32s" "PostgreSQL user:")${CMSG}postgres${CEND}"
[[ "${db_option}" =~ ^[6-8]$ ]] && echo "$(printf "%-32s" "postgres password:")${CMSG}${dbpostgrespwd}${CEND}"
[ "${db_option}" == '9' ] && echo -e "\n$(printf "%-32s" "MongoDB install dir:")${CMSG}${mongo_install_dir}${CEND}"
[ "${db_option}" == '9' ] && echo "$(printf "%-32s" "MongoDB data dir:")${CMSG}${mongo_data_dir}${CEND}"
[ "${db_option}" == '9' ] && echo "$(printf "%-32s" "MongoDB user:")${CMSG}root${CEND}"
[ "${db_option}" == '9' ] && echo "$(printf "%-32s" "MongoDB password:")${CMSG}${dbmongopwd}${CEND}"
[[ "${php_option}" =~ ^[1-3]$ ]] && echo -e "\n$(printf "%-32s" "PHP install dir:")${CMSG}${php_install_dir}${CEND}"
[ "${phpcache_option}" == '1' ] && echo "$(printf "%-32s" "Opcache Control Panel URL:")${CMSG}http://${IPADDR}/ocp.php${CEND}"
[ "${phpcache_option}" == '2' ] && echo "$(printf "%-32s" "APC Control Panel URL:")${CMSG}http://${IPADDR}/apc.php${CEND}"
[ "${phpcache_option}" == '3' -a -e "${php_install_dir}/etc/php.d/04-xcache.ini" ] && echo "$(printf "%-32s" "xcache Control Panel URL:")${CMSG}http://${IPADDR}/xcache${CEND}"
[ "${phpcache_option}" == '3' -a -e "${php_install_dir}/etc/php.d/04-xcache.ini" ] && echo "$(printf "%-32s" "xcache user:")${CMSG}admin${CEND}"
[ "${phpcache_option}" == '3' -a -e "${php_install_dir}/etc/php.d/04-xcache.ini" ] && echo "$(printf "%-32s" "xcache password:")${CMSG}${xcachepwd}${CEND}"
[ "${phpcache_option}" == '4' -a -e "${php_install_dir}/etc/php.d/02-eaccelerator.ini" ] && echo "$(printf "%-32s" "eAccelerator Control Panel URL:")${CMSG}http://${IPADDR}/control.php${CEND}"
[ "${phpcache_option}" == '4' -a -e "${php_install_dir}/etc/php.d/02-eaccelerator.ini" ] && echo "$(printf "%-32s" "eAccelerator user:")${CMSG}admin${CEND}"
[ "${phpcache_option}" == '4' -a -e "${php_install_dir}/etc/php.d/02-eaccelerator.ini" ] && echo "$(printf "%-32s" "eAccelerator password:")${CMSG}eAccelerator${CEND}"
[ "${pureftpd_flag}" == 'y' ] && echo -e "\n$(printf "%-32s" "Pure-FTPd install dir:")${CMSG}${pureftpd_install_dir}${CEND}"
[ "${pureftpd_flag}" == 'y' ] && echo "$(printf "%-32s" "Create FTP virtual script:")${CMSG}./pureftpd_vhost.sh${CEND}"
[ "${phpmyadmin_flag}" == 'y' ] && echo -e "\n$(printf "%-32s" "phpMyAdmin dir:")${CMSG}${wwwroot_dir}/default/phpMyAdmin${CEND}"
[ "${phpmyadmin_flag}" == 'y' ] && echo "$(printf "%-32s" "phpMyAdmin Control Panel URL:")${CMSG}http://${IPADDR}/phpMyAdmin${CEND}"
[ "${redis_flag}" == 'y' ] && echo -e "\n$(printf "%-32s" "redis install dir:")${CMSG}${redis_install_dir}${CEND}"
if [[ ${nginx_option} =~ ^[1-2]$ ]]; then
echo -e "\n$(printf "%-32s" "Index URL:")${CMSG}http://${IPADDR}/${CEND}"
fi
if [ ${ARG_NUM} == 0 ]; then
while :; do echo
echo "${CMSG}Please restart the server and see if the services start up fine.${CEND}"
read -e -p "Do you want to restart OS ? [y/n]: " reboot_flag
if [[ ! "${reboot_flag}" =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
break
fi
done
fi
[ "${reboot_flag}" == 'y' ] && reboot
}
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
# core/validator.sh - unified option validation.
#
# The primary validation still happens inline inside parse_arguments and
# show_menu (migrated verbatim, to preserve the exact error messages and the
# "already installed" guards). validate_options() is a final, idempotent
# safety net: it re-checks only options that are still set, using the same
# regexes and messages, so it can never change a valid install path.
# Validate a single value against an ERE.
# $1 = value, $2 = regex, $3 = error message
is_valid() {
local val="$1" regex="$2" msg="$3"
if [[ "${val}" =~ ${regex} ]]; then
return 0
fi
echo "${CWARNING}${msg}${CEND}"
return 1
}
# Re-validate options that are still set after parse/menu. Empty options
# (e.g. unset because already installed) are skipped.
validate_options() {
_check_opt() {
# $1 = value, $2 = regex, $3 = message
[ -z "$1" ] && return 0
is_valid "$1" "$2" "$3" || error_exit "$3"
}
_check_opt "${nginx_option}" '^[1-2]$' "nginx_option input error! Please only input number 1~2"
_check_opt "${php_option}" '^[1-3]$' "php_option input error! Please only input number 1~3"
_check_opt "${mphp_ver}" '^(74|80|81)$' "mphp_ver input error! Please only input number 74/80/81"
# On Ubuntu 24+ only PHP 8.x is supported; PHP 7.4 (and the mphp 7.4 build)
# fails to compile against the newer system libicu.
if [[ "${Family}" == "ubuntu" ]] && [ "${Ubuntu_ver:-0}" -ge 24 ]; then
[ "${php_option}" == '1' ] && error_exit "PHP 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please choose PHP 8.x (option 2 or 3)"
[ "${mphp_ver}" == '74' ] && error_exit "mphp 7.4 is not supported on Ubuntu ${Ubuntu_ver}+, please choose 80 or 81"
fi
_check_opt "${db_option}" '^[1-9]$' "db_option input error! Please only input number 1~9"
_check_opt "${dbinstallmethod}" '^[1-2]$' "dbinstallmethod input error! Please only input number 1~2"
}
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# core/workflow.sh - top-level install workflow orchestration.
#
# This is the single place that defines the install order. install.sh only
# bootstraps the environment and calls main(); all flow control lives here.
# Each step delegates to a focused module so install.sh stays a thin entry
# point with no business logic of its own.
main() {
init_environment # root check, banner, set oneinstack_dir, cd
load_configs # config/versions.txt / config/options.conf / color / check_os / ...
init_variables # random credentials (overrides config/options.conf dbrootpwd)
parse_arguments "$@" # getopt -> sets *_option / *_flag globals
check_environment # guard that the OS was detected
show_menu # interactive only when ARG_NUM == 0
validate_options # final idempotent option re-check
prepare_install # dirs, base dev tools, IP, download libs, checkDownload
init_os # OS hardening + base dependency packages
install_prereqs # OpenSSL + Jemalloc
install_modules # DB -> Web(Nginx) -> PHP -> addons -> ...
configure_modules # default demo site + re-read install dirs
start_services # start DB, reload php-fpm
print_summary # summary + reboot prompt
}