Files
ServerStack/bin/upgrade.sh
T
condor 679e0b4184 init
2026-07-24 18:54:53 +08:00

163 lines
4.7 KiB
Bash

#!/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
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
clear
printf "
#######################################################################
# OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+ #
# Upgrade Software versions for OneinStack #
# 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; }
oneinstack_dir="$(cd "$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")/.." && pwd)"
cd "${oneinstack_dir}" || exit 1
. ./config/versions.txt
. ./config/options.conf
. ./lib/color.sh
. ./lib/check_os.sh
. ./lib/check_dir.sh
. ./lib/download.sh
. ./lib/get_char.sh
. ./modules/upgrade/upgrade_web.sh
. ./modules/upgrade/upgrade_db.sh
. ./modules/upgrade/upgrade_php.sh
. ./modules/upgrade/upgrade_redis.sh
. ./modules/upgrade/upgrade_phpmyadmin.sh
. ./modules/upgrade/upgrade_oneinstack.sh
# Ensure a `python` interpreter exists for the legacy *.py helpers
# (Ubuntu 22.04+ ships only `python3`). Without this, get_public_ipaddr.py /
# get_ipaddr_state.py silently fail and mirror selection falls back to upstream.
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
PUBLIC_IPADDR=$(./lib/py/get_public_ipaddr.py)
IPADDR_COUNTRY=$(./lib/py/get_ipaddr_state.py ${PUBLIC_IPADDR})
Show_Help() {
echo
echo "Usage: $0 command ...[version]....
--help, -h Show this help message
--nginx [version] Upgrade Nginx
--db [version] Upgrade MySQL/MariaDB
--php [version] Upgrade PHP
--redis [version] Upgrade Redis
--phpmyadmin [version] Upgrade phpMyAdmin
--oneinstack Upgrade OneinStack latest
--acme.sh Upgrade acme.sh latest
"
}
ARG_NUM=$#
TEMP=`getopt -o h --long help,nginx:,db:,php:,redis:,phpmyadmin:,oneinstack,acme.sh -- "$@" 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
;;
--nginx)
nginx_flag=y; NEW_nginx_ver=$2; shift 2
;;
--db)
db_flag=y; NEW_db_ver=$2; shift 2
;;
--php)
php_flag=y; NEW_php_ver=$2; shift 2
;;
--redis)
redis_flag=y; NEW_redis_ver=$2; shift 2
;;
--phpmyadmin)
phpmyadmin_flag=y; NEW_phpmyadmin_ver=$2; shift 2
;;
--oneinstack)
NEW_oneinstack_ver=latest; shift 1
;;
--acme.sh)
NEW_acme_ver=latest; shift 1
;;
--)
shift
;;
*)
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
;;
esac
done
Menu() {
while :; do
printf "
What Are You Doing?
\t${CMSG} 1${CEND}. Upgrade Nginx
\t${CMSG} 2${CEND}. Upgrade MySQL/MariaDB
\t${CMSG} 3${CEND}. Upgrade PHP
\t${CMSG} 4${CEND}. Upgrade Redis
\t${CMSG} 5${CEND}. Upgrade phpMyAdmin
\t${CMSG} 6${CEND}. Upgrade OneinStack latest
\t${CMSG} 7${CEND}. Upgrade acme.sh latest
\t${CMSG} q${CEND}. Exit
"
echo
read -e -p "Please input the correct option: " Upgrade_flag
if [[ ! "${Upgrade_flag}" =~ ^[1-7,q]$ ]]; then
echo "${CWARNING}input error! Please only input 1~7 and q${CEND}"
else
case "${Upgrade_flag}" in
1)
[ -e "${nginx_install_dir}/sbin/nginx" ] && Upgrade_Nginx
;;
2)
Upgrade_DB
;;
3)
Upgrade_PHP
;;
4)
Upgrade_Redis
;;
5)
Upgrade_phpMyAdmin
;;
6)
Upgrade_OneinStack
;;
7)
[ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --force --upgrade; ~/.acme.sh/acme.sh --version; }
;;
q)
exit
;;
esac
fi
done
}
if [ ${ARG_NUM} == 0 ]; then
Menu
else
[ "${nginx_flag}" == 'y' ] && Upgrade_Nginx
[ "${db_flag}" == 'y' ] && Upgrade_DB
[ "${php_flag}" == 'y' ] && Upgrade_PHP
[ "${redis_flag}" == 'y' ] && Upgrade_Redis
[ "${phpmyadmin_flag}" == 'y' ] && Upgrade_phpMyAdmin
[ "${NEW_oneinstack_ver}" == 'latest' ] && Upgrade_OneinStack
[ "${NEW_acme_ver}" == 'latest' ] && [ -e ~/.acme.sh/acme.sh ] && { ~/.acme.sh/acme.sh --force --upgrade; ~/.acme.sh/acme.sh --version; }
fi