init
This commit is contained in:
+212
@@ -0,0 +1,212 @@
|
||||
#!/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+ #
|
||||
# Install/Uninstall Extensions #
|
||||
# For more information please visit https://oneinstack.com #
|
||||
#######################################################################
|
||||
"
|
||||
# Check if user is root
|
||||
# shellcheck disable=SC2046
|
||||
[ $(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)"
|
||||
# shellcheck disable=SC2164
|
||||
cd "${oneinstack_dir}" || exit 1
|
||||
|
||||
. ./config/versions.txt
|
||||
. ./config/options.conf
|
||||
. ./lib/color.sh
|
||||
. ./lib/check_os.sh
|
||||
. ./lib/download.sh
|
||||
. ./lib/get_char.sh
|
||||
|
||||
. ./modules/php-addons/composer.sh
|
||||
|
||||
. ./modules/lang/python.sh
|
||||
|
||||
. ./modules/security/fail2ban.sh
|
||||
|
||||
. ./modules/security/ngx_lua_waf.sh
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
Show_Help() {
|
||||
echo
|
||||
echo "Usage: $0 command ...
|
||||
--help, -h Show this help message
|
||||
--install, -i Install
|
||||
--uninstall, -u Uninstall
|
||||
--composer Composer
|
||||
--fail2ban Fail2ban
|
||||
--ngx_lua_waf Ngx_lua_waf
|
||||
--python Python (PATH: ${python_install_dir})
|
||||
"
|
||||
}
|
||||
|
||||
ARG_NUM=$#
|
||||
TEMP=`getopt -o hiu --long help,install,uninstall,composer,fail2ban,ngx_lua_waf,python -- "$@" 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
|
||||
;;
|
||||
-i|--install)
|
||||
install_flag=y; shift 1
|
||||
;;
|
||||
-u|--uninstall)
|
||||
uninstall_flag=y; shift 1
|
||||
;;
|
||||
--composer)
|
||||
composer_flag=y; shift 1
|
||||
;;
|
||||
--fail2ban)
|
||||
fail2ban_flag=y; shift 1
|
||||
;;
|
||||
--ngx_lua_waf)
|
||||
ngx_lua_waf_flag=y; shift 1
|
||||
;;
|
||||
--python)
|
||||
python_flag=y; shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
ACTION_FUN() {
|
||||
while :; do
|
||||
echo
|
||||
echo "Please select an action:"
|
||||
echo -e "\t${CMSG}1${CEND}. install"
|
||||
echo -e "\t${CMSG}2${CEND}. uninstall"
|
||||
read -e -p "Please input a number:(Default 1 press Enter) " ACTION
|
||||
ACTION=${ACTION:-1}
|
||||
if [[ ! "${ACTION}" =~ ^[1,2]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input number 1~2${CEND}"
|
||||
else
|
||||
[ "${ACTION}" == '1' ] && install_flag=y
|
||||
[ "${ACTION}" == '2' ] && uninstall_flag=y
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
Menu() {
|
||||
while :;do
|
||||
printf "
|
||||
What Are You Doing?
|
||||
\t${CMSG}1${CEND}. Install/Uninstall PHP Composer
|
||||
\t${CMSG}2${CEND}. Install/Uninstall fail2ban
|
||||
\t${CMSG}3${CEND}. Install/Uninstall ngx_lua_waf
|
||||
\t${CMSG}4${CEND}. Install/Uninstall Python3.6
|
||||
\t${CMSG}q${CEND}. Exit
|
||||
"
|
||||
read -e -p "Please input the correct option: " Number
|
||||
if [[ ! "${Number}" =~ ^[1-5,q]$ ]]; then
|
||||
echo "${CFAILURE}input error! Please only input 1~4 and q${CEND}"
|
||||
else
|
||||
case "${Number}" in
|
||||
1)
|
||||
ACTION_FUN
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_composer
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_composer
|
||||
fi
|
||||
;;
|
||||
2)
|
||||
ACTION_FUN
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_Python
|
||||
Install_fail2ban
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_fail2ban
|
||||
fi
|
||||
;;
|
||||
3)
|
||||
ACTION_FUN
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
# shellcheck disable=SC2154
|
||||
[ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
|
||||
enable_lua_waf
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
disable_lua_waf
|
||||
fi
|
||||
;;
|
||||
4)
|
||||
ACTION_FUN
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_Python
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_Python
|
||||
fi
|
||||
;;
|
||||
5)
|
||||
ACTION_FUN
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_Python
|
||||
Install_Panel
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_Panel
|
||||
fi
|
||||
;;
|
||||
q)
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ ${ARG_NUM} == 0 ]; then
|
||||
Menu
|
||||
else
|
||||
if [ "${composer_flag}" == 'y' ]; then
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_composer
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_composer
|
||||
fi
|
||||
fi
|
||||
if [ "${fail2ban_flag}" == 'y' ]; then
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_Python
|
||||
Install_fail2ban
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_fail2ban
|
||||
fi
|
||||
fi
|
||||
if [ "${ngx_lua_waf_flag}" == 'y' ]; then
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
[ -e "${nginx_install_dir}/sbin/nginx" ] && Nginx_lua_waf
|
||||
enable_lua_waf
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
disable_lua_waf
|
||||
fi
|
||||
fi
|
||||
if [ "${python_flag}" == 'y' ]; then
|
||||
if [ "${install_flag}" = 'y' ]; then
|
||||
Install_Python
|
||||
elif [ "${uninstall_flag}" = 'y' ]; then
|
||||
Uninstall_Python
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
+295
@@ -0,0 +1,295 @@
|
||||
#!/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
|
||||
|
||||
# Check if user is root
|
||||
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
|
||||
|
||||
oneinstack_dir=$(dirname "`readlink -f $0`")
|
||||
pushd ${oneinstack_dir}/tools > /dev/null
|
||||
. ../config/options.conf
|
||||
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
|
||||
|
||||
DB_Local_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
done
|
||||
}
|
||||
|
||||
DB_Remote_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
echo "file:::${backup_dir}/${DB_FILE} ${backup_dir} push" >> config_backup.txt
|
||||
echo "com:::[ -e "${backup_dir}/${DB_FILE}" ] && rm -rf ${backup_dir}/DB_${D}_$(date +%Y%m%d --date="${expired_days} days ago")_*.tgz" >> config_backup.txt
|
||||
done
|
||||
}
|
||||
|
||||
DB_OSS_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
/usr/local/bin/ossutil cp -f ${backup_dir}/${DB_FILE} oss://${oss_bucket}/`date +%F`/${DB_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/ossutil rm -rf oss://${oss_bucket}/`date +%F --date="${expired_days} days ago"`/
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${backup_dir}/${DB_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
DB_COS_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
${python_install_dir}/bin/coscmd upload ${backup_dir}/${DB_FILE} /`date +%F`/${DB_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
${python_install_dir}/bin/coscmd delete -r -f `date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${backup_dir}/${DB_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
DB_UPYUN_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
/usr/local/bin/upx put ${backup_dir}/${DB_FILE} /`date +%F`/${DB_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/upx rm -a `date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${backup_dir}/${DB_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
DB_QINIU_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
/usr/local/bin/qshell rput ${qiniu_bucket} /`date +%F`/${DB_FILE} ${backup_dir}/${DB_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/qshell listbucket ${qiniu_bucket} /`date +%F --date="${expired_days} days ago"` /tmp/qiniu.txt > /dev/null 2>&1
|
||||
/usr/local/bin/qshell batchdelete -force ${qiniu_bucket} /tmp/qiniu.txt > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${backup_dir}/${DB_FILE}
|
||||
rm -f /tmp/qiniu.txt
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
DB_S3_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
${python_install_dir}/bin/s3cmd put ${backup_dir}/${DB_FILE} s3://${s3_bucket}/`date +%F`/${DB_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
${python_install_dir}/bin/s3cmd rm -r s3://${s3_bucket}/`date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${backup_dir}/${DB_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
DB_DROPBOX_BK() {
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
./db_bk.sh ${D}
|
||||
DB_GREP="DB_${D}_`date +%Y%m%d`"
|
||||
DB_FILE=`ls -lrt ${backup_dir} | grep ${DB_GREP} | tail -1 | awk '{print $NF}'`
|
||||
/usr/local/bin/dbxcli put ${backup_dir}/${DB_FILE} `date +%F`/${DB_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/dbxcli rm -f `date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${backup_dir}/${DB_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_LOCAL_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
./website_bk.sh $W
|
||||
done
|
||||
}
|
||||
|
||||
WEB_Remote_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
if [ `du -sm "${wwwroot_dir}/${WebSite}" | awk '{print $1}'` -lt 2048 ]; then
|
||||
./website_bk.sh $W
|
||||
Web_GREP="Web_${W}_`date +%Y%m%d`"
|
||||
Web_FILE=`ls -lrt ${backup_dir} | grep ${Web_GREP} | tail -1 | awk '{print $NF}'`
|
||||
echo "file:::${backup_dir}/${Web_FILE} ${backup_dir} push" >> config_backup.txt
|
||||
echo "com:::[ -e "${backup_dir}/${Web_FILE}" ] && rm -rf ${backup_dir}/Web_${W}_$(date +%Y%m%d --date="${expired_days} days ago")_*.tgz" >> config_backup.txt
|
||||
else
|
||||
echo "file:::${wwwroot_dir}/$W ${backup_dir} push" >> config_backup.txt
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_OSS_BK() {
|
||||
for W in `echo $website_name | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist"; break; }
|
||||
PUSH_FILE="${backup_dir}/Web_${W}_$(date +%Y%m%d_%H).tgz"
|
||||
if [ ! -e "${PUSH_FILE}" ]; then
|
||||
pushd ${wwwroot_dir} > /dev/null
|
||||
tar czf ${PUSH_FILE} ./$W
|
||||
popd > /dev/null
|
||||
fi
|
||||
/usr/local/bin/ossutil cp -f ${PUSH_FILE} oss://${oss_bucket}/`date +%F`/${PUSH_FILE##*/}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/ossutil rm -rf oss://${oss_bucket}/`date +%F --date="${expired_days} days ago"`/
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${PUSH_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_COS_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist"; break; }
|
||||
PUSH_FILE="${backup_dir}/Web_${W}_$(date +%Y%m%d_%H).tgz"
|
||||
if [ ! -e "${PUSH_FILE}" ]; then
|
||||
pushd ${wwwroot_dir} > /dev/null
|
||||
tar czf ${PUSH_FILE} ./$W
|
||||
popd > /dev/null
|
||||
fi
|
||||
${python_install_dir}/bin/coscmd upload ${PUSH_FILE} /`date +%F`/${PUSH_FILE##*/}
|
||||
if [ $? -eq 0 ]; then
|
||||
${python_install_dir}/bin/coscmd delete -r -f `date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${PUSH_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_UPYUN_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist"; break; }
|
||||
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
|
||||
PUSH_FILE="${backup_dir}/Web_${W}_$(date +%Y%m%d_%H).tgz"
|
||||
if [ ! -e "${PUSH_FILE}" ]; then
|
||||
pushd ${wwwroot_dir} > /dev/null
|
||||
tar czf ${PUSH_FILE} ./$W
|
||||
popd > /dev/null
|
||||
fi
|
||||
/usr/local/bin/upx put ${PUSH_FILE} /`date +%F`/${PUSH_FILE##*/}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/upx rm -a `date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${PUSH_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_QINIU_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist"; break; }
|
||||
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
|
||||
PUSH_FILE="${backup_dir}/Web_${W}_$(date +%Y%m%d_%H).tgz"
|
||||
if [ ! -e "${PUSH_FILE}" ]; then
|
||||
pushd ${wwwroot_dir} > /dev/null
|
||||
tar czf ${PUSH_FILE} ./$W
|
||||
popd > /dev/null
|
||||
fi
|
||||
/usr/local/bin/qshell rput ${qiniu_bucket} /`date +%F`/${PUSH_FILE##*/} ${PUSH_FILE}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/qshell listbucket ${qiniu_bucket} /`date +%F --date="${expired_days} days ago"` /tmp/qiniu.txt > /dev/null 2>&1
|
||||
/usr/local/bin/qshell batchdelete -force ${qiniu_bucket} /tmp/qiniu.txt > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${PUSH_FILE}
|
||||
rm -f /tmp/qiniu.txt
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_S3_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist"; break; }
|
||||
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
|
||||
PUSH_FILE="${backup_dir}/Web_${W}_$(date +%Y%m%d_%H).tgz"
|
||||
if [ ! -e "${PUSH_FILE}" ]; then
|
||||
pushd ${wwwroot_dir} > /dev/null
|
||||
tar czf ${PUSH_FILE} ./$W
|
||||
popd > /dev/null
|
||||
fi
|
||||
${python_install_dir}/bin/s3cmd put ${PUSH_FILE} s3://${s3_bucket}/`date +%F`/${PUSH_FILE##*/}
|
||||
if [ $? -eq 0 ]; then
|
||||
${python_install_dir}/bin/s3cmd rm -r s3://${s3_bucket}/`date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${PUSH_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
WEB_DROPBOX_BK() {
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist"; break; }
|
||||
[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
|
||||
PUSH_FILE="${backup_dir}/Web_${W}_$(date +%Y%m%d_%H).tgz"
|
||||
if [ ! -e "${PUSH_FILE}" ]; then
|
||||
pushd ${wwwroot_dir} > /dev/null
|
||||
tar czf ${PUSH_FILE} ./$W
|
||||
popd > /dev/null
|
||||
fi
|
||||
/usr/local/bin/dbxcli put ${PUSH_FILE} `date +%F`/${PUSH_FILE##*/}
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/dbxcli rm -f `date +%F --date="${expired_days} days ago"` > /dev/null 2>&1
|
||||
[ -z "`echo ${backup_destination} | grep -ow 'local'`" ] && rm -f ${PUSH_FILE}
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
for DEST in `echo ${backup_destination} | tr ',' ' '`
|
||||
do
|
||||
if [ "${DEST}" == 'local' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_Local_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_LOCAL_BK
|
||||
fi
|
||||
if [ "${DEST}" == 'remote' ]; then
|
||||
echo "com:::[ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}" > config_backup.txt
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_Remote_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_Remote_BK
|
||||
./mabs.sh -c config_backup.txt -T -1 | tee -a mabs.log
|
||||
fi
|
||||
if [ "${DEST}" == 'oss' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_OSS_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_OSS_BK
|
||||
fi
|
||||
if [ "${DEST}" == 'cos' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_COS_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_COS_BK
|
||||
fi
|
||||
if [ "${DEST}" == 'upyun' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_UPYUN_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_UPYUN_BK
|
||||
fi
|
||||
if [ "${DEST}" == 'qiniu' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_QINIU_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_QINIU_BK
|
||||
fi
|
||||
if [ "${DEST}" == 's3' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_S3_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_S3_BK
|
||||
fi
|
||||
if [ "${DEST}" == 'dropbox' ]; then
|
||||
[ -n "`echo ${backup_content} | grep -ow db`" ] && DB_DROPBOX_BK
|
||||
[ -n "`echo ${backup_content} | grep -ow web`" ] && WEB_DROPBOX_BK
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,535 @@
|
||||
#!/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+ #
|
||||
# Setup the backup parameters #
|
||||
# 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/options.conf
|
||||
. ./config/versions.txt
|
||||
. ./lib/color.sh
|
||||
. ./lib/check_os.sh
|
||||
. ./lib/check_dir.sh
|
||||
. ./lib/download.sh
|
||||
. ./modules/lang/python.sh
|
||||
|
||||
while :; do echo
|
||||
echo 'Please select your backup destination:'
|
||||
echo -e "\t${CMSG}1${CEND}. Localhost"
|
||||
echo -e "\t${CMSG}2${CEND}. Remote host"
|
||||
echo -e "\t${CMSG}3${CEND}. Aliyun OSS"
|
||||
echo -e "\t${CMSG}4${CEND}. Qcloud COS"
|
||||
echo -e "\t${CMSG}5${CEND}. UPYUN"
|
||||
echo -e "\t${CMSG}6${CEND}. QINIU"
|
||||
echo -e "\t${CMSG}7${CEND}. Amazon S3"
|
||||
echo -e "\t${CMSG}8${CEND}. Dropbox"
|
||||
read -e -p "Please input numbers:(Default 1 press Enter) " desc_bk
|
||||
desc_bk=${desc_bk:-'1'}
|
||||
array_desc=(${desc_bk})
|
||||
array_all=(1 2 3 4 5 6 7 8)
|
||||
for v in ${array_desc[@]}
|
||||
do
|
||||
[ -z "`echo ${array_all[@]} | grep -w ${v}`" ] && desc_flag=1
|
||||
done
|
||||
if [ "${desc_flag}" == '1' ]; then
|
||||
unset desc_flag
|
||||
echo; echo "${CWARNING}input error! Please only input number 1 3 4 and so on${CEND}"; echo
|
||||
continue
|
||||
else
|
||||
sed -i 's@^backup_destination=.*@backup_destination=@' ./config/options.conf
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
[ -n "`echo ${desc_bk} | grep -w 1`" ] && sed -i 's@^backup_destination=.*@backup_destination=local@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 2`" ] && sed -i 's@^backup_destination=.*@&,remote@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 3`" ] && sed -i 's@^backup_destination=.*@&,oss@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 4`" ] && sed -i 's@^backup_destination=.*@&,cos@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 5`" ] && sed -i 's@^backup_destination=.*@&,upyun@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 6`" ] && sed -i 's@^backup_destination=.*@&,qiniu@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 7`" ] && sed -i 's@^backup_destination=.*@&,s3@' ./config/options.conf
|
||||
[ -n "`echo ${desc_bk} | grep -w 8`" ] && sed -i 's@^backup_destination=.*@&,dropbox@' ./config/options.conf
|
||||
sed -i 's@^backup_destination=,@backup_destination=@' ./config/options.conf
|
||||
|
||||
while :; do echo
|
||||
echo 'Please select your backup content:'
|
||||
echo -e "\t${CMSG}1${CEND}. Only Database"
|
||||
echo -e "\t${CMSG}2${CEND}. Only Website"
|
||||
echo -e "\t${CMSG}3${CEND}. Database and Website"
|
||||
read -e -p "Please input a number:(Default 1 press Enter) " content_bk
|
||||
content_bk=${content_bk:-1}
|
||||
if [[ ! ${content_bk} =~ ^[1-3]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input number 1~3${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
[ "${content_bk}" == '1' ] && sed -i 's@^backup_content=.*@backup_content=db@' ./config/options.conf
|
||||
[ "${content_bk}" == '2' ] && sed -i 's@^backup_content=.*@backup_content=web@' ./config/options.conf
|
||||
[ "${content_bk}" == '3' ] && sed -i 's@^backup_content=.*@backup_content=db,web@' ./config/options.conf
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -Ew '1|2'`" ]; then
|
||||
while :; do echo
|
||||
echo "Please enter the directory for save the backup file: "
|
||||
read -e -p "(Default directory: ${backup_dir}): " new_backup_dir
|
||||
new_backup_dir=${new_backup_dir:-${backup_dir}}
|
||||
if [ -z "`echo ${new_backup_dir}| grep '^/'`" ]; then
|
||||
echo "${CWARNING}input error! ${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
sed -i "s@^backup_dir=.*@backup_dir=${new_backup_dir}@" ./config/options.conf
|
||||
fi
|
||||
|
||||
while :; do echo
|
||||
echo "Please enter a valid backup number of days: "
|
||||
read -e -p "(Default days: 5): " expired_days
|
||||
expired_days=${expired_days:-5}
|
||||
[ -n "`echo ${expired_days} | sed -n "/^[0-9]\+$/p"`" ] && break || echo "${CWARNING}input error! Please only enter numbers! ${CEND}"
|
||||
done
|
||||
sed -i "s@^expired_days=.*@expired_days=${expired_days}@" ./config/options.conf
|
||||
|
||||
if [ "${content_bk}" != '2' ]; then
|
||||
databases=`${db_install_dir}/bin/mysql -uroot -p$dbrootpwd -e "show databases\G" | grep Database | awk '{print $2}' | grep -Evw "(performance_schema|information_schema|mysql|sys)"`
|
||||
while :; do echo
|
||||
echo "Please enter one or more name for database, separate multiple database names with commas: "
|
||||
read -e -p "(Default database: `echo $databases | tr ' ' ','`) " db_name
|
||||
db_name=`echo ${db_name} | tr -d ' '`
|
||||
[ -z "${db_name}" ] && db_name="`echo $databases | tr ' ' ','`"
|
||||
D_tmp=0
|
||||
for D in `echo ${db_name} | tr ',' ' '`
|
||||
do
|
||||
[ -z "`echo $databases | grep -w $D`" ] && { echo "${CWARNING}$D was not exist! ${CEND}" ; D_tmp=1; }
|
||||
done
|
||||
[ "$D_tmp" != '1' ] && break
|
||||
done
|
||||
sed -i "s@^db_name=.*@db_name=${db_name}@" ./config/options.conf
|
||||
fi
|
||||
|
||||
if [ "${content_bk}" != '1' ]; then
|
||||
websites=`ls ${wwwroot_dir}`
|
||||
while :; do echo
|
||||
echo "Please enter one or more name for website, separate multiple website names with commas: "
|
||||
read -e -p "(Default website: `echo $websites | tr ' ' ','`) " website_name
|
||||
website_name=`echo ${website_name} | tr -d ' '`
|
||||
[ -z "${website_name}" ] && website_name="`echo $websites | tr ' ' ','`"
|
||||
W_tmp=0
|
||||
for W in `echo ${website_name} | tr ',' ' '`
|
||||
do
|
||||
[ ! -e "${wwwroot_dir}/$W" ] && { echo "${CWARNING}${wwwroot_dir}/$W not exist! ${CEND}" ; W_tmp=1; }
|
||||
done
|
||||
[ "$W_tmp" != '1' ] && break
|
||||
done
|
||||
sed -i "s@^website_name=.*@website_name=${website_name}@" ./config/options.conf
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "You have to backup the content:"
|
||||
[ "${content_bk}" != '2' ] && echo "Database: ${CMSG}${db_name}${CEND}"
|
||||
[ "${content_bk}" != '1' ] && echo "Website: ${CMSG}${website_name}${CEND}"
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 2`" ]; then
|
||||
> tools/iplist.txt
|
||||
while :; do echo
|
||||
read -e -p "Please enter the remote host address: " remote_address
|
||||
[ -z "${remote_address}" -o "${remote_address}" == '127.0.0.1' ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the remote host port(Default: 22) : " remote_port
|
||||
remote_port=${remote_port:-22}
|
||||
echo
|
||||
read -e -p "Please enter the remote host user(Default: root) : " remote_user
|
||||
remote_user=${remote_user:-root}
|
||||
echo
|
||||
read -e -p "Please enter the remote host password: " remote_password
|
||||
IPcode=$(echo "ibase=16;$(echo "${remote_address}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
|
||||
Portcode=$(echo "ibase=16;$(echo "${remote_port}" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
|
||||
PWcode=$(echo "ibase=16;$(echo "$remote_password" | xxd -ps -u)"|bc|tr -d '\\'|tr -d '\n')
|
||||
[ -e "~/.ssh/known_hosts" ] && grep ${remote_address} ~/.ssh/known_hosts | sed -i "/${remote_address}/d" ~/.ssh/known_hosts
|
||||
./tools/mssh.exp ${IPcode}P ${remote_user} ${PWcode}P ${Portcode}P true 10
|
||||
if [ $? -eq 0 ]; then
|
||||
[ -z "`grep ${remote_address} tools/iplist.txt`" ] && echo "${remote_address} ${remote_port} ${remote_user} $remote_password" >> tools/iplist.txt || echo "${CWARNING}${remote_address} has been added! ${CEND}"
|
||||
while :; do
|
||||
read -e -p "Do you want to add more host ? [y/n]: " morehost_flag
|
||||
if [[ ! ${morehost_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ "${morehost_flag}" == 'n' ] && break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 3`" ]; then
|
||||
if [ ! -e "/usr/local/bin/ossutil" ]; then
|
||||
if [ "${armplatform}" == 'y' ]; then
|
||||
wget -qc https://gosspublic.alicdn.com/ossutil/1.7.10/ossutilarm64 -O /usr/local/bin/ossutil
|
||||
else
|
||||
wget -qc https://gosspublic.alicdn.com/ossutil/1.7.10/ossutil64 -O /usr/local/bin/ossutil
|
||||
fi
|
||||
chmod +x /usr/local/bin/ossutil
|
||||
fi
|
||||
while :; do echo
|
||||
echo 'Please select your backup aliyun datacenter:'
|
||||
echo -e "\t ${CMSG}1${CEND}. cn-hangzhou-华东1 (杭州) ${CMSG}2${CEND}. cn-shanghai-华东2 (上海)"
|
||||
echo -e "\t ${CMSG}3${CEND}. cn-qingdao-华北1 (青岛) ${CMSG}4${CEND}. cn-beijing-华北2 (北京)"
|
||||
echo -e "\t ${CMSG}5${CEND}. cn-zhangjiakou-华北3 (张家口) ${CMSG}6${CEND}. cn-huhehaote-华北5(呼和浩特)"
|
||||
echo -e "\t ${CMSG}7${CEND}. cn-wulanchabu-华北6(乌兰察布) ${CMSG}8${CEND}. cn-shenzhen-华南1(深圳)"
|
||||
echo -e "\t ${CMSG}9${CEND}. cn-heyuan-华南2(河源) ${CMSG}10${CEND}. cn-guangzhou-华南3(广州)"
|
||||
echo -e "\t${CMSG}11${CEND}. cn-chengdu-西南1(成都) ${CMSG}12${CEND}. cn-hongkong-香港"
|
||||
echo -e "\t${CMSG}13${CEND}. us-west-1-美国(硅谷) ${CMSG}14${CEND}. us-east-1-美国(弗吉尼亚)"
|
||||
echo -e "\t${CMSG}15${CEND}. ap-southeast-1-新加坡 ${CMSG}16${CEND}. ap-southeast-2-澳大利亚(悉尼)"
|
||||
echo -e "\t${CMSG}17${CEND}. ap-southeast-3-马来西亚(吉隆坡)${CMSG}18${CEND}. ap-southeast-5-印度尼西亚(雅加达)"
|
||||
echo -e "\t${CMSG}19${CEND}. ap-northeast-1-日本(东京) ${CMSG}20${CEND}. ap-south-1-印度(孟买)"
|
||||
echo -e "\t${CMSG}21${CEND}. eu-central-1-德国(法兰克福) ${CMSG}22${CEND}. eu-west-1-英国(伦敦)"
|
||||
echo -e "\t${CMSG}23${CEND}. me-east-1-中东东部 (迪拜) ${CMSG}24${CEND}. ap-southeast-6-菲律宾(马尼拉)"
|
||||
read -e -p "Please input a number:(Default 1 press Enter) " Location
|
||||
Location=${Location:-1}
|
||||
if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^24$ ]]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! Please only input number 1~24${CEND}"
|
||||
fi
|
||||
done
|
||||
[ "${Location}" == '1' ] && Host=oss-cn-hangzhou-internal.aliyuncs.com
|
||||
[ "${Location}" == '2' ] && Host=oss-cn-shanghai-internal.aliyuncs.com
|
||||
[ "${Location}" == '3' ] && Host=oss-cn-qingdao-internal.aliyuncs.com
|
||||
[ "${Location}" == '4' ] && Host=oss-cn-beijing-internal.aliyuncs.com
|
||||
[ "${Location}" == '5' ] && Host=oss-cn-zhangjiakou-internal.aliyuncs.com
|
||||
[ "${Location}" == '6' ] && Host=oss-cn-huhehaote-internal.aliyuncs.com
|
||||
[ "${Location}" == '7' ] && Host=oss-cn-wulanchabu-internal.aliyuncs.com
|
||||
[ "${Location}" == '8' ] && Host=oss-cn-shenzhen-internal.aliyuncs.com
|
||||
[ "${Location}" == '9' ] && Host=oss-cn-heyuan-internal.aliyuncs.com
|
||||
[ "${Location}" == '10' ] && Host=oss-cn-guangzhou-internal.aliyuncs.com
|
||||
[ "${Location}" == '11' ] && Host=oss-cn-chengdu-internal.aliyuncs.com
|
||||
[ "${Location}" == '12' ] && Host=oss-cn-hongkong-internal.aliyuncs.com
|
||||
[ "${Location}" == '13' ] && Host=oss-us-west-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '14' ] && Host=oss-us-east-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '15' ] && Host=oss-ap-southeast-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '16' ] && Host=oss-ap-southeast-2-internal.aliyuncs.com
|
||||
[ "${Location}" == '17' ] && Host=oss-ap-southeast-3-internal.aliyuncs.com
|
||||
[ "${Location}" == '18' ] && Host=oss-ap-southeast-5-internal.aliyuncs.com
|
||||
[ "${Location}" == '19' ] && Host=oss-ap-northeast-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '20' ] && Host=oss-ap-south-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '21' ] && Host=oss-eu-central-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '22' ] && Host=oss-eu-west-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '23' ] && Host=oss-me-east-1-internal.aliyuncs.com
|
||||
[ "${Location}" == '24' ] && Host=oss-ap-southeast-6-internal.aliyuncs.com
|
||||
[ "$(./lib/py/check_port.py ${Host} 80)" == "False" ] && Host=`echo ${Host} | sed 's@-internal@@g'`
|
||||
[ -e "/root/.ossutilconfig" ] && rm -f /root/.ossutilconfig
|
||||
while :; do echo
|
||||
read -e -p "Please enter the aliyun oss Access Key ID: " KeyID
|
||||
[ -z "${KeyID}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the aliyun oss Access Key Secret: " KeySecret
|
||||
[ -z "${KeySecret}" ] && continue
|
||||
/usr/local/bin/ossutil ls -e ${Host} -i ${KeyID} -k ${KeySecret} > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
/usr/local/bin/ossutil config -e ${Host} -i ${KeyID} -k ${KeySecret} > /dev/null 2>&1
|
||||
while :; do echo
|
||||
read -e -p "Please enter the aliyun oss bucket: " OSS_BUCKET
|
||||
/usr/local/bin/ossutil mb oss://${OSS_BUCKET} > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${CMSG}Bucket oss://${OSS_BUCKET}/ created${CEND}"
|
||||
sed -i "s@^oss_bucket=.*@oss_bucket=${OSS_BUCKET}@" ./config/options.conf
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}[${OSS_BUCKET}] already exists, You need to use the OSS Console to create a bucket for storing.${CEND}"
|
||||
fi
|
||||
done
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 4`" ]; then
|
||||
Install_Python
|
||||
[ ! -e "${python_install_dir}/bin/coscmd" ] && ${python_install_dir}/bin/pip install coscmd > /dev/null 2>&1
|
||||
while :; do echo
|
||||
echo 'Please select your backup qcloud datacenter:'
|
||||
echo -e "\t ${CMSG} 1${CEND}. ap-beijing-1-北京一区(华北) ${CMSG}2${CEND}. ap-beijing-北京"
|
||||
echo -e "\t ${CMSG} 3${CEND}. ap-nanjing-南京 ${CMSG}4${CEND}. ap-shanghai-上海"
|
||||
echo -e "\t ${CMSG} 5${CEND}. ap-guangzhou-广州 ${CMSG}6${CEND}. ap-chengdu-成都"
|
||||
echo -e "\t ${CMSG} 7${CEND}. ap-chongqing-重庆 ${CMSG}8${CEND}. ap-shenzhen-fsi-深圳金融"
|
||||
echo -e "\t ${CMSG} 9${CEND}. ap-shanghai-fsi-上海金融 ${CMSG}10${CEND}. ap-beijing-fsi-北京金融"
|
||||
echo -e "\t ${CMSG}11${CEND}. ap-hongkong-香港 ${CMSG}11${CEND}. ap-singapore-新加坡"
|
||||
echo -e "\t ${CMSG}13${CEND}. ap-mumbai-孟买 ${CMSG}14${CEND}. ap-jakarta-雅加达"
|
||||
echo -e "\t ${CMSG}15${CEND}. ap-seoul-首尔 ${CMSG}16${CEND}. ap-bangkok-曼谷"
|
||||
echo -e "\t ${CMSG}17${CEND}. ap-tokyo-东京 ${CMSG}18${CEND}. na-siliconvalley-硅谷(美西)"
|
||||
echo -e "\t ${CMSG}19${CEND}. na-ashburn-弗吉尼亚(美东) ${CMSG}20${CEND}. na-toronto-多伦多"
|
||||
echo -e "\t ${CMSG}21${CEND}. sa-saopaulo-圣保罗 ${CMSG}22${CEND}. eu-frankfurt-法兰克福"
|
||||
echo -e "\t ${CMSG}23${CEND}. eu-moscow-莫斯科"
|
||||
read -e -p "Please input a number:(Default 1 press Enter) " Location
|
||||
Location=${Location:-1}
|
||||
if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^2[0-3]$ ]]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! Please only input number 1~23${CEND}"
|
||||
fi
|
||||
done
|
||||
[ "${Location}" == '1' ] && REGION='ap-beijing-1'
|
||||
[ "${Location}" == '2' ] && REGION='ap-beijing'
|
||||
[ "${Location}" == '3' ] && REGION='ap-nanjing'
|
||||
[ "${Location}" == '4' ] && REGION='ap-shanghai'
|
||||
[ "${Location}" == '5' ] && REGION='ap-guangzhou'
|
||||
[ "${Location}" == '6' ] && REGION='ap-chengdu'
|
||||
[ "${Location}" == '7' ] && REGION='ap-chongqing'
|
||||
[ "${Location}" == '8' ] && REGION='ap-shenzhen-fsi'
|
||||
[ "${Location}" == '9' ] && REGION='ap-shanghai-fsi'
|
||||
[ "${Location}" == '10' ] && REGION='ap-beijing-fsi'
|
||||
[ "${Location}" == '11' ] && REGION='ap-hongkong'
|
||||
[ "${Location}" == '12' ] && REGION='ap-singapore'
|
||||
[ "${Location}" == '13' ] && REGION='ap-mumbai'
|
||||
[ "${Location}" == '14' ] && REGION='ap-jakarta'
|
||||
[ "${Location}" == '15' ] && REGION='ap-seoul'
|
||||
[ "${Location}" == '16' ] && REGION='ap-bangkok'
|
||||
[ "${Location}" == '17' ] && REGION='ap-tokyo'
|
||||
[ "${Location}" == '18' ] && REGION='na-siliconvalley'
|
||||
[ "${Location}" == '19' ] && REGION='na-ashburn'
|
||||
[ "${Location}" == '20' ] && REGION='na-toronto'
|
||||
[ "${Location}" == '21' ] && REGION='sa-saopaulo'
|
||||
[ "${Location}" == '22' ] && REGION='eu-frankfurt'
|
||||
[ "${Location}" == '23' ] && REGION='eu-moscow'
|
||||
while :; do echo
|
||||
read -e -p "Please enter the Qcloud COS APPID: " APPID
|
||||
[[ ! "${APPID}" =~ ^[0-9]+$ ]] && { echo "${CWARNING}input error, must be a number${CEND}"; continue; }
|
||||
echo
|
||||
read -e -p "Please enter the Qcloud COS SECRET_ID: " SECRET_ID
|
||||
[ -z "${SECRET_ID}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the Qcloud COS SECRET_KEY: " SECRET_KEY
|
||||
[ -z "${SECRET_KEY}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the Qcloud COS BUCKET: " COS_BUCKET
|
||||
if [[ ${COS_BUCKET} =~ "-${APPID}"$ ]]; then
|
||||
COS_BUCKET=${COS_BUCKET}
|
||||
else
|
||||
[ -z "${COS_BUCKET}" ] && continue
|
||||
echo
|
||||
COS_BUCKET=${COS_BUCKET}-${APPID}
|
||||
fi
|
||||
${python_install_dir}/bin/coscmd config -u ${APPID} -a ${SECRET_ID} -s ${SECRET_KEY} -r ${REGION} -b ${COS_BUCKET} > /dev/null 2>&1
|
||||
${python_install_dir}/bin/coscmd list > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${CMSG}APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET OK${CEND}"
|
||||
echo
|
||||
break
|
||||
else
|
||||
${python_install_dir}/bin/coscmd -b ${COS_BUCKET} createbucket > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${CMSG}Bucket ${COS_BUCKET} created${CEND}"
|
||||
echo
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! APPID/SECRET_ID/SECRET_KEY/REGION/BUCKET invalid${CEND}"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 5`" ]; then
|
||||
if [ ! -e "/usr/local/bin/upx" ]; then
|
||||
if [ "${armplatform}" == 'y' ]; then
|
||||
wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx_0.3.6_linux_arm64.tar.gz -O /tmp/upx_0.3.6_linux_arm64.tar.gz
|
||||
tar xzf /tmp/upx_0.3.6_linux_arm64.tar.gz -C /tmp/
|
||||
else
|
||||
wget -qc http://collection.b0.upaiyun.com/softwares/upx/upx_0.3.6_linux_x86_64.tar.gz -O /tmp/upx_0.3.6_linux_x86_64.tar.gz
|
||||
tar xzf /tmp/upx_0.3.6_linux_x86_64.tar.gz -C /tmp/
|
||||
fi
|
||||
/bin/mv /tmp/upx /usr/local/bin/upx
|
||||
chmod +x /usr/local/bin/upx
|
||||
rm -f /tmp/upx_* /tmp/LICENSE /tmp/README.md
|
||||
fi
|
||||
while :; do echo
|
||||
read -e -p "Please enter the upyun ServiceName: " ServiceName
|
||||
[ -z "${ServiceName}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the upyun Operator: " Operator
|
||||
[ -z "${Operator}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the upyun Password: " Password
|
||||
[ -z "${Password}" ] && continue
|
||||
echo
|
||||
/usr/local/bin/upx login ${ServiceName} ${Operator} ${Password} > /dev/null 2>&1
|
||||
if [ $? = 0 ]; then
|
||||
echo "${CMSG}ServiceName/Operator/Password OK${CEND}"
|
||||
echo
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! ServiceName/Operator/Password invalid${CEND}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 6`" ]; then
|
||||
if [ ! -e "/usr/local/bin/qshell" ]; then
|
||||
if [ "${armplatform}" == 'y' ]; then
|
||||
wget -qc https://devtools.qiniu.com/qshell-v2.6.2-linux-arm64.tar.gz -O /tmp/qshell-v2.6.2-linux-arm64.tar.gz
|
||||
tar xzf /tmp/qshell-v2.6.2-linux-arm64.tar.gz -C /usr/local/bin/
|
||||
else
|
||||
wget -qc https://devtools.qiniu.com/qshell-v2.6.2-linux-amd64.tar.gz -O /tmp/qshell-v2.6.2-linux-amd64.tar.gz
|
||||
tar xzf /tmp/qshell-v2.6.2-linux-amd64.tar.gz -C /usr/local/bin/
|
||||
fi
|
||||
chmod +x /usr/local/bin/qshell
|
||||
rm -f /tmp/qshell*
|
||||
fi
|
||||
while :; do echo
|
||||
echo 'Please select your backup qiniu datacenter:'
|
||||
echo -e "\t ${CMSG} 1${CEND}. 华东 ${CMSG}2${CEND}. 华北"
|
||||
echo -e "\t ${CMSG} 3${CEND}. 华南 ${CMSG}4${CEND}. 北美"
|
||||
echo -e "\t ${CMSG} 5${CEND}. 东南亚 ${CMSG}6${CEND}. 华东-浙江2"
|
||||
read -e -p "Please input a number:(Default 1 press Enter) " Location
|
||||
Location=${Location:-1}
|
||||
if [[ "${Location}" =~ ^[1-6]$ ]]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! Please only input number 1~6${CEND}"
|
||||
fi
|
||||
done
|
||||
[ "${Location}" == '1' ] && zone='z0'
|
||||
[ "${Location}" == '2' ] && zone='z1'
|
||||
[ "${Location}" == '3' ] && zone='z2'
|
||||
[ "${Location}" == '4' ] && zone='na0'
|
||||
[ "${Location}" == '5' ] && zone='as0'
|
||||
[ "${Location}" == '6' ] && zone='cn-east-2'
|
||||
while :; do echo
|
||||
read -e -p "Please enter the qiniu AccessKey: " AccessKey
|
||||
[ -z "${AccessKey}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the qiniu SecretKey: " SecretKey
|
||||
[ -z "${SecretKey}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the qiniu bucket: " QINIU_BUCKET
|
||||
[ -z "${QINIU_BUCKET}" ] && continue
|
||||
echo
|
||||
/usr/local/bin/qshell account ${AccessKey} ${SecretKey} backup
|
||||
if /usr/local/bin/qshell buckets | grep -w ${QINIU_BUCKET} > /dev/null 2>&1; then
|
||||
sed -i "s@^qiniu_bucket=.*@qiniu_bucket=${QINIU_BUCKET}@" ./config/options.conf
|
||||
echo "${CMSG}AccessKey/SecretKey/Bucket OK${CEND}"
|
||||
echo
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! AccessKey/SecretKey/Bucket invalid${CEND}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 7`" ]; then
|
||||
Install_Python
|
||||
[ ! -e "${python_install_dir}/bin/s3cmd" ] && ${python_install_dir}/bin/pip install s3cmd > /dev/null 2>&1
|
||||
while :; do echo
|
||||
echo 'Please select your backup amazon datacenter:'
|
||||
echo -e "\t ${CMSG} 1${CEND}. us-east-2 ${CMSG} 2${CEND}. us-east-1"
|
||||
echo -e "\t ${CMSG} 3${CEND}. us-west-1 ${CMSG} 4${CEND}. us-west-2"
|
||||
echo -e "\t ${CMSG} 5${CEND}. ap-south-1 ${CMSG} 6${CEND}. ap-northeast-3"
|
||||
echo -e "\t ${CMSG} 7${CEND}. ap-northeast-2 ${CMSG} 8${CEND}. ap-southeast-1"
|
||||
echo -e "\t ${CMSG} 9${CEND}. ap-southeast-2 ${CMSG}10${CEND}. ap-northeast-1"
|
||||
echo -e "\t ${CMSG}11${CEND}. ca-central-1 ${CMSG}12${CEND}. cn-north-1"
|
||||
echo -e "\t ${CMSG}13${CEND}. cn-northwest-1 ${CMSG}14${CEND}. eu-central-1"
|
||||
echo -e "\t ${CMSG}15${CEND}. eu-west-1 ${CMSG}16${CEND}. eu-west-2"
|
||||
echo -e "\t ${CMSG}17${CEND}. eu-west-3 ${CMSG}18${CEND}. eu-north-1"
|
||||
echo -e "\t ${CMSG}19${CEND}. sa-east-1 ${CMSG}20${CEND}. us-gov-east-1"
|
||||
echo -e "\t ${CMSG}21${CEND}. us-gov-west-1"
|
||||
read -e -p "Please input a number:(Default 1 press Enter) " Location
|
||||
Location=${Location:-1}
|
||||
if [[ "${Location}" =~ ^[1-9]$|^1[0-9]$|^2[0-1]$ ]]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! Please only input number 1~21${CEND}"
|
||||
fi
|
||||
done
|
||||
[ "${Location}" == '1' ] && REGION='us-east-2'
|
||||
[ "${Location}" == '2' ] && REGION='us-east-1'
|
||||
[ "${Location}" == '3' ] && REGION='us-west-1'
|
||||
[ "${Location}" == '4' ] && REGION='us-west-2'
|
||||
[ "${Location}" == '5' ] && REGION='ap-south-1'
|
||||
[ "${Location}" == '6' ] && REGION='ap-northeast-3'
|
||||
[ "${Location}" == '7' ] && REGION='ap-northeast-2'
|
||||
[ "${Location}" == '8' ] && REGION='ap-southeast-1'
|
||||
[ "${Location}" == '9' ] && REGION='ap-southeast-2'
|
||||
[ "${Location}" == '10' ] && REGION='ap-northeast-1'
|
||||
[ "${Location}" == '11' ] && REGION='ca-central-1'
|
||||
[ "${Location}" == '12' ] && REGION='cn-north-1'
|
||||
[ "${Location}" == '13' ] && REGION='cn-northwest-1'
|
||||
[ "${Location}" == '14' ] && REGION='eu-central-1'
|
||||
[ "${Location}" == '15' ] && REGION='eu-west-1'
|
||||
[ "${Location}" == '16' ] && REGION='eu-west-2'
|
||||
[ "${Location}" == '17' ] && REGION='eu-west-3'
|
||||
[ "${Location}" == '18' ] && REGION='eu-north-1'
|
||||
[ "${Location}" == '19' ] && REGION='sa-east-1'
|
||||
[ "${Location}" == '20' ] && REGION='us-gov-east-1'
|
||||
[ "${Location}" == '21' ] && REGION='us-gov-west-1'
|
||||
while :; do echo
|
||||
read -e -p "Please enter the AWS Access Key: " ACCESS_KEY
|
||||
[ -z "${ACCESS_KEY}" ] && continue
|
||||
echo
|
||||
read -e -p "Please enter the AWS Access Key: " SECRET_KEY
|
||||
[ -z "${SECRET_KEY}" ] && continue
|
||||
${python_install_dir}/bin/s3cmd --access_key=${ACCESS_KEY} --secret_key=${SECRET_KEY} --region=${REGION} la > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
${python_install_dir}/bin/s3cmd --configure --access_key=${ACCESS_KEY} --secret_key=${SECRET_KEY} --region=${REGION} --dump-config > ~/.s3cfg
|
||||
echo "${CMSG}ACCESS_KEY/SECRET_KEY OK${CEND}"
|
||||
while :; do echo
|
||||
read -e -p "Please enter the Amazon S3 bucket: " S3_BUCKET
|
||||
[ -z "${S3_BUCKET}" ] && continue
|
||||
${python_install_dir}/bin/s3cmd ls s3://${S3_BUCKET} > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${CMSG}Bucket s3://${S3_BUCKET}/ existed${CEND}"
|
||||
sed -i "s@^s3_bucket=.*@s3_bucket=${S3_BUCKET}@" ./config/options.conf
|
||||
break
|
||||
else
|
||||
${python_install_dir}/bin/s3cmd mb s3://${S3_BUCKET} > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${CMSG}Bucket s3://${S3_BUCKET}/ created${CEND}"
|
||||
sed -i "s@^s3_bucket=.*@s3_bucket=${S3_BUCKET}@" ./config/options.conf
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.${CEND}"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
done
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error! ACCESS_KEY/SECRET_KEY invalid${CEND}"
|
||||
continue
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -n "`echo ${desc_bk} | grep -w 8`" ]; then
|
||||
if [ ! -e "/usr/local/bin/dbxcli" ]; then
|
||||
if [ "${armplatform}" == 'y' ]; then
|
||||
wget -qc http://mirrors.linuxeye.com/oneinstack/src/dbxcli-linux-arm -O /usr/local/bin/dbxcli
|
||||
else
|
||||
wget -qc http://mirrors.linuxeye.com/oneinstack/src/dbxcli-linux-amd64 -O /usr/local/bin/dbxcli
|
||||
fi
|
||||
chmod +x /usr/local/bin/dbxcli
|
||||
fi
|
||||
while :; do echo
|
||||
if dbxcli account; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
# ServerStack entry point.
|
||||
#
|
||||
# This script is now a THIN ENTRY POINT only. It bootstraps the environment
|
||||
# and orchestrates the install workflow by calling main() from
|
||||
# core/workflow.sh. All business logic (system detection, parameter
|
||||
# parsing, menu, download, install, config, services, summary) has been moved
|
||||
# into focused modules under lib/ (shared functions), core/ (orchestration)
|
||||
# and modules/ (per-software installers).
|
||||
#
|
||||
# Usage and behavior are unchanged from the previous install.sh.
|
||||
|
||||
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||
|
||||
# Ensure cwd is the project root so all relative sources work exactly as before.
|
||||
# oneinstack_dir is the project root (one level up from bin/); falling back to
|
||||
# "$0" keeps this working even when readlink -f is unavailable.
|
||||
oneinstack_dir="$(cd "$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")/.." && pwd)"
|
||||
cd "${oneinstack_dir}" || exit 1
|
||||
|
||||
# Load framework modules (function definitions only; nothing runs yet).
|
||||
. ./lib/loader.sh
|
||||
. ./lib/log.sh
|
||||
. ./core/environment.sh
|
||||
. ./core/init.sh
|
||||
. ./core/argument.sh
|
||||
. ./core/menu.sh
|
||||
. ./core/validator.sh
|
||||
. ./core/installer.sh
|
||||
. ./core/service.sh
|
||||
. ./core/summary.sh
|
||||
. ./core/workflow.sh
|
||||
|
||||
# Unified exception handling (cleanup / rollback on exit, interrupt, terminate).
|
||||
# NOTE: ERR is intentionally NOT trapped. Binding ERR would fire trap_handler on
|
||||
# every non-zero command (even benign ones outside if/&&/||) and auto-write an
|
||||
# [ERROR] line to install.log, changing the original log output. Logging is done
|
||||
# explicitly via log_error/error_exit; this trap only guarantees best-effort
|
||||
# cleanup (currently no-ops) so the happy path and its logs stay faithful.
|
||||
trap 'trap_handler' EXIT INT TERM
|
||||
|
||||
# Run the install workflow.
|
||||
main "$@"
|
||||
@@ -0,0 +1,271 @@
|
||||
#!/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+ #
|
||||
# FTP virtual user account management #
|
||||
# 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/options.conf
|
||||
. ./lib/color.sh
|
||||
|
||||
[ ! -d "${pureftpd_install_dir}" ] && { echo "${CFAILURE}FTP server does not exist! ${CEND}"; exit 1; }
|
||||
|
||||
FTP_conf=${pureftpd_install_dir}/etc/pure-ftpd.conf
|
||||
FTP_tmp_passfile=${pureftpd_install_dir}/etc/pureftpd_psss.tmp
|
||||
Puredbfile=${pureftpd_install_dir}/etc/pureftpd.pdb
|
||||
Passwdfile=${pureftpd_install_dir}/etc/pureftpd.passwd
|
||||
FTP_bin=${pureftpd_install_dir}/bin/pure-pw
|
||||
[ -z "`grep ^PureDB ${FTP_conf}`" ] && { echo "${CFAILURE}pure-ftpd is not own password database${CEND}" ; exit 1; }
|
||||
|
||||
ARG_NUM=$#
|
||||
Show_Help() {
|
||||
echo
|
||||
echo "Usage: $0 command ...[parameters]....
|
||||
--help, -h Show this help message
|
||||
--useradd,--add Add username
|
||||
--usermod Modify directory
|
||||
--passwd Modify password
|
||||
--userdel,--delete Delete User
|
||||
--listalluser,--list List all User
|
||||
--showuser List User details
|
||||
--username,-u [ftp username] Ftp username
|
||||
--password,-p [ftp password] Ftp password
|
||||
--directory,-d,-D [ftp directory] Ftp home directory
|
||||
"
|
||||
}
|
||||
|
||||
TEMP=`getopt -o hu:p:d:D: --long help,useradd,add,usermod,passwd,userdel,delete,listalluser,list,showuser,username:,password:,directory: -- "$@" 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
|
||||
;;
|
||||
--add|--useradd)
|
||||
useradd_flag=y; shift 1
|
||||
;;
|
||||
--usermod)
|
||||
usermod_flag=y; shift 1
|
||||
;;
|
||||
--passwd)
|
||||
passwd_flag=y; shift 1
|
||||
;;
|
||||
--delete|--userdel)
|
||||
userdel_flag=y; shift 1
|
||||
;;
|
||||
--list|--listalluser)
|
||||
listalluser_flag=y; shift 1
|
||||
;;
|
||||
--showuser)
|
||||
showuser_flag=y; shift 1
|
||||
;;
|
||||
-u|--username)
|
||||
username_flag=y; User=$2; shift 2
|
||||
;;
|
||||
-p|--password)
|
||||
password_flag=y; Password=$2; shift 2
|
||||
;;
|
||||
-d|-D|--directory)
|
||||
directory_flag=y; Directory=$2; shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
USER() {
|
||||
while :; do
|
||||
if [ "${username_flag}" != 'y' ]; then
|
||||
echo
|
||||
read -e -p "Please input a username: " User
|
||||
fi
|
||||
if [ -z "${User}" ]; then
|
||||
echo "${CWARNING}username can't be NULL! ${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
PASSWORD() {
|
||||
while :; do
|
||||
if [ "${password_flag}" != 'y' ]; then
|
||||
echo
|
||||
read -e -p "Please input the password: " Password
|
||||
fi
|
||||
[ -n "`echo ${Password} | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and &${CEND}"; continue; }
|
||||
if (( ${#Password} >= 5 )); then
|
||||
echo -e "${Password}\n${Password}" > ${FTP_tmp_passfile}
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}Ftp password least 5 characters! ${CEND}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
DIRECTORY() {
|
||||
while :; do
|
||||
if [ "${directory_flag}" != 'y' ]; then
|
||||
echo
|
||||
read -e -p "Please input the directory(Default directory: ${wwwroot_dir}): " Directory
|
||||
fi
|
||||
Directory=${Directory:-${wwwroot_dir}}
|
||||
if [ ! -d "${Directory}" ]; then
|
||||
echo "${CWARNING}The directory does not exist${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
UserAdd() {
|
||||
USER
|
||||
[ -e "${Passwdfile}" ] && [ -n "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] is already existed! ${CEND}"; exit 1; }
|
||||
PASSWORD;DIRECTORY
|
||||
${FTP_bin} useradd ${User} -f ${Passwdfile} -u ${run_user} -g ${run_group} -d ${Directory} -m < ${FTP_tmp_passfile}
|
||||
${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
|
||||
echo "#####################################"
|
||||
echo
|
||||
echo "[${User}] create successful! "
|
||||
echo
|
||||
echo "You user name is : ${CMSG}${User}${CEND}"
|
||||
echo "You Password is : ${CMSG}${Password}${CEND}"
|
||||
echo "You directory is : ${CMSG}${Directory}${CEND}"
|
||||
echo
|
||||
}
|
||||
|
||||
UserMod() {
|
||||
USER
|
||||
[ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
|
||||
DIRECTORY
|
||||
${FTP_bin} usermod ${User} -f ${Passwdfile} -d ${Directory} -m
|
||||
${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
|
||||
echo "#####################################"
|
||||
echo
|
||||
echo "[${User}] modify a successful! "
|
||||
echo
|
||||
echo "You user name is : ${CMSG}${User}${CEND}"
|
||||
echo "You new directory is : ${CMSG}${Directory}${CEND}"
|
||||
echo
|
||||
}
|
||||
|
||||
UserPasswd() {
|
||||
USER
|
||||
[ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
|
||||
PASSWORD
|
||||
${FTP_bin} passwd ${User} -f ${Passwdfile} -m < ${FTP_tmp_passfile}
|
||||
${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
|
||||
echo "#####################################"
|
||||
echo
|
||||
echo "[${User}] Password changed successfully! "
|
||||
echo
|
||||
echo "You user name is : ${CMSG}${User}${CEND}"
|
||||
echo "You new password is : ${CMSG}${Password}${CEND}"
|
||||
echo
|
||||
}
|
||||
|
||||
UserDel() {
|
||||
if [ ! -e "${Passwdfile}" ]; then
|
||||
echo "${CQUESTION}User was not existed! ${CEND}"
|
||||
else
|
||||
${FTP_bin} list
|
||||
fi
|
||||
|
||||
USER
|
||||
[ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
|
||||
${FTP_bin} userdel ${User} -f ${Passwdfile} -m
|
||||
${FTP_bin} mkdb ${Puredbfile} -f ${Passwdfile} > /dev/null 2>&1
|
||||
echo
|
||||
echo "[${User}] have been deleted! "
|
||||
}
|
||||
|
||||
ListAllUser() {
|
||||
if [ ! -e "${Passwdfile}" ]; then
|
||||
echo "${CQUESTION}User was not existed! ${CEND}"
|
||||
else
|
||||
${FTP_bin} list
|
||||
fi
|
||||
}
|
||||
|
||||
ShowUser() {
|
||||
USER
|
||||
[ -e "${Passwdfile}" ] && [ -z "`grep ^${User}: ${Passwdfile}`" ] && { echo "${CQUESTION}[${User}] was not existed! ${CEND}"; exit 1; }
|
||||
${FTP_bin} show ${User}
|
||||
}
|
||||
|
||||
Menu() {
|
||||
while :; do
|
||||
printf "
|
||||
What Are You Doing?
|
||||
\t${CMSG}1${CEND}. UserAdd
|
||||
\t${CMSG}2${CEND}. UserMod
|
||||
\t${CMSG}3${CEND}. UserPasswd
|
||||
\t${CMSG}4${CEND}. UserDel
|
||||
\t${CMSG}5${CEND}. ListAllUser
|
||||
\t${CMSG}6${CEND}. ShowUser
|
||||
\t${CMSG}q${CEND}. Exit
|
||||
"
|
||||
read -e -p "Please input the correct option: " Number
|
||||
if [[ ! ${Number} =~ ^[1-6,q]$ ]]; then
|
||||
echo "${CFAILURE}input error! Please only input 1~6 and q${CEND}"
|
||||
else
|
||||
case "${Number}" in
|
||||
1)
|
||||
UserAdd
|
||||
;;
|
||||
2)
|
||||
UserMod
|
||||
;;
|
||||
3)
|
||||
UserPasswd
|
||||
;;
|
||||
4)
|
||||
UserDel
|
||||
;;
|
||||
5)
|
||||
ListAllUser
|
||||
;;
|
||||
6)
|
||||
ShowUser
|
||||
;;
|
||||
q)
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ ${ARG_NUM} == 0 ]; then
|
||||
Menu
|
||||
else
|
||||
[ "${useradd_flag}" == 'y' ] && UserAdd
|
||||
[ "${usermod_flag}" == 'y' ] && UserMod
|
||||
[ "${passwd_flag}" == 'y' ] && UserPasswd
|
||||
[ "${userdel_flag}" == 'y' ] && UserDel
|
||||
[ "${listalluser_flag}" == 'y' ] && ListAllUser
|
||||
[ "${showuser_flag}" == 'y' ] && ShowUser
|
||||
fi
|
||||
@@ -0,0 +1,145 @@
|
||||
#!/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+ #
|
||||
# Reset Database root password for OneinStack #
|
||||
# For more information please visit https://oneinstack.com #
|
||||
#######################################################################
|
||||
"
|
||||
oneinstack_dir="$(cd "$(dirname "$(readlink -f "$0" 2>/dev/null || echo "$0")")/.." && pwd)"
|
||||
cd "${oneinstack_dir}" || exit 1
|
||||
. ./config/options.conf
|
||||
. ./lib/color.sh
|
||||
. ./lib/check_dir.sh
|
||||
[ ! -d "${db_install_dir}" ] && { echo "${CFAILURE}Database is not installed on your system! ${CEND}"; exit 1; }
|
||||
|
||||
Show_Help() {
|
||||
echo "Usage: $0 command ...[parameters]....
|
||||
-h, --help print this help.
|
||||
-q, --quiet quiet operation.
|
||||
-f, --force Lost Database Password? Forced reset password.
|
||||
-p, --password [pass] DB super password.
|
||||
"
|
||||
}
|
||||
|
||||
New_dbrootpwd="`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`"
|
||||
TEMP=`getopt -o hqfp: --long help,quiet,force,password: -- "$@" 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
|
||||
;;
|
||||
-q|--quiet)
|
||||
quiet_flag=y; shift 1
|
||||
;;
|
||||
-f|--force)
|
||||
force_flag=y; shift 1
|
||||
;;
|
||||
-p|--password)
|
||||
New_dbrootpwd=$2; shift 2
|
||||
password_flag=y
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
Input_dbrootpwd() {
|
||||
while :; do echo
|
||||
read -e -p "Please input the root password of database: " New_dbrootpwd
|
||||
[ -n "`echo ${New_dbrootpwd} | grep '[+|&]'`" ] && { echo "${CWARNING}input error,not contain a plus sign (+) and &${CEND}"; continue; }
|
||||
(( ${#New_dbrootpwd} >= 5 )) && break || echo "${CWARNING}database root password least 5 characters! ${CEND}"
|
||||
done
|
||||
}
|
||||
|
||||
Reset_Interaction_dbrootpwd() {
|
||||
${db_install_dir}/bin/mysqladmin -uroot -p"${dbrootpwd}" password "${New_dbrootpwd}" -h localhost > /dev/null 2>&1
|
||||
status_Localhost=`echo $?`
|
||||
${db_install_dir}/bin/mysqladmin -uroot -p"${dbrootpwd}" password "${New_dbrootpwd}" -h 127.0.0.1 > /dev/null 2>&1
|
||||
status_127=`echo $?`
|
||||
if [ ${status_Localhost} == '0' -a ${status_127} == '0' ]; then
|
||||
sed -i "s+^dbrootpwd.*+dbrootpwd='${New_dbrootpwd}'+" ./config/options.conf
|
||||
echo
|
||||
echo "Password reset succesfully! "
|
||||
echo "The new password: ${CMSG}${New_dbrootpwd}${CEND}"
|
||||
echo
|
||||
else
|
||||
echo "${CFAILURE}Reset Database root password failed! ${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
Reset_force_dbrootpwd() {
|
||||
DB_Ver="`${db_install_dir}/bin/mysql_config --version`"
|
||||
echo "${CMSG}Stopping MySQL...${CEND}"
|
||||
service mysqld stop > /dev/null 2>&1
|
||||
while [ -n "`ps -ef | grep mysqld | grep -v grep | awk '{print $2}'`" ]; do
|
||||
sleep 1
|
||||
done
|
||||
echo "${CMSG}skip grant tables...${CEND}"
|
||||
${db_install_dir}/bin/mysqld_safe --skip-grant-tables > /dev/null 2>&1 &
|
||||
sleep 5
|
||||
while [ -z "`ps -ef | grep 'mysqld ' | grep -v grep | awk '{print $2}'`" ]; do
|
||||
sleep 1
|
||||
done
|
||||
if echo "${DB_Ver}" | grep -Eqi '^8.0.|^5.7.|^10.2.'; then
|
||||
${db_install_dir}/bin/mysql -uroot -hlocalhost << EOF
|
||||
flush privileges;
|
||||
alter user 'root'@'localhost' identified by "${New_dbrootpwd}";
|
||||
alter user 'root'@'127.0.0.1' identified by "${New_dbrootpwd}";
|
||||
EOF
|
||||
else
|
||||
${db_install_dir}/bin/mysql -uroot -hlocalhost << EOF
|
||||
update mysql.user set password = Password("${New_dbrootpwd}") where User = 'root';
|
||||
EOF
|
||||
fi
|
||||
if [ $? -eq 0 ]; then
|
||||
killall mysqld
|
||||
while [ -n "`ps -ef | grep mysqld | grep -v grep | awk '{print $2}'`" ]; do
|
||||
sleep 1
|
||||
done
|
||||
[ -n "`ps -ef | grep mysqld | grep -v grep | awk '{print $2}'`" ] && ps -ef | grep mysqld | grep -v grep | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1
|
||||
service mysqld start > /dev/null 2>&1
|
||||
sed -i "s+^dbrootpwd.*+dbrootpwd='${New_dbrootpwd}'+" ./config/options.conf
|
||||
[ -e ~/ReadMe ] && sed -i "s+^MySQL root password:.*+MySQL root password: ${New_dbrootpwd}+" ~/ReadMe
|
||||
echo
|
||||
echo "Password reset succesfully! "
|
||||
echo "The new password: ${CMSG}${New_dbrootpwd}${CEND}"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
[ "${password_flag}" == 'y' ] && quiet_flag=y
|
||||
if [ "${quiet_flag}" == 'y' ]; then
|
||||
if [ "${force_flag}" == 'y' ]; then
|
||||
Reset_force_dbrootpwd
|
||||
else
|
||||
sleep 2 && [ ! -e /tmp/mysql.sock ] && service mysqld start
|
||||
Reset_Interaction_dbrootpwd
|
||||
fi
|
||||
else
|
||||
Input_dbrootpwd
|
||||
if [ "${force_flag}" == 'y' ]; then
|
||||
Reset_force_dbrootpwd
|
||||
else
|
||||
Reset_Interaction_dbrootpwd
|
||||
fi
|
||||
fi
|
||||
popd > /dev/null
|
||||
@@ -0,0 +1,686 @@
|
||||
#!/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+ #
|
||||
# Uninstall 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/options.conf
|
||||
. ./lib/color.sh
|
||||
. ./lib/get_char.sh
|
||||
. ./lib/check_dir.sh
|
||||
|
||||
Show_Help() {
|
||||
echo
|
||||
echo "Usage: $0 command ...[parameters]....
|
||||
--help, -h Show this help message, More: https://oneinstack.com
|
||||
--quiet, -q quiet operation
|
||||
--all Uninstall All
|
||||
--web Uninstall Nginx
|
||||
--mysql Uninstall MySQL/MariaDB
|
||||
--postgresql Uninstall PostgreSQL
|
||||
--mongodb Uninstall MongoDB
|
||||
--php Uninstall PHP (PATH: ${php_install_dir})
|
||||
--mphp_ver [53~81] Uninstall another PHP version (PATH: ${php_install_dir}\${mphp_ver})
|
||||
--allphp Uninstall all PHP
|
||||
--phpcache Uninstall PHP opcode cache
|
||||
--php_extensions [ext name] Uninstall PHP extensions, include zendguardloader,ioncube,
|
||||
sourceguardian,imagick,gmagick,fileinfo,imap,ldap,calendar,phalcon,
|
||||
yaf,yar,redis,mongodb,swoole,xdebug
|
||||
--pureftpd Uninstall PureFtpd
|
||||
--redis Uninstall Redis-server
|
||||
--phpmyadmin Uninstall phpMyAdmin
|
||||
--python Uninstall Python (PATH: ${python_install_dir})
|
||||
--node Uninstall Nodejs (PATH: ${nodejs_install_dir})
|
||||
"
|
||||
}
|
||||
|
||||
ARG_NUM=$#
|
||||
TEMP=`getopt -o hvVq --long help,version,quiet,all,web,mysql,postgresql,mongodb,php,mphp_ver:,allphp,phpcache,php_extensions:,pureftpd,redis,phpmyadmin,python,node -- "$@" 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
|
||||
;;
|
||||
-q|--quiet)
|
||||
quiet_flag=y
|
||||
uninstall_flag=y
|
||||
shift 1
|
||||
;;
|
||||
--all)
|
||||
all_flag=y
|
||||
web_flag=y
|
||||
mysql_flag=y
|
||||
postgresql_flag=y
|
||||
mongodb_flag=y
|
||||
allphp_flag=y
|
||||
nodejs_flag=y
|
||||
pureftpd_flag=y
|
||||
redis_flag=y
|
||||
phpmyadmin_flag=y
|
||||
python_flag=y
|
||||
shift 1
|
||||
;;
|
||||
--web)
|
||||
web_flag=y; shift 1
|
||||
;;
|
||||
--mysql)
|
||||
mysql_flag=y; shift 1
|
||||
;;
|
||||
--postgresql)
|
||||
postgresql_flag=y; shift 1
|
||||
;;
|
||||
--mongodb)
|
||||
mongodb_flag=y; shift 1
|
||||
;;
|
||||
--php)
|
||||
php_flag=y; shift 1
|
||||
;;
|
||||
--mphp_ver)
|
||||
mphp_ver=$2; mphp_flag=y; shift 2
|
||||
[[ ! "${mphp_ver}" =~ ^5[3-6]$|^7[0-4]$|^8[0-1]$ ]] && { echo "${CWARNING}mphp_ver input error! Please only input number 53~81${CEND}"; exit 1; }
|
||||
;;
|
||||
--allphp)
|
||||
allphp_flag=y; shift 1
|
||||
;;
|
||||
--phpcache)
|
||||
phpcache_flag=y; shift 1
|
||||
;;
|
||||
--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
|
||||
;;
|
||||
--node)
|
||||
nodejs_flag=y; shift 1
|
||||
;;
|
||||
--pureftpd)
|
||||
pureftpd_flag=y; shift 1
|
||||
;;
|
||||
--redis)
|
||||
redis_flag=y; shift 1
|
||||
;;
|
||||
--phpmyadmin)
|
||||
phpmyadmin_flag=y; shift 1
|
||||
;;
|
||||
--python)
|
||||
python_flag=y; shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
Uninstall_status() {
|
||||
if [ "${quiet_flag}" != 'y' ]; then
|
||||
while :; do echo
|
||||
read -e -p "Do you want to uninstall? [y/n]: " uninstall_flag
|
||||
if [[ ! ${uninstall_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
Print_Warn() {
|
||||
echo
|
||||
echo "${CWARNING}You will uninstall OneinStack, Please backup your configure files and DB data! ${CEND}"
|
||||
}
|
||||
|
||||
Print_web() {
|
||||
[ -d "${nginx_install_dir}" ] && echo ${nginx_install_dir}
|
||||
[ -e "/etc/services/nginx" ] && echo /etc/services/nginx
|
||||
[ -e "/lib/systemd/system/nginx.service" ] && echo /lib/systemd/system/nginx.service
|
||||
[ -e "/etc/logrotate.d/nginx" ] && echo /etc/logrotate.d/nginx
|
||||
}
|
||||
|
||||
Uninstall_Web() {
|
||||
[ -d "${nginx_install_dir}" ] && { killall nginx > /dev/null 2>&1; rm -rf ${nginx_install_dir} /etc/services/nginx /etc/logrotate.d/nginx; sed -i "s@${nginx_install_dir}/sbin:@@" /etc/profile; echo "${CMSG}Nginx uninstall completed! ${CEND}"; }
|
||||
[ -e "/lib/systemd/system/nginx.service" ] && { systemctl disable nginx > /dev/null 2>&1; rm -f /lib/systemd/system/nginx.service; }
|
||||
[ -e "${wwwroot_dir}" ] && /bin/mv ${wwwroot_dir}{,$(date +%Y%m%d%H)}
|
||||
sed -i 's@^website_name=.*@website_name=@' ./config/options.conf
|
||||
sed -i 's@^backup_content=.*@backup_content=@' ./config/options.conf
|
||||
}
|
||||
|
||||
Print_MySQL() {
|
||||
[ -e "${db_install_dir}" ] && echo ${db_install_dir}
|
||||
[ -e "/etc/init.d/mysqld" ] && echo /etc/init.d/mysqld
|
||||
[ -e "/etc/my.cnf" ] && echo /etc/my.cnf
|
||||
}
|
||||
|
||||
Print_PostgreSQL() {
|
||||
[ -e "${pgsql_install_dir}" ] && echo ${pgsql_install_dir}
|
||||
[ -e "/etc/services/postgresql" ] && echo /etc/services/postgresql
|
||||
[ -e "/lib/systemd/system/postgresql.service" ] && echo /lib/systemd/system/postgresql.service
|
||||
}
|
||||
|
||||
Print_MongoDB() {
|
||||
[ -e "${mongo_install_dir}" ] && echo ${mongo_install_dir}
|
||||
[ -e "/etc/services/mongod" ] && echo /etc/services/mongod
|
||||
[ -e "/lib/systemd/system/mongod.service" ] && echo /lib/systemd/system/mongod.service
|
||||
[ -e "/etc/mongod.conf" ] && echo /etc/mongod.conf
|
||||
}
|
||||
|
||||
Uninstall_MySQL() {
|
||||
# uninstall mysql,mariadb
|
||||
if [ -d "${db_install_dir}/support-files" ]; then
|
||||
service mysqld stop > /dev/null 2>&1
|
||||
rm -rf ${db_install_dir} /etc/init.d/mysqld /etc/my.cnf* /etc/ld.so.conf.d/*{mysql,mariadb}*.conf
|
||||
id -u mysql >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel mysql
|
||||
[ -e "${db_data_dir}" ] && /bin/mv ${db_data_dir}{,$(date +%Y%m%d%H)}
|
||||
sed -i 's@^dbrootpwd=.*@dbrootpwd=@' ./config/options.conf
|
||||
sed -i "s@${db_install_dir}/bin:@@" /etc/profile
|
||||
echo "${CMSG}MySQL uninstall completed! ${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_PostgreSQL() {
|
||||
# uninstall postgresql
|
||||
if [ -e "${pgsql_install_dir}/bin/psql" ]; then
|
||||
service postgresql stop > /dev/null 2>&1
|
||||
rm -rf ${pgsql_install_dir} /etc/services/postgresql
|
||||
[ -e "/lib/systemd/system/postgresql.service" ] && { systemctl disable postgresql > /dev/null 2>&1; rm -f /lib/systemd/system/postgresql.service; }
|
||||
[ -e "${php_install_dir}/etc/php.d/07-pgsql.ini" ] && rm -f ${php_install_dir}/etc/php.d/07-pgsql.ini
|
||||
id -u postgres >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel postgres
|
||||
[ -e "${pgsql_data_dir}" ] && /bin/mv ${pgsql_data_dir}{,$(date +%Y%m%d%H)}
|
||||
sed -i 's@^dbpostgrespwd=.*@dbpostgrespwd=@' ./config/options.conf
|
||||
sed -i "s@${pgsql_install_dir}/bin:@@" /etc/profile
|
||||
echo "${CMSG}PostgreSQL uninstall completed! ${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
Uninstall_MongoDB() {
|
||||
# uninstall mongodb
|
||||
if [ -e "${mongo_install_dir}/bin/mongo" ]; then
|
||||
service mongod stop > /dev/null 2>&1
|
||||
rm -rf ${mongo_install_dir} /etc/mongod.conf /etc/services/mongod /tmp/mongo*.sock
|
||||
[ -e "/lib/systemd/system/mongod.service" ] && { systemctl disable mongod > /dev/null 2>&1; rm -f /lib/systemd/system/mongod.service; }
|
||||
[ -e "${php_install_dir}/etc/php.d/07-mongo.ini" ] && rm -f ${php_install_dir}/etc/php.d/07-mongo.ini
|
||||
[ -e "${php_install_dir}/etc/php.d/07-mongodb.ini" ] && rm -f ${php_install_dir}/etc/php.d/07-mongodb.ini
|
||||
id -u mongod > /dev/null 2>&1 ; [ $? -eq 0 ] && userdel mongod
|
||||
[ -e "${mongo_data_dir}" ] && /bin/mv ${mongo_data_dir}{,$(date +%Y%m%d%H)}
|
||||
sed -i 's@^dbmongopwd=.*@dbmongopwd=@' ./config/options.conf
|
||||
sed -i "s@${mongo_install_dir}/bin:@@" /etc/profile
|
||||
echo "${CMSG}MongoDB uninstall completed! ${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
Print_PHP() {
|
||||
[ -e "${php_install_dir}" ] && echo ${php_install_dir}
|
||||
[ -e "/etc/services/php-fpm" ] && echo /etc/services/php-fpm
|
||||
[ -e "/lib/systemd/system/php-fpm.service" ] && echo /lib/systemd/system/php-fpm.service
|
||||
}
|
||||
|
||||
Print_MPHP() {
|
||||
[ -e "${php_install_dir}${mphp_ver}" ] && echo ${php_install_dir}${mphp_ver}
|
||||
[ -e "/etc/services/php${mphp_ver}-fpm" ] && echo /etc/services/php${mphp_ver}-fpm
|
||||
[ -e "/lib/systemd/system/php${mphp_ver}-fpm.service" ] && echo /lib/systemd/system/php${mphp_ver}-fpm.service
|
||||
}
|
||||
|
||||
Print_ALLPHP() {
|
||||
[ -e "${php_install_dir}" ] && echo ${php_install_dir}
|
||||
[ -e "/etc/services/php-fpm" ] && echo /etc/services/php-fpm
|
||||
[ -e "/lib/systemd/system/php-fpm.service" ] && echo /lib/systemd/system/php-fpm.service
|
||||
for php_ver in 53 54 55 56 70 71 72 73 74 80 81; do
|
||||
[ -e "${php_install_dir}${php_ver}" ] && echo ${php_install_dir}${php_ver}
|
||||
[ -e "/etc/services/php${php_ver}-fpm" ] && echo /etc/services/php${php_ver}-fpm
|
||||
[ -e "/lib/systemd/system/php${php_ver}-fpm.service" ] && echo /lib/systemd/system/php${php_ver}-fpm.service
|
||||
done
|
||||
[ -e "${imagick_install_dir}" ] && echo ${imagick_install_dir}
|
||||
[ -e "${gmagick_install_dir}" ] && echo ${gmagick_install_dir}
|
||||
[ -e "${curl_install_dir}" ] && echo ${curl_install_dir}
|
||||
[ -e "${freetype_install_dir}" ] && echo ${freetype_install_dir}
|
||||
}
|
||||
|
||||
Uninstall_PHP() {
|
||||
[ -e "/etc/services/php-fpm" ] && { service php-fpm stop > /dev/null 2>&1; rm -f /etc/services/php-fpm; }
|
||||
[ -e "/lib/systemd/system/php-fpm.service" ] && { systemctl stop php-fpm > /dev/null 2>&1; systemctl disable php-fpm > /dev/null 2>&1; rm -f /lib/systemd/system/php-fpm.service; }
|
||||
[ -e "${php_install_dir}" ] && { rm -rf ${php_install_dir}; echo "${CMSG}PHP uninstall completed! ${CEND}"; }
|
||||
sed -i "s@${php_install_dir}/bin:@@" /etc/profile
|
||||
}
|
||||
|
||||
Uninstall_MPHP() {
|
||||
[ -e "/etc/services/php${mphp_ver}-fpm" ] && { service php${mphp_ver}-fpm stop > /dev/null 2>&1; rm -f /etc/services/php${mphp_ver}-fpm; }
|
||||
[ -e "/lib/systemd/system/php${mphp_ver}-fpm.service" ] && { systemctl stop php${mphp_ver}-fpm > /dev/null 2>&1; systemctl disable php${mphp_ver}-fpm > /dev/null 2>&1; rm -f /lib/systemd/system/php${mphp_ver}-fpm.service; }
|
||||
[ -e "${php_install_dir}${mphp_ver}" ] && { rm -rf ${php_install_dir}${mphp_ver}; echo "${CMSG}PHP${mphp_ver} uninstall completed! ${CEND}"; }
|
||||
}
|
||||
|
||||
Uninstall_ALLPHP() {
|
||||
[ -e "/etc/services/php-fpm" ] && { service php-fpm stop > /dev/null 2>&1; rm -f /etc/services/php-fpm; }
|
||||
[ -e "/lib/systemd/system/php-fpm.service" ] && { systemctl stop php-fpm > /dev/null 2>&1; systemctl disable php-fpm > /dev/null 2>&1; rm -f /lib/systemd/system/php-fpm.service; }
|
||||
[ -e "${php_install_dir}" ] && { rm -rf ${php_install_dir}; echo "${CMSG}PHP uninstall completed! ${CEND}"; }
|
||||
sed -i "s@${php_install_dir}/bin:@@" /etc/profile
|
||||
for php_ver in 53 54 55 56 70 71 72 73 74 80 81; do
|
||||
[ -e "/etc/services/php${php_ver}-fpm" ] && { service php${php_ver}-fpm stop > /dev/null 2>&1; rm -f /etc/services/php${php_ver}-fpm; }
|
||||
[ -e "/lib/systemd/system/php${php_ver}-fpm.service" ] && { systemctl stop php${php_ver}-fpm > /dev/null 2>&1; systemctl disable php${php_ver}-fpm > /dev/null 2>&1; rm -f /lib/systemd/system/php${php_ver}-fpm.service; }
|
||||
[ -e "${php_install_dir}${php_ver}" ] && { rm -rf ${php_install_dir}${php_ver}; echo "${CMSG}PHP${php_ver} uninstall completed! ${CEND}"; }
|
||||
done
|
||||
[ -e "${imagick_install_dir}" ] && rm -rf ${imagick_install_dir}
|
||||
[ -e "${gmagick_install_dir}" ] && rm -rf ${gmagick_install_dir}
|
||||
[ -e "${curl_install_dir}" ] && rm -rf ${curl_install_dir}
|
||||
[ -e "${freetype_install_dir}" ] && rm -rf ${freetype_install_dir}
|
||||
}
|
||||
|
||||
Uninstall_PHPcache() {
|
||||
. modules/php-addons/zendopcache.sh
|
||||
. modules/php-addons/xcache.sh
|
||||
. modules/php-addons/apcu.sh
|
||||
. modules/php-addons/eaccelerator.sh
|
||||
Uninstall_ZendOPcache
|
||||
Uninstall_XCache
|
||||
Uninstall_APCU
|
||||
Uninstall_eAccelerator
|
||||
# reload php
|
||||
[ -e "${php_install_dir}/sbin/php-fpm" ] && { [ -e "/bin/systemctl" ] && systemctl reload php-fpm || service php-fpm reload; }
|
||||
[ -n "${mphp_ver}" -a -e "${php_install_dir}${mphp_ver}/sbin/php-fpm" ] && { [ -e "/bin/systemctl" ] && systemctl reload php${mphp_ver}-fpm || service php${mphp_ver}-fpm reload; }
|
||||
}
|
||||
|
||||
Uninstall_PHPext() {
|
||||
# ZendGuardLoader
|
||||
if [ "${pecl_zendguardloader}" == '1' ]; then
|
||||
. modules/php-addons/ZendGuardLoader.sh
|
||||
Uninstall_ZendGuardLoader
|
||||
fi
|
||||
|
||||
# ioncube
|
||||
if [ "${pecl_ioncube}" == '1' ]; then
|
||||
. modules/php-addons/ioncube.sh
|
||||
Uninstall_ionCube
|
||||
fi
|
||||
|
||||
# SourceGuardian
|
||||
if [ "${pecl_sourceguardian}" == '1' ]; then
|
||||
. modules/php-addons/sourceguardian.sh
|
||||
Uninstall_SourceGuardian
|
||||
fi
|
||||
|
||||
# imagick
|
||||
if [ "${pecl_imagick}" == '1' ]; then
|
||||
. modules/image/ImageMagick.sh
|
||||
Uninstall_ImageMagick
|
||||
Uninstall_pecl_imagick
|
||||
fi
|
||||
|
||||
# gmagick
|
||||
if [ "${pecl_gmagick}" == '1' ]; then
|
||||
. modules/image/GraphicsMagick.sh
|
||||
Uninstall_GraphicsMagick
|
||||
Uninstall_pecl_gmagick
|
||||
fi
|
||||
|
||||
# fileinfo
|
||||
if [ "${pecl_fileinfo}" == '1' ]; then
|
||||
. modules/php-addons/pecl_fileinfo.sh
|
||||
Uninstall_pecl_fileinfo
|
||||
fi
|
||||
|
||||
# imap
|
||||
if [ "${pecl_imap}" == '1' ]; then
|
||||
. modules/php-addons/pecl_imap.sh
|
||||
Uninstall_pecl_imap
|
||||
fi
|
||||
|
||||
# ldap
|
||||
if [ "${pecl_ldap}" == '1' ]; then
|
||||
. modules/php-addons/pecl_ldap.sh
|
||||
Uninstall_pecl_ldap
|
||||
fi
|
||||
|
||||
# calendar
|
||||
if [ "${pecl_calendar}" == '1' ]; then
|
||||
. modules/php-addons/pecl_calendar.sh
|
||||
Uninstall_pecl_calendar
|
||||
fi
|
||||
|
||||
# phalcon
|
||||
if [ "${pecl_phalcon}" == '1' ]; then
|
||||
. modules/php-addons/pecl_phalcon.sh
|
||||
Uninstall_pecl_phalcon
|
||||
fi
|
||||
|
||||
# yaf
|
||||
if [ "${pecl_yaf}" == '1' ]; then
|
||||
. modules/php-addons/pecl_yaf.sh
|
||||
Uninstall_pecl_yaf 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
|
||||
fi
|
||||
|
||||
# yar
|
||||
if [ "${pecl_yar}" == '1' ]; then
|
||||
. modules/php-addons/pecl_yar.sh
|
||||
Uninstall_pecl_yar 2>&1 | tee -a ${oneinstack_dir}/runtime/install.log
|
||||
fi
|
||||
|
||||
# pecl_redis
|
||||
if [ "${pecl_redis}" == '1' ]; then
|
||||
. modules/cache/redis.sh
|
||||
Uninstall_pecl_redis
|
||||
fi
|
||||
|
||||
# pecl_mongodb
|
||||
if [ "${pecl_mongodb}" == '1' ]; then
|
||||
. modules/php-addons/pecl_mongodb.sh
|
||||
Uninstall_pecl_mongodb
|
||||
fi
|
||||
|
||||
# swoole
|
||||
if [ "${pecl_swoole}" == '1' ]; then
|
||||
. modules/php-addons/pecl_swoole.sh
|
||||
Uninstall_pecl_swoole
|
||||
fi
|
||||
|
||||
# xdebug
|
||||
if [ "${pecl_xdebug}" == '1' ]; then
|
||||
. modules/php-addons/pecl_xdebug.sh
|
||||
Uninstall_pecl_xdebug
|
||||
fi
|
||||
|
||||
# reload php
|
||||
[ -e "${php_install_dir}/sbin/php-fpm" ] && { [ -e "/bin/systemctl" ] && systemctl reload php-fpm || service php-fpm reload; }
|
||||
[ -n "${mphp_ver}" -a -e "${php_install_dir}${mphp_ver}/sbin/php-fpm" ] && { [ -e "/bin/systemctl" ] && systemctl reload php${mphp_ver}-fpm || service php${mphp_ver}-fpm reload; }
|
||||
}
|
||||
|
||||
Menu_PHPext() {
|
||||
while :; do
|
||||
echo 'Please select uninstall PHP extensions:'
|
||||
echo -e "\t${CMSG} 0${CEND}. Do not uninstall"
|
||||
echo -e "\t${CMSG} 1${CEND}. Uninstall zendguardloader(PHP<=5.6)"
|
||||
echo -e "\t${CMSG} 2${CEND}. Uninstall ioncube"
|
||||
echo -e "\t${CMSG} 3${CEND}. Uninstall sourceguardian(PHP<=7.2)"
|
||||
echo -e "\t${CMSG} 4${CEND}. Uninstall imagick"
|
||||
echo -e "\t${CMSG} 5${CEND}. Uninstall gmagick"
|
||||
echo -e "\t${CMSG} 6${CEND}. Uninstall fileinfo"
|
||||
echo -e "\t${CMSG} 7${CEND}. Uninstall imap"
|
||||
echo -e "\t${CMSG} 8${CEND}. Uninstall ldap"
|
||||
echo -e "\t${CMSG} 9${CEND}. Uninstall phalcon(PHP>=5.5)"
|
||||
echo -e "\t${CMSG}10${CEND}. Uninstall redis"
|
||||
echo -e "\t${CMSG}11${CEND}. Uninstall mongodb"
|
||||
echo -e "\t${CMSG}12${CEND}. Uninstall swoole"
|
||||
echo -e "\t${CMSG}13${CEND}. Uninstall xdebug(PHP>=5.5)"
|
||||
read -e -p "Please input a number:(Default 0 press Enter) " phpext_option
|
||||
phpext_option=${phpext_option:-0}
|
||||
[ "${phpext_option}" == '0' ] && break
|
||||
array_phpext=(${phpext_option})
|
||||
array_all=(1 2 3 4 5 6 7 8 9 10 11 12 13)
|
||||
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 1 2 3 14 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_redis=1
|
||||
[ -n "`echo ${array_phpext[@]} | grep -w 11`" ] && pecl_mongodb=1
|
||||
[ -n "`echo ${array_phpext[@]} | grep -w 12`" ] && pecl_swoole=1
|
||||
[ -n "`echo ${array_phpext[@]} | grep -w 13`" ] && pecl_xdebug=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
Print_PureFtpd() {
|
||||
[ -e "${pureftpd_install_dir}" ] && echo ${pureftpd_install_dir}
|
||||
[ -e "/etc/services/pureftpd" ] && echo /etc/services/pureftpd
|
||||
[ -e "/lib/systemd/system/pureftpd.service" ] && echo /lib/systemd/system/pureftpd.service
|
||||
}
|
||||
|
||||
Uninstall_PureFtpd() {
|
||||
[ -e "${pureftpd_install_dir}" ] && { service pureftpd stop > /dev/null 2>&1; rm -rf ${pureftpd_install_dir} /etc/services/pureftpd; echo "${CMSG}Pureftpd uninstall completed! ${CEND}"; }
|
||||
[ -e "/lib/systemd/system/pureftpd.service" ] && { systemctl disable pureftpd > /dev/null 2>&1; rm -f /lib/systemd/system/pureftpd.service; }
|
||||
}
|
||||
|
||||
Print_Redis_server() {
|
||||
[ -e "${redis_install_dir}" ] && echo ${redis_install_dir}
|
||||
[ -e "/etc/services/redis-server" ] && echo /etc/services/redis-server
|
||||
[ -e "/lib/systemd/system/redis-server.service" ] && echo /lib/systemd/system/redis-server.service
|
||||
}
|
||||
|
||||
Uninstall_Redis_server() {
|
||||
[ -e "${redis_install_dir}" ] && { service redis-server stop > /dev/null 2>&1; rm -rf ${redis_install_dir} /etc/services/redis-server /usr/local/bin/redis-*; echo "${CMSG}Redis uninstall completed! ${CEND}"; }
|
||||
[ -e "/lib/systemd/system/redis-server.service" ] && { systemctl disable redis-server > /dev/null 2>&1; rm -f /lib/systemd/system/redis-server.service; }
|
||||
}
|
||||
|
||||
Print_phpMyAdmin() {
|
||||
[ -d "${wwwroot_dir}/default/phpMyAdmin" ] && echo ${wwwroot_dir}/default/phpMyAdmin
|
||||
}
|
||||
|
||||
Uninstall_phpMyAdmin() {
|
||||
[ -d "${wwwroot_dir}/default/phpMyAdmin" ] && rm -rf ${wwwroot_dir}/default/phpMyAdmin
|
||||
}
|
||||
|
||||
Print_openssl() {
|
||||
[ -d "${openssl_install_dir}" ] && echo ${openssl_install_dir}
|
||||
}
|
||||
|
||||
Uninstall_openssl() {
|
||||
[ -d "${openssl_install_dir}" ] && rm -rf ${openssl_install_dir}
|
||||
}
|
||||
|
||||
Print_Python() {
|
||||
[ -d "${python_install_dir}" ] && echo ${python_install_dir}
|
||||
}
|
||||
|
||||
Print_Nodejs() {
|
||||
[ -e "${nodejs_install_dir}" ] && echo ${nodejs_install_dir}
|
||||
[ -e "/etc/profile.d/nodejs.sh" ] && echo /etc/profile.d/nodejs.sh
|
||||
}
|
||||
|
||||
Menu() {
|
||||
while :; do
|
||||
printf "
|
||||
What Are You Doing?
|
||||
\t${CMSG} 0${CEND}. Uninstall All
|
||||
\t${CMSG} 1${CEND}. Uninstall Nginx
|
||||
\t${CMSG} 2${CEND}. Uninstall MySQL/MariaDB
|
||||
\t${CMSG} 3${CEND}. Uninstall PostgreSQL
|
||||
\t${CMSG} 4${CEND}. Uninstall MongoDB
|
||||
\t${CMSG} 5${CEND}. Uninstall all PHP
|
||||
\t${CMSG} 6${CEND}. Uninstall PHP opcode cache
|
||||
\t${CMSG} 7${CEND}. Uninstall PHP extensions
|
||||
\t${CMSG} 8${CEND}. Uninstall PureFtpd
|
||||
\t${CMSG} 9${CEND}. Uninstall Redis
|
||||
\t${CMSG}10${CEND}. Uninstall phpMyAdmin
|
||||
\t${CMSG}11${CEND}. Uninstall Python (PATH: ${python_install_dir})
|
||||
\t${CMSG}12${CEND}. Uninstall Nodejs (PATH: ${nodejs_install_dir})
|
||||
\t${CMSG} q${CEND}. Exit
|
||||
"
|
||||
echo
|
||||
read -e -p "Please input the correct option: " Number
|
||||
if [[ ! "${Number}" =~ ^[0-9,q]$|^1[0-2]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 0~12 and q${CEND}"
|
||||
else
|
||||
case "$Number" in
|
||||
0)
|
||||
Print_Warn
|
||||
Print_web
|
||||
Print_MySQL
|
||||
Print_PostgreSQL
|
||||
Print_MongoDB
|
||||
Print_ALLPHP
|
||||
Print_PureFtpd
|
||||
Print_Redis_server
|
||||
Print_openssl
|
||||
Print_phpMyAdmin
|
||||
Print_Python
|
||||
Print_Nodejs
|
||||
Uninstall_status
|
||||
if [ "${uninstall_flag}" == 'y' ]; then
|
||||
Uninstall_Web
|
||||
Uninstall_MySQL
|
||||
Uninstall_PostgreSQL
|
||||
Uninstall_MongoDB
|
||||
Uninstall_ALLPHP
|
||||
Uninstall_PureFtpd
|
||||
Uninstall_Redis_server
|
||||
Uninstall_openssl
|
||||
Uninstall_phpMyAdmin
|
||||
. modules/lang/python.sh; Uninstall_Python
|
||||
. modules/lang/nodejs.sh; Uninstall_Nodejs
|
||||
else
|
||||
exit
|
||||
fi
|
||||
;;
|
||||
1)
|
||||
Print_Warn
|
||||
Print_web
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_Web || exit
|
||||
;;
|
||||
2)
|
||||
Print_Warn
|
||||
Print_MySQL
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_MySQL || exit
|
||||
;;
|
||||
3)
|
||||
Print_Warn
|
||||
Print_PostgreSQL
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_PostgreSQL || exit
|
||||
;;
|
||||
4)
|
||||
Print_Warn
|
||||
Print_MongoDB
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_MongoDB || exit
|
||||
;;
|
||||
5)
|
||||
Print_ALLPHP
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_ALLPHP || exit
|
||||
;;
|
||||
6)
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_PHPcache || exit
|
||||
;;
|
||||
7)
|
||||
Menu_PHPext
|
||||
[ "${phpext_option}" != '0' ] && Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_PHPext || exit
|
||||
;;
|
||||
8)
|
||||
Print_PureFtpd
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_PureFtpd || exit
|
||||
;;
|
||||
9)
|
||||
Print_Redis_server
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_Redis_server || exit
|
||||
;;
|
||||
10)
|
||||
Print_phpMyAdmin
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && Uninstall_phpMyAdmin || exit
|
||||
;;
|
||||
11)
|
||||
Print_Python
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && { . modules/lang/python.sh; Uninstall_Python; } || exit
|
||||
;;
|
||||
12)
|
||||
Print_Nodejs
|
||||
Uninstall_status
|
||||
[ "${uninstall_flag}" == 'y' ] && { . modules/lang/nodejs.sh; Uninstall_Nodejs; } || exit
|
||||
;;
|
||||
q)
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ ${ARG_NUM} == 0 ]; then
|
||||
Menu
|
||||
else
|
||||
[ "${web_flag}" == 'y' ] && Print_web
|
||||
[ "${mysql_flag}" == 'y' ] && Print_MySQL
|
||||
[ "${postgresql_flag}" == 'y' ] && Print_PostgreSQL
|
||||
[ "${mongodb_flag}" == 'y' ] && Print_MongoDB
|
||||
if [ "${allphp_flag}" == 'y' ]; then
|
||||
Print_ALLPHP
|
||||
else
|
||||
[ "${php_flag}" == 'y' ] && Print_PHP
|
||||
[ "${mphp_flag}" == 'y' ] && [ "${phpcache_flag}" != 'y' ] && [ -z "${php_extensions}" ] && Print_MPHP
|
||||
fi
|
||||
[ "${pureftpd_flag}" == 'y' ] && Print_PureFtpd
|
||||
[ "${redis_flag}" == 'y' ] && Print_Redis_server
|
||||
[ "${phpmyadmin_flag}" == 'y' ] && Print_phpMyAdmin
|
||||
[ "${python_flag}" == 'y' ] && Print_Python
|
||||
[ "${nodejs_flag}" == 'y' ] && Print_Nodejs
|
||||
[ "${all_flag}" == 'y' ] && Print_openssl
|
||||
Uninstall_status
|
||||
if [ "${uninstall_flag}" == 'y' ]; then
|
||||
[ "${web_flag}" == 'y' ] && Uninstall_Web
|
||||
[ "${mysql_flag}" == 'y' ] && Uninstall_MySQL
|
||||
[ "${postgresql_flag}" == 'y' ] && Uninstall_PostgreSQL
|
||||
[ "${mongodb_flag}" == 'y' ] && Uninstall_MongoDB
|
||||
if [ "${allphp_flag}" == 'y' ]; then
|
||||
Uninstall_ALLPHP
|
||||
else
|
||||
[ "${php_flag}" == 'y' ] && Uninstall_PHP
|
||||
[ "${phpcache_flag}" == 'y' ] && Uninstall_PHPcache
|
||||
[ -n "${php_extensions}" ] && Uninstall_PHPext
|
||||
[ "${mphp_flag}" == 'y' ] && [ "${phpcache_flag}" != 'y' ] && [ -z "${php_extensions}" ] && Uninstall_MPHP
|
||||
[ "${mphp_flag}" == 'y' ] && [ "${phpcache_flag}" == 'y' ] && { php_install_dir=${php_install_dir}${mphp_ver}; Uninstall_PHPcache; }
|
||||
[ "${mphp_flag}" == 'y' ] && [ -n "${php_extensions}" ] && { php_install_dir=${php_install_dir}${mphp_ver}; Uninstall_PHPext; }
|
||||
fi
|
||||
[ "${pureftpd_flag}" == 'y' ] && Uninstall_PureFtpd
|
||||
[ "${redis_flag}" == 'y' ] && Uninstall_Redis_server
|
||||
[ "${phpmyadmin_flag}" == 'y' ] && Uninstall_phpMyAdmin
|
||||
[ "${python_flag}" == 'y' ] && { . modules/lang/python.sh; Uninstall_Python; }
|
||||
[ "${nodejs_flag}" == 'y' ] && { . modules/lang/nodejs.sh; Uninstall_Nodejs; }
|
||||
[ "${all_flag}" == 'y' ] && Uninstall_openssl
|
||||
fi
|
||||
fi
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
#!/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
|
||||
+780
@@ -0,0 +1,780 @@
|
||||
#!/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+ #
|
||||
# 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/options.conf
|
||||
. ./lib/color.sh
|
||||
. ./lib/check_dir.sh
|
||||
. ./lib/check_os.sh
|
||||
. ./lib/get_char.sh
|
||||
|
||||
Show_Help() {
|
||||
echo
|
||||
echo "Usage: $0 command ...[parameters]....
|
||||
--help, -h Show this help message
|
||||
--quiet, -q quiet operation
|
||||
--list, -l List Virtualhost
|
||||
--mphp_ver [74/80/81] Use another PHP version (PATH: /usr/local/php${mphp_ver})
|
||||
--proxy Use proxy
|
||||
--add Add Virtualhost
|
||||
--delete, --del Delete Virtualhost
|
||||
--httponly Use HTTP Only
|
||||
--selfsigned Use your own SSL Certificate and Key
|
||||
--letsencrypt Use Let's Encrypt to Create SSL Certificate and Key
|
||||
--dnsapi Use dns API to automatically issue Let's Encrypt Cert
|
||||
"
|
||||
}
|
||||
|
||||
ARG_NUM=$#
|
||||
TEMP=`getopt -o hql --long help,quiet,list,proxy,mphp_ver:,add,delete,del,httponly,selfsigned,letsencrypt,dnsapi -- "$@" 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
|
||||
;;
|
||||
-q|--quiet)
|
||||
quiet_flag=y; shift 1
|
||||
;;
|
||||
-l|--list)
|
||||
list_flag=y; shift 1
|
||||
;;
|
||||
--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}"; unset mphp_ver mphp_flag; }
|
||||
;;
|
||||
--proxy)
|
||||
proxy_flag=y; shift 1
|
||||
;;
|
||||
--add)
|
||||
add_flag=y; shift 1
|
||||
;;
|
||||
--delete|--del)
|
||||
delete_flag=y; shift 1
|
||||
;;
|
||||
--httponly)
|
||||
sslquiet_flag=y
|
||||
httponly_flag=y
|
||||
Domian_Mode=1
|
||||
shift 1
|
||||
;;
|
||||
--selfsigned)
|
||||
sslquiet_flag=y
|
||||
selfsigned_flag=y
|
||||
Domian_Mode=2
|
||||
shift 1
|
||||
;;
|
||||
--letsencrypt)
|
||||
sslquiet_flag=y
|
||||
letsencrypt_flag=y
|
||||
Domian_Mode=3
|
||||
shift 1
|
||||
;;
|
||||
--dnsapi)
|
||||
sslquiet_flag=y
|
||||
dnsapi_flag=y
|
||||
letsencrypt_flag=y
|
||||
shift 1
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "${CWARNING}ERROR: unknown argument! ${CEND}" && Show_Help && exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
Choose_ENV() {
|
||||
# Only Nginx is supported; PHP-FPM is the backend for PHP applications.
|
||||
NGX_FLAG=php
|
||||
}
|
||||
|
||||
Create_SSL() {
|
||||
if [ "${Domian_Mode}" == '2' ]; then
|
||||
printf "
|
||||
You are about to be asked to enter information that will be incorporated
|
||||
into your certificate request.
|
||||
What you are about to enter is what is called a Distinguished Name or a DN.
|
||||
There are quite a few fields but you can leave some blank
|
||||
For some fields there will be a default value,
|
||||
If you enter '.', the field will be left blank.
|
||||
"
|
||||
echo
|
||||
read -e -p "Country Name (2 letter code) [CN]: " SELFSIGNEDSSL_C
|
||||
SELFSIGNEDSSL_C=${SELFSIGNEDSSL_C:-CN}
|
||||
# shellcheck disable=SC2104
|
||||
[ ${#SELFSIGNEDSSL_C} != 2 ] && { echo "${CWARNING}input error, You must input 2 letter code country name${CEND}"; continue; }
|
||||
echo
|
||||
read -e -p "State or Province Name (full name) [Shanghai]: " SELFSIGNEDSSL_ST
|
||||
SELFSIGNEDSSL_ST=${SELFSIGNEDSSL_ST:-Shanghai}
|
||||
echo
|
||||
read -e -p "Locality Name (eg, city) [Shanghai]: " SELFSIGNEDSSL_L
|
||||
SELFSIGNEDSSL_L=${SELFSIGNEDSSL_L:-Shanghai}
|
||||
echo
|
||||
read -e -p "Organization Name (eg, company) [Example Inc.]: " SELFSIGNEDSSL_O
|
||||
SELFSIGNEDSSL_O=${SELFSIGNEDSSL_O:-"Example Inc."}
|
||||
echo
|
||||
read -e -p "Organizational Unit Name (eg, section) [IT Dept.]: " SELFSIGNEDSSL_OU
|
||||
SELFSIGNEDSSL_OU=${SELFSIGNEDSSL_OU:-"IT Dept."}
|
||||
|
||||
openssl req -utf8 -new -newkey rsa:2048 -sha256 -nodes -out ${PATH_SSL}/${domain}.csr -keyout ${PATH_SSL}/${domain}.key -subj "/C=${SELFSIGNEDSSL_C}/ST=${SELFSIGNEDSSL_ST}/L=${SELFSIGNEDSSL_L}/O=${SELFSIGNEDSSL_O}/OU=${SELFSIGNEDSSL_OU}/CN=${domain}" > /dev/null 2>&1
|
||||
openssl x509 -req -days 36500 -sha256 -in ${PATH_SSL}/${domain}.csr -signkey ${PATH_SSL}/${domain}.key -out ${PATH_SSL}/${domain}.crt > /dev/null 2>&1
|
||||
elif [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ]; then
|
||||
while :; do echo
|
||||
echo 'Please select domain cert key length.'
|
||||
echo "${CMSG}Enter one of 2048, 3072, 4096, 8192 will issue a RSA cert.${CEND}"
|
||||
echo "${CMSG}Enter one of ec-256, ec-384, ec-521 will issue a ECC cert.${CEND}"
|
||||
echo
|
||||
read -e -p "Please enter your cert key length (default 2048): " CERT_KEYLENGTH
|
||||
if [ "${CERT_KEYLENGTH}" == "" ]; then
|
||||
CERT_KEYLENGTH="2048"
|
||||
break
|
||||
elif [[ "${CERT_KEYLENGTH}" =~ ^2048$|^3072$|^4096$|^8192$|^ec-256$|^ec-384$|^ec-521$ ]]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error!${CEND}"
|
||||
fi
|
||||
done
|
||||
if [ ! -e ~/.acme.sh/ca/acme.zerossl.com/account.key ]; then
|
||||
while :; do echo
|
||||
read -e -p "Please enter your email: " EMAIL
|
||||
echo
|
||||
if [[ "${EMAIL}" =~ ^[A-Za-z0-9._-]+@[A-Za-z0-9._-]+\.[A-Za-z]{2,9}$ ]]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}input error!${CEND}"
|
||||
fi
|
||||
done
|
||||
~/.acme.sh/acme.sh --register-account -m ${EMAIL}
|
||||
fi
|
||||
if [ "${moredomain}" == "*.${domain}" -o "${dnsapi_flag}" == 'y' ]; then
|
||||
while :; do echo
|
||||
echo 'Please select DNS provider:'
|
||||
echo "${CMSG}dp${CEND},${CMSG}cx${CEND},${CMSG}ali${CEND},${CMSG}cf${CEND},${CMSG}aws${CEND},${CMSG}linode${CEND},${CMSG}he${CEND},${CMSG}namesilo${CEND},${CMSG}dgon${CEND},${CMSG}freedns${CEND},${CMSG}gd${CEND},${CMSG}namecom${CEND} and so on."
|
||||
echo "${CMSG}More: https://oneinstack.com/faq/letsencrypt${CEND}"
|
||||
read -e -p "Please enter your DNS provider: " DNS_PRO
|
||||
if [ -e ~/.acme.sh/dnsapi/dns_${DNS_PRO}.sh ]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}You DNS api mode is not supported${CEND}"
|
||||
fi
|
||||
done
|
||||
while :; do echo
|
||||
echo "Syntax: export Key1=Value1 ; export Key2=Value1"
|
||||
read -e -p "Please enter your dnsapi parameters: " DNS_PAR
|
||||
echo
|
||||
eval ${DNS_PAR}
|
||||
if [ $? == 0 ]; then
|
||||
break
|
||||
else
|
||||
echo "${CWARNING}Syntax error! PS: export Ali_Key=LTq ; export Ali_Secret=0q5E${CEND}"
|
||||
fi
|
||||
done
|
||||
[ "${moredomainame_flag}" == 'y' ] && moredomainame_D="$(for D in ${moredomainame}; do echo -d ${D}; done)"
|
||||
~/.acme.sh/acme.sh --force --issue -k ${CERT_KEYLENGTH} --dns dns_${DNS_PRO} -d ${domain} ${moredomainame_D}
|
||||
else
|
||||
if [ "${nginx_ssl_flag}" == 'y' ]; then
|
||||
[ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
|
||||
if [ -n "`ifconfig | grep inet6`" ]; then
|
||||
echo "server { listen 80; listen [::]:80; server_name ${domain}${moredomainame}; root ${vhostdir}; access_log off; }" > ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
else
|
||||
echo "server { listen 80; server_name ${domain}${moredomainame}; root ${vhostdir}; access_log off; }" > ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
fi
|
||||
${web_install_dir}/sbin/nginx -s reload
|
||||
fi
|
||||
|
||||
auth_file="`< /dev/urandom tr -dc A-Za-z0-9 | head -c8`".html
|
||||
auth_str='oneinstack'; echo ${auth_str} > ${vhostdir}/${auth_file}
|
||||
for D in ${domain} ${moredomainame}
|
||||
do
|
||||
curl_str=`curl --connect-timeout 30 -4 -s $D/${auth_file} 2>&1`
|
||||
[ "${curl_str}" != "${auth_str}" ] && { echo; echo "${CFAILURE}Let's Encrypt Verify error! DNS problem: NXDOMAIN looking up A for ${D}${CEND}"; }
|
||||
done
|
||||
rm -f ${vhostdir}/${auth_file}
|
||||
[ "${moredomainame_flag}" == 'y' ] && moredomainame_D="$(for D in ${moredomainame}; do echo -d ${D}; done)"
|
||||
~/.acme.sh/acme.sh --force --issue -k ${CERT_KEYLENGTH} -w ${vhostdir} -d ${domain} ${moredomainame_D}
|
||||
fi
|
||||
[ -e "${PATH_SSL}/${domain}.crt" ] && rm -f ${PATH_SSL}/${domain}.{crt,key}
|
||||
Nginx_cmd="/bin/systemctl restart nginx"
|
||||
Command="${Nginx_cmd}"
|
||||
if [ -s ~/.acme.sh/${domain}/fullchain.cer ] && [[ "${CERT_KEYLENGTH}" =~ ^2048$|^3072$|^4096$|^8192$ ]]; then
|
||||
~/.acme.sh/acme.sh --force --install-cert -d ${domain} --fullchain-file ${PATH_SSL}/${domain}.crt --key-file ${PATH_SSL}/${domain}.key --reloadcmd "${Command}" > /dev/null
|
||||
elif [ -s ~/.acme.sh/${domain}_ecc/fullchain.cer ] && [[ "${CERT_KEYLENGTH}" =~ ^ec-256$|^ec-384$|^ec-521$ ]]; then
|
||||
~/.acme.sh/acme.sh --force --install-cert --ecc -d ${domain} --fullchain-file ${PATH_SSL}/${domain}.crt --key-file ${PATH_SSL}/${domain}.key --reloadcmd "${Command}" > /dev/null
|
||||
else
|
||||
echo "${CFAILURE}Error: Create Let's Encrypt SSL Certificate failed! ${CEND}"
|
||||
[ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && rm -f ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
Print_SSL() {
|
||||
if [ "${Domian_Mode}" == '2' ]; then
|
||||
echo "$(printf "%-30s" "Self-signed SSL Certificate:")${CMSG}${PATH_SSL}/${domain}.crt${CEND}"
|
||||
echo "$(printf "%-30s" "SSL Private Key:")${CMSG}${PATH_SSL}/${domain}.key${CEND}"
|
||||
echo "$(printf "%-30s" "SSL CSR File:")${CMSG}${PATH_SSL}/${domain}.csr${CEND}"
|
||||
elif [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ]; then
|
||||
echo "$(printf "%-30s" "Let's Encrypt SSL Certificate:")${CMSG}${PATH_SSL}/${domain}.crt${CEND}"
|
||||
echo "$(printf "%-30s" "SSL Private Key:")${CMSG}${PATH_SSL}/${domain}.key${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
Input_Add_proxy() {
|
||||
while :; do echo
|
||||
read -e -p "Please input the correct proxy_pass: " Proxy_Pass
|
||||
if [ -z "$(echo $Proxy_Pass | grep -E '^http://|https://')" ]; then
|
||||
echo "${CFAILURE}input error! Please only input example http://192.168.1.1:8080${CEND}"
|
||||
else
|
||||
echo "proxy_pass=${Proxy_Pass}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
Input_Add_domain() {
|
||||
if [ "${sslquiet_flag}" != 'y' ]; then
|
||||
while :;do
|
||||
printf "
|
||||
What Are You Doing?
|
||||
\t${CMSG}1${CEND}. Use HTTP Only
|
||||
\t${CMSG}2${CEND}. Use your own SSL Certificate and Key
|
||||
\t${CMSG}3${CEND}. Use Let's Encrypt to Create SSL Certificate and Key
|
||||
\t${CMSG}q${CEND}. Exit
|
||||
"
|
||||
read -e -p "Please input the correct option: " Domian_Mode
|
||||
if [[ ! "${Domian_Mode}" =~ ^[1-3,q]$ ]]; then
|
||||
echo "${CFAILURE}input error! Please only input 1~3 and q${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
#Multiple_PHP
|
||||
if [ $(ls /dev/shm/php*-cgi.sock 2> /dev/null | wc -l) -ge 2 ]; then
|
||||
if [ "${mphp_flag}" != 'y' ]; then
|
||||
PHP_detail_ver=`${php_install_dir}/bin/php-config --version`
|
||||
PHP_main_ver=${PHP_detail_ver%.*}
|
||||
while :; do echo
|
||||
echo 'Please select a version of the PHP:'
|
||||
echo -e "\t${CMSG} 0${CEND}. PHP ${PHP_main_ver} (default)"
|
||||
[ -e "/dev/shm/php74-cgi.sock" ] && echo -e "\t${CMSG} 1${CEND}. PHP 7.4"
|
||||
[ -e "/dev/shm/php80-cgi.sock" ] && echo -e "\t${CMSG} 2${CEND}. PHP 8.0"
|
||||
[ -e "/dev/shm/php81-cgi.sock" ] && echo -e "\t${CMSG} 3${CEND}. PHP 8.1"
|
||||
read -e -p "Please input a number:(Default 0 press Enter) " php_option
|
||||
php_option=${php_option:-0}
|
||||
if [[ ! ${php_option} =~ ^[0-3]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input number 0~3${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
[ "${php_option}" == '1' ] && mphp_ver=74
|
||||
[ "${php_option}" == '2' ] && mphp_ver=80
|
||||
[ "${php_option}" == '3' ] && mphp_ver=81
|
||||
[ ! -e "/dev/shm/php${mphp_ver}-cgi.sock" ] && unset mphp_ver
|
||||
fi
|
||||
|
||||
case "${NGX_FLAG}" in
|
||||
"php")
|
||||
NGX_CONF=$(echo -e "location ~ [^/]\.php(/|$) {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n }")
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "${Domian_Mode}" == '3' -o "${dnsapi_flag}" == 'y' ] && [ ! -e ~/.acme.sh/acme.sh ]; then
|
||||
pushd ${oneinstack_dir}/src > /dev/null
|
||||
[ ! -e acme.sh-master.tar.gz ] && wget -qc http://mirrors.linuxeye.com/oneinstack/src/acme.sh-master.tar.gz
|
||||
tar xzf acme.sh-master.tar.gz
|
||||
pushd acme.sh-master > /dev/null
|
||||
./acme.sh --install > /dev/null 2>&1
|
||||
popd > /dev/null
|
||||
popd > /dev/null
|
||||
fi
|
||||
[ -e ~/.acme.sh/account.conf ] && sed -i '/^CERT_HOME=/d' ~/.acme.sh/account.conf
|
||||
if [[ "${Domian_Mode}" =~ ^[2-3]$ ]] || [ "${dnsapi_flag}" == 'y' ]; then
|
||||
if [ -e "${web_install_dir}/sbin/nginx" ]; then
|
||||
nginx_ssl_flag=y
|
||||
PATH_SSL=${web_install_dir}/conf/ssl
|
||||
[ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
|
||||
else
|
||||
nginx_ssl_flag=y
|
||||
PATH_SSL=${web_install_dir}/conf/ssl
|
||||
[ ! -d "${PATH_SSL}" ] && mkdir ${PATH_SSL}
|
||||
fi
|
||||
elif [ "${Domian_Mode}" == 'q' ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while :; do echo
|
||||
read -e -p "Please input domain(example: www.example.com): " domain
|
||||
if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
|
||||
echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ]; then
|
||||
[ -e "${web_install_dir}/conf/vhost/${domain}.conf" ] && echo -e "${domain} in the Nginx already exist! \nYou can delete ${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND} and re-create"
|
||||
exit
|
||||
else
|
||||
echo "domain=${domain}"
|
||||
fi
|
||||
if [[ -z ${proxy_flag} || "${proxy_flag}" != 'y' ]]; then
|
||||
while :; do echo
|
||||
echo "Please input the directory for the domain:${domain} :"
|
||||
read -e -p "(Default directory: ${wwwroot_dir}/${domain}): " vhostdir
|
||||
if [ -n "${vhostdir}" -a -z "$(echo ${vhostdir} | grep '^/')" ]; then
|
||||
echo "${CWARNING}input error! Press Enter to continue...${CEND}"
|
||||
else
|
||||
if [ -z "${vhostdir}" ]; then
|
||||
vhostdir="${wwwroot_dir}/${domain}"
|
||||
echo "Virtual Host Directory=${CMSG}${vhostdir}${CEND}"
|
||||
fi
|
||||
echo
|
||||
echo "Create Virtul Host directory......"
|
||||
mkdir -p ${vhostdir}
|
||||
echo "set permissions of Virtual Host directory......"
|
||||
chown -R ${run_user}:${run_group} ${vhostdir}
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
while :; do echo
|
||||
read -e -p "Do you want to add more domain name? [y/n]: " moredomainame_flag
|
||||
if [[ ! ${moredomainame_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "${moredomainame_flag}" == 'y' ]; then
|
||||
while :; do echo
|
||||
read -e -p "Type domainname or IP(example: example.com other.example.com): " moredomain
|
||||
if [ -z "$(echo ${moredomain} | grep '.*\..*')" ]; then
|
||||
echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
|
||||
else
|
||||
[ "${moredomain}" == "${domain}" ] && echo "${CWARNING}Domain name already exists! ${CND}" && continue
|
||||
echo domain list="$moredomain"
|
||||
moredomainame=" $moredomain"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -e "${web_install_dir}/sbin/nginx" ]; then
|
||||
while :; do echo
|
||||
read -e -p "Do you want to redirect from ${moredomain} to ${domain}? [y/n]: " redirect_flag
|
||||
if [[ ! ${redirect_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ "${redirect_flag}" == 'y' ] && Nginx_redirect="if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "${nginx_ssl_flag}" == 'y' ]; then
|
||||
while :; do echo
|
||||
read -e -p "Do you want to redirect all HTTP requests to HTTPS? [y/n]: " https_flag
|
||||
if [[ ! ${https_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "$(${web_install_dir}/sbin/nginx -V 2>&1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
|
||||
LISTENOPT="443 ssl http2"
|
||||
else
|
||||
LISTENOPT="443 ssl spdy"
|
||||
fi
|
||||
Create_SSL
|
||||
if [ -n "`ifconfig | grep inet6`" ]; then
|
||||
Nginx_conf=$(echo -e "listen 80;\n listen [::]:80;\n listen ${LISTENOPT};\n listen [::]:${LISTENOPT};\n ssl_certificate ${PATH_SSL}/${domain}.crt;\n ssl_certificate_key ${PATH_SSL}/${domain}.key;\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;\n ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;\n ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256;\n ssl_conf_command Options PrioritizeChaCha;\n ssl_prefer_server_ciphers on;\n ssl_session_timeout 10m;\n ssl_session_cache shared:SSL:10m;\n ssl_buffer_size 2k;\n add_header Strict-Transport-Security max-age=15768000;\n ssl_stapling on;\n ssl_stapling_verify on;\n")
|
||||
else
|
||||
Nginx_conf=$(echo -e "listen 80;\n listen ${LISTENOPT};\n ssl_certificate ${PATH_SSL}/${domain}.crt;\n ssl_certificate_key ${PATH_SSL}/${domain}.key;\n ssl_protocols TLSv1.2 TLSv1.3;\n ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;\n ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;\n ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256;\n ssl_conf_command Options PrioritizeChaCha;\n ssl_prefer_server_ciphers on;\n ssl_session_timeout 10m;\n ssl_session_cache shared:SSL:10m;\n ssl_buffer_size 2k;\n add_header Strict-Transport-Security max-age=15768000;\n ssl_stapling on;\n ssl_stapling_verify on;\n")
|
||||
fi
|
||||
else
|
||||
if [ -n "`ifconfig | grep inet6`" ]; then
|
||||
Nginx_conf=$(echo -e "listen 80;\n listen [::]:80;")
|
||||
else
|
||||
Nginx_conf=$(echo -e "listen 80;")
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
Nginx_anti_hotlinking() {
|
||||
while :; do echo
|
||||
read -e -p "Do you want to add hotlink protection? [y/n]: " anti_hotlinking_flag
|
||||
if [[ ! ${anti_hotlinking_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$(echo ${domain} | grep '.*\..*\..*')" ]; then
|
||||
domain_allow="*.${domain#*.} ${domain}"
|
||||
else
|
||||
domain_allow="*.${domain} ${domain}"
|
||||
fi
|
||||
|
||||
if [ "${anti_hotlinking_flag}" == 'y' ]; then
|
||||
if [ "${moredomainame_flag}" == 'y' -a "${moredomain}" != "*.${domain}" ]; then
|
||||
domain_allow_all=${domain_allow}${moredomainame}
|
||||
else
|
||||
domain_allow_all=${domain_allow}
|
||||
fi
|
||||
domain_allow_all=`echo ${domain_allow_all} | tr ' ' '\n' | awk '!a[$1]++' | xargs`
|
||||
anti_hotlinking=$(echo -e "location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {\n valid_referers none blocked ${domain_allow_all};\n if (\$invalid_referer) {\n return 403;\n }\n }")
|
||||
fi
|
||||
}
|
||||
|
||||
Nginx_rewrite() {
|
||||
[ ! -d "${web_install_dir}/conf/rewrite" ] && mkdir ${web_install_dir}/conf/rewrite
|
||||
while :; do echo
|
||||
read -e -p "Allow Rewrite rule? [y/n]: " rewrite_flag
|
||||
if [[ ! "${rewrite_flag}" =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "${rewrite_flag}" == 'n' ]; then
|
||||
rewrite="none"
|
||||
touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
|
||||
else
|
||||
echo
|
||||
echo "Please input the rewrite of programme :"
|
||||
echo "${CMSG}wordpress${CEND},${CMSG}opencart${CEND},${CMSG}magento2${CEND},${CMSG}drupal${CEND},${CMSG}joomla${CEND},${CMSG}codeigniter${CEND},${CMSG}laravel${CEND}"
|
||||
echo "${CMSG}thinkphp${CEND},${CMSG}pathinfo${CEND},${CMSG}discuz${CEND},${CMSG}typecho${CEND},${CMSG}ecshop${CEND},${CMSG}nextcloud${CEND},${CMSG}zblog${CEND},${CMSG}whmcs${CEND} rewrite was exist."
|
||||
read -e -p "(Default rewrite: other): " rewrite
|
||||
if [ "${rewrite}" == "" ]; then
|
||||
rewrite="other"
|
||||
fi
|
||||
echo "You choose rewrite=${CMSG}$rewrite${CEND}"
|
||||
[ "${NGX_FLAG}" == 'php' -a "${rewrite}" == "joomla" ] && NGX_CONF=$(echo -e "location ~ \\.php\$ {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n }")
|
||||
[ "${NGX_FLAG}" == 'php' ] && [[ "${rewrite}" =~ ^codeigniter$|^thinkphp$|^pathinfo$ ]] && NGX_CONF=$(echo -e "location ~ [^/]\.php(/|\$) {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n fastcgi_split_path_info ^(.+?\.php)(/.*)\$;\n set \$path_info \$fastcgi_path_info;\n fastcgi_param PATH_INFO \$path_info;\n try_files \$fastcgi_script_name =404; \n }")
|
||||
[ "${NGX_FLAG}" == 'php' -a "${rewrite}" == "typecho" ] && NGX_CONF=$(echo -e "location ~ .*\.php(\/.*)*\$ {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php${mphp_ver}-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n set \$path_info \"\";\n set \$real_script_name \$fastcgi_script_name;\n if (\$fastcgi_script_name ~ \"^(.+?\.php)(/.+)\$\") {\n set \$real_script_name \$1;\n set \$path_info \$2;\n }\n fastcgi_param SCRIPT_FILENAME \$document_root\$real_script_name;\n fastcgi_param SCRIPT_NAME \$real_script_name;\n fastcgi_param PATH_INFO \$path_info;\n }")
|
||||
if [[ ! "${rewrite}" =~ ^magento2$|^pathinfo$ ]]; then
|
||||
if [ -e "config/${rewrite}.conf" ]; then
|
||||
/bin/cp config/${rewrite}.conf ${web_install_dir}/conf/rewrite/${rewrite}.conf
|
||||
else
|
||||
touch "${web_install_dir}/conf/rewrite/${rewrite}.conf"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
Nginx_log() {
|
||||
while :; do echo
|
||||
read -e -p "Allow Nginx access_log? [y/n]: " access_flag
|
||||
if [[ ! "${access_flag}" =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "${access_flag}" == 'n' ]; then
|
||||
Nginx_log="access_log off;"
|
||||
else
|
||||
Nginx_log="access_log ${wwwlogs_dir}/${domain}_nginx.log combined;"
|
||||
echo "You access log file=${CMSG}${wwwlogs_dir}/${domain}_nginx.log${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
Create_nginx_phpfpm_conf() {
|
||||
[ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
|
||||
cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
|
||||
server {
|
||||
${Nginx_conf}
|
||||
server_name ${domain}${moredomainame};
|
||||
${Nginx_log}
|
||||
index index.html index.htm index.php;
|
||||
root ${vhostdir};
|
||||
${Nginx_redirect}
|
||||
include ${web_install_dir}/conf/rewrite/${rewrite}.conf;
|
||||
#error_page 404 /404.html;
|
||||
#error_page 502 /502.html;
|
||||
${anti_hotlinking}
|
||||
${NGX_CONF}
|
||||
|
||||
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
|
||||
expires 30d;
|
||||
access_log off;
|
||||
}
|
||||
location ~ .*\.(js|css)?$ {
|
||||
expires 7d;
|
||||
access_log off;
|
||||
}
|
||||
location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
|
||||
deny all;
|
||||
}
|
||||
location /.well-known {
|
||||
allow all;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
[ "${rewrite}" == 'pathinfo' ] && sed -i '/pathinfo.conf;$/d' ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
if [ "${rewrite}" == 'magento2' -a -e "config/${rewrite}.conf" ]; then
|
||||
/bin/cp config/${rewrite}.conf ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@/dev/shm/php-cgi.sock@/dev/shm/php${mphp_ver}-cgi.sock@g" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ set \$MAGE_ROOT.*;@ set \$MAGE_ROOT ${vhostdir};@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@ server_name ${domain}${moredomainame};@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ${Nginx_log}@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
if [ "${anti_hotlinking_flag}" == 'y' ]; then
|
||||
sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n return 403;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n rewrite ^/ http://www.linuxeye.com/403.html;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n if (\$invalid_referer) {@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n valid_referers none blocked ${domain_allow_all};@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)\$ {@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
fi
|
||||
|
||||
[ "${redirect_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
|
||||
if [ "${nginx_ssl_flag}" == 'y' ]; then
|
||||
sed -i "s@^ listen 80;@&\n listen ${LISTENOPT};@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_stapling_verify on;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_stapling on;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n add_header Strict-Transport-Security max-age=15768000;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_buffer_size 2k;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_session_cache shared:SSL:10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_session_timeout 10m;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_prefer_server_ciphers on;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_conf_command Options PrioritizeChaCha;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_conf_command Ciphersuites TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_protocols TLSv1.2 TLSv1.3;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_certificate_key ${PATH_SSL}/${domain}.key;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ server_name.*;@&\n ssl_certificate ${PATH_SSL}/${domain}.crt;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
|
||||
echo
|
||||
${web_install_dir}/sbin/nginx -t
|
||||
if [ $? == 0 ]; then
|
||||
echo "Reload Nginx......"
|
||||
${web_install_dir}/sbin/nginx -s reload
|
||||
else
|
||||
rm -f ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "
|
||||
#######################################################################
|
||||
# OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+ #
|
||||
# For more information please visit https://oneinstack.com #
|
||||
#######################################################################
|
||||
"
|
||||
echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
|
||||
echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
|
||||
echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
|
||||
[ "${rewrite_flag}" == 'y' -a "${rewrite}" != 'magento2' -a "${rewrite}" != 'pathinfo' ] && echo "$(printf "%-30s" "Rewrite rule:")${CMSG}${web_install_dir}/conf/rewrite/${rewrite}.conf${CEND}"
|
||||
Print_SSL
|
||||
}
|
||||
|
||||
Create_nginx_proxy_conf() {
|
||||
[ ! -d ${web_install_dir}/conf/vhost ] && mkdir ${web_install_dir}/conf/vhost
|
||||
cat > ${web_install_dir}/conf/vhost/${domain}.conf << EOF
|
||||
server {
|
||||
${Nginx_conf}
|
||||
server_name ${domain}${moredomainame};
|
||||
${Nginx_log}
|
||||
index index.html index.htm index.php;
|
||||
${Nginx_redirect}
|
||||
location / {
|
||||
proxy_pass ${Proxy_Pass};
|
||||
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-NginX-Proxy true;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade \$http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_max_temp_file_size 0;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
#error_page 502 /502.html;
|
||||
${anti_hotlinking}
|
||||
|
||||
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
|
||||
expires 30d;
|
||||
access_log off;
|
||||
}
|
||||
location ~ .*\.(js|css)?$ {
|
||||
expires 7d;
|
||||
access_log off;
|
||||
}
|
||||
location ~ /(\.user\.ini|\.ht|\.git|\.svn|\.project|LICENSE|README\.md) {
|
||||
deny all;
|
||||
}
|
||||
location /.well-known {
|
||||
allow all;
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
[ "${redirect_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$host != ${domain}) { return 301 \$scheme://${domain}\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
|
||||
if [ "${anti_hotlinking_flag}" == 'y' ]; then
|
||||
sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n return 403;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n rewrite ^/ http://www.linuxeye.com/403.html;@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n if (\$invalid_referer) {@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n valid_referers none blocked ${domain_allow_all};@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
sed -i "s@^ root.*;@&\n location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)\$ {@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
fi
|
||||
|
||||
[ "${https_flag}" == 'y' ] && sed -i "s@^ root.*;@&\n if (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
|
||||
echo
|
||||
${web_install_dir}/sbin/nginx -t
|
||||
if [ $? == 0 ]; then
|
||||
echo "Reload Nginx......"
|
||||
${web_install_dir}/sbin/nginx -s reload
|
||||
else
|
||||
rm -f ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
echo "Create virtualhost ... [${CFAILURE}FAILED${CEND}]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "
|
||||
#######################################################################
|
||||
# OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+ #
|
||||
# For more information please visit https://oneinstack.com #
|
||||
#######################################################################
|
||||
"
|
||||
echo "$(printf "%-30s" "Your domain:")${CMSG}${domain}${CEND}"
|
||||
echo "$(printf "%-30s" "Virtualhost conf:")${CMSG}${web_install_dir}/conf/vhost/${domain}.conf${CEND}"
|
||||
#echo "$(printf "%-30s" "Directory of:")${CMSG}${vhostdir}${CEND}"
|
||||
[ "${rewrite_flag}" == 'y' -a "${rewrite}" != 'magento2' -a "${rewrite}" != 'pathinfo' ] && echo "$(printf "%-30s" "Rewrite rule:")${CMSG}${web_install_dir}/conf/rewrite/${rewrite}.conf${CEND}"
|
||||
Print_SSL
|
||||
}
|
||||
|
||||
|
||||
Add_Vhost() {
|
||||
if [ -e "${web_install_dir}/sbin/nginx" ]; then
|
||||
Choose_ENV
|
||||
Input_Add_domain
|
||||
Nginx_anti_hotlinking
|
||||
if [ "${proxy_flag}" == "y" ]; then
|
||||
Input_Add_proxy
|
||||
Create_nginx_proxy_conf
|
||||
else
|
||||
Nginx_rewrite
|
||||
Nginx_log
|
||||
Create_nginx_phpfpm_conf
|
||||
fi
|
||||
else
|
||||
echo "Error! ${CFAILURE}Nginx${CEND} not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
Del_NGX_Vhost() {
|
||||
if [ -e "${web_install_dir}/sbin/nginx" ]; then
|
||||
[ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
|
||||
if [ -n "${Domain_List}" ]; then
|
||||
echo
|
||||
echo "Virtualhost list:"
|
||||
echo ${CMSG}${Domain_List}${CEND}
|
||||
while :; do echo
|
||||
read -e -p "Please input a domain you want to delete: " domain
|
||||
if [ -z "$(echo ${domain} | grep '.*\..*')" ]; then
|
||||
echo "${CWARNING}Your ${domain} is invalid! ${CEND}"
|
||||
else
|
||||
if [ -e "${web_install_dir}/conf/vhost/${domain}.conf" ]; then
|
||||
Directory=$(grep '^ root' ${web_install_dir}/conf/vhost/${domain}.conf | head -1 | awk -F'[ ;]' '{print $(NF-1)}')
|
||||
rm -f ${web_install_dir}/conf/vhost/${domain}.conf
|
||||
[ -e "${web_install_dir}/conf/ssl/${domain}.crt" ] && rm -f ${web_install_dir}/conf/ssl/${domain}.{crt,key}
|
||||
${web_install_dir}/sbin/nginx -s reload
|
||||
while :; do echo
|
||||
read -e -p "Do you want to delete Virtul Host directory? [y/n]: " Del_Vhost_wwwroot_flag
|
||||
if [[ ! ${Del_Vhost_wwwroot_flag} =~ ^[y,n]$ ]]; then
|
||||
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "${Del_Vhost_wwwroot_flag}" == 'y' ]; then
|
||||
if [ "${quiet_flag}" != 'y' ]; then
|
||||
echo "Press Ctrl+c to cancel or Press any key to continue..."
|
||||
char=$(get_char)
|
||||
fi
|
||||
rm -rf ${Directory}
|
||||
fi
|
||||
echo
|
||||
[ -d ~/.acme.sh/${domain} ] && ~/.acme.sh/acme.sh --force --remove -d ${domain} > /dev/null 2>&1
|
||||
[ -d ~/.acme.sh/${domain}_ecc ] && ~/.acme.sh/acme.sh --force --remove --ecc -d ${domain} > /dev/null 2>&1
|
||||
echo "${CMSG}Domain: ${domain} has been deleted.${CEND}"
|
||||
echo
|
||||
else
|
||||
echo "${CWARNING}Virtualhost: ${domain} was not exist! ${CEND}"
|
||||
fi
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "${CWARNING}Virtualhost was not exist! ${CEND}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
List_Vhost() {
|
||||
[ -d "${web_install_dir}/conf/vhost" ] && Domain_List=$(ls ${web_install_dir}/conf/vhost | sed "s@.conf@@g")
|
||||
if [ -n "${Domain_List}" ]; then
|
||||
echo
|
||||
echo "Virtualhost list:"
|
||||
for D in ${Domain_List}; do echo ${CMSG}${D}${CEND}; done
|
||||
else
|
||||
echo "${CWARNING}Virtualhost was not exist! ${CEND}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ ${ARG_NUM} == 0 ]; then
|
||||
Add_Vhost
|
||||
else
|
||||
[ "${add_flag}" == 'y' -o "${proxy_flag}" == 'y' -o "${sslquiet_flag}" == 'y' ] && Add_Vhost
|
||||
[ "${list_flag}" == 'y' ] && List_Vhost
|
||||
[ "${delete_flag}" == 'y' ] && Del_NGX_Vhost
|
||||
fi
|
||||
Reference in New Issue
Block a user