Fixed issues #39

Signed-off-by: Teddysun <i@teddysun.com>
This commit is contained in:
Teddysun 2017-10-26 22:10:39 +09:00
parent 8809542183
commit 22582f5730
No known key found for this signature in database
GPG Key ID: 09BD4C080AD6C46D

View File

@ -9,6 +9,8 @@
# Intro: https://shadowsocks.be/10.html # Intro: https://shadowsocks.be/10.html
# #
cur_dir=`pwd`
[[ $EUID -ne 0 ]] && echo "Error: This script must be run as root!" && exit 1 [[ $EUID -ne 0 ]] && echo "Error: This script must be run as root!" && exit 1
clear clear
@ -20,24 +22,56 @@ echo "# Author: Teddysun <i@teddysun.com> #"
echo "#############################################################" echo "#############################################################"
echo echo
checkos(){ check_sys() {
if [[ -f /etc/redhat-release ]]; then local checkType=$1
OS="centos" local value=$2
local release=''
local systemPackage=''
if [ -f /etc/redhat-release ]; then
release="centos"
systemPackage="yum"
elif cat /etc/issue | grep -Eqi "debian"; then elif cat /etc/issue | grep -Eqi "debian"; then
OS="debian" release="debian"
systemPackage="apt"
elif cat /etc/issue | grep -Eqi "ubuntu"; then elif cat /etc/issue | grep -Eqi "ubuntu"; then
OS="ubuntu" release="ubuntu"
systemPackage="apt"
elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
OS="centos" release="centos"
systemPackage="yum"
elif cat /proc/version | grep -Eqi "debian"; then elif cat /proc/version | grep -Eqi "debian"; then
OS="debian" release="debian"
systemPackage="apt"
elif cat /proc/version | grep -Eqi "ubuntu"; then elif cat /proc/version | grep -Eqi "ubuntu"; then
OS="ubuntu" release="ubuntu"
systemPackage="apt"
elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
OS="centos" release="centos"
systemPackage="yum"
fi
if [ ${checkType} == "sysRelease" ]; then
if [ "$value" == "$release" ]; then
return 0
else
return 1
fi
elif [ ${checkType} == "packageManager" ]; then
if [ "$value" == "$systemPackage" ]; then
return 0
else
return 1
fi
fi
}
install_check() {
if check_sys packageManager yum || check_sys packageManager apt; then
return 0
else else
echo "Not supported OS, Please reinstall OS and try again." return 1
exit 1
fi fi
} }
@ -81,8 +115,14 @@ get_char(){
# Pre-installation settings # Pre-installation settings
pre_install(){ pre_install(){
if ! install_check; then
echo "Your OS is not supported to run it."
echo "Please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again."
exit 1
fi
# Set haproxy config port # Set haproxy config port
while : while true
do do
echo -e "Please enter a port for haproxy and Shadowsocks server [1-65535]" echo -e "Please enter a port for haproxy and Shadowsocks server [1-65535]"
read -p "(Default port: 8989):" haproxyport read -p "(Default port: 8989):" haproxyport
@ -169,29 +209,29 @@ EOF
install(){ install(){
# Install haproxy # Install haproxy
if [ "${OS}" == "centos" ]; then if check_sys packageManager yum; then
yum install -y haproxy yum install -y haproxy
else elif check_sys packageManager apt; then
apt-get -y update apt-get -y update
apt-get install -y haproxy apt-get install -y haproxy
fi fi
if [ -d /etc/haproxy ]; then if [ -d /etc/haproxy ]; then
echo "haproxy install successed." echo "haproxy install success."
echo "Config haproxy start..." echo "Config haproxy start..."
config_haproxy config_haproxy
echo "Config haproxy completed..." echo "Config haproxy completed..."
if [ "${OS}" == "centos" ]; then if check_sys packageManager yum; then
chkconfig --add haproxy chkconfig --add haproxy
chkconfig haproxy on chkconfig haproxy on
else elif check_sys packageManager apt; then
update-rc.d haproxy defaults update-rc.d haproxy defaults
fi fi
# Start haproxy # Start haproxy
/etc/init.d/haproxy start service haproxy start
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "haproxy start success..." echo "haproxy start success..."
else else
@ -205,7 +245,7 @@ install(){
sleep 3 sleep 3
# restart haproxy # restart haproxy
/etc/init.d/haproxy restart service haproxy restart
# Active Internet connections confirm # Active Internet connections confirm
netstat -nxtlp netstat -nxtlp
echo echo
@ -222,11 +262,10 @@ install(){
# Install haproxy # Install haproxy
install_haproxy(){ install_haproxy(){
checkos
disable_selinux disable_selinux
pre_install pre_install
install install
} }
# Initialization step # Initialization step
install_haproxy 2>&1 | tee ~/haproxy_for_shadowsocks.log install_haproxy 2>&1 | tee ${cur_dir}/haproxy_for_shadowsocks.log