update comment

This commit is contained in:
Teddysun 2016-09-13 15:21:36 +09:00 committed by GitHub
parent 921ef5d7cc
commit 65d6bef5c5

View File

@ -21,6 +21,7 @@ echo
#Current folder
cur_dir=`pwd`
# Get public IP address
get_ip(){
local IP=$( ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1 )
@ -37,23 +38,55 @@ rootness(){
fi
}
# Check OS
checkos(){
if [ -f /etc/redhat-release ];then
OS='CentOS'
elif [ ! -z "`cat /etc/issue | grep bian`" ];then
OS='Debian'
elif [ ! -z "`cat /etc/issue | grep Ubuntu`" ];then
OS='Ubuntu'
#Check system
check_sys(){
local checkType=$1
local value=$2
local release=''
local systemPackage=''
if [[ -f /etc/redhat-release ]]; then
release="centos"
systemPackage="yum"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
systemPackage="apt"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
systemPackage="apt"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
systemPackage="yum"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
systemPackage="apt"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
systemPackage="apt"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
systemPackage="yum"
fi
if [[ ${checkType} == "sysRelease" ]]; then
if [ "$value" == "$release" ]; then
return 0
else
echo "Not support OS, Please reinstall OS and retry!"
exit 1
return 1
fi
elif [[ ${checkType} == "packageManager" ]]; then
if [ "$value" == "$systemPackage" ]; then
return 0
else
return 1
fi
fi
}
# Get version
getversion(){
if [[ -s /etc/redhat-release ]];then
if [[ -s /etc/redhat-release ]]; then
grep -oE "[0-9.]+" /etc/redhat-release
else
grep -oE "[0-9.]+" /etc/issue
@ -62,14 +95,18 @@ getversion(){
# CentOS version
centosversion(){
if check_sys sysRelease centos; then
local code=$1
local version="`getversion`"
local version="$(getversion)"
local main_ver=${version%%.*}
if [ $main_ver == $code ];then
if [ "$main_ver" == "$code" ]; then
return 0
else
return 1
fi
else
return 1
fi
}
# Disable selinux
@ -82,18 +119,23 @@ fi
# Pre-installation settings
pre_install(){
if check_sys packageManager yum || check_sys packageManager apt; then
# Not support CentOS 5
if centosversion 5; then
echo "Not support CentOS 5, please change OS to CentOS 6+/Debian 7+/Ubuntu 12+ and retry."
echo "Error: Not supported CentOS 5, please change to CentOS 6+/Debian 7+/Ubuntu 12+ and try again."
exit 1
fi
else
echo "Error: Your OS is not supported. please change OS to CentOS/Debian/Ubuntu and try again."
exit 1
fi
# Set ShadowsocksR config password
echo "Please input password for ShadowsocksR:"
read -p "(Default password: teddysun.com):" shadowsockspwd
[ -z "$shadowsockspwd" ] && shadowsockspwd="teddysun.com"
[ -z "${shadowsockspwd}" ] && shadowsockspwd="teddysun.com"
echo
echo "---------------------------"
echo "password = $shadowsockspwd"
echo "password = ${shadowsockspwd}"
echo "---------------------------"
echo
# Set ShadowsocksR config port
@ -101,13 +143,13 @@ pre_install(){
do
echo -e "Please input port for ShadowsocksR [1-65535]:"
read -p "(Default port: 8989):" shadowsocksport
[ -z "$shadowsocksport" ] && shadowsocksport="8989"
[ -z "${shadowsocksport}" ] && shadowsocksport="8989"
expr ${shadowsocksport} + 0 &>/dev/null
if [ $? -eq 0 ]; then
if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ]; then
echo
echo "---------------------------"
echo "port = $shadowsocksport"
echo "port = ${shadowsocksport}"
echo "---------------------------"
echo
break
@ -131,10 +173,10 @@ pre_install(){
echo "Press any key to start...or Press Ctrl+C to cancel"
char=`get_char`
# Install necessary dependencies
if [ "$OS" == 'CentOS' ]; then
if check_sys packageManager yum; then
yum install -y wget unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent
yum install -y m2crypto automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel
else
elif check_sys packageManager apt; then
apt-get -y update
apt-get -y install python python-dev python-pip python-m2crypto curl wget unzip gcc swig automake make perl cpio build-essential
fi
@ -145,7 +187,7 @@ pre_install(){
download_files(){
# Download libsodium file
if ! wget --no-check-certificate -O libsodium-1.0.11.tar.gz https://github.com/jedisct1/libsodium/releases/download/1.0.11/libsodium-1.0.11.tar.gz; then
echo "Failed to download libsodium file!"
echo "Failed to download libsodium-1.0.11.tar.gz!"
exit 1
fi
# Download ShadowsocksR file
@ -154,12 +196,12 @@ download_files(){
exit 1
fi
# Download ShadowsocksR chkconfig file
if [ "$OS" == 'CentOS' ]; then
if check_sys packageManager yum; then
if ! wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR -O /etc/init.d/shadowsocks; then
echo "Failed to download ShadowsocksR chkconfig file!"
exit 1
fi
else
elif check_sys packageManager apt; then
if ! wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR-debian -O /etc/init.d/shadowsocks; then
echo "Failed to download ShadowsocksR chkconfig file!"
exit 1
@ -234,8 +276,13 @@ EOF
install_ss(){
# Install libsodium
tar zxf libsodium-1.0.11.tar.gz
cd ${cur_dir}/libsodium-1.0.11
cd libsodium-1.0.11/
./configure && make && make install
if [ $? -ne 0 ]; then
echo "libsodium install failed!"
install_cleanup
exit 1
fi
echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
ldconfig
# Install ShadowsocksR
@ -245,10 +292,10 @@ install_ss(){
if [ -f /usr/local/shadowsocks/server.py ]; then
chmod +x /etc/init.d/shadowsocks
# Add run on system start up
if [ "$OS" == 'CentOS' ]; then
if check_sys packageManager yum; then
chkconfig --add shadowsocks
chkconfig shadowsocks on
else
elif check_sys packageManager apt; then
update-rc.d -f shadowsocks defaults
fi
# Run ShadowsocksR in the background
@ -293,18 +340,15 @@ uninstall_shadowsocks(){
printf "Are you sure uninstall ShadowsocksR? (y/n) "
printf "\n"
read -p "(Default: n):" answer
if [ -z ${answer} ]; then
answer="n"
fi
if [ "$answer" = "y" ]; then
[ -z ${answer} ] && answer="n"
if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
/etc/init.d/shadowsocks status > /dev/null 2>&1
if [ $? -eq 0 ]; then
/etc/init.d/shadowsocks stop
fi
checkos
if [ "$OS" == 'CentOS' ]; then
if check_sys packageManager yum; then
chkconfig --del shadowsocks
else
elif check_sys packageManager apt; then
update-rc.d -f shadowsocks remove
fi
rm -f /etc/shadowsocks.json
@ -313,20 +357,19 @@ uninstall_shadowsocks(){
rm -rf /usr/local/shadowsocks
echo "ShadowsocksR uninstall success!"
else
echo "uninstall cancelled, Nothing to do"
echo "uninstall cancelled, nothing to do..."
fi
}
# Install ShadowsocksR
install_shadowsocks(){
checkos
rootness
disable_selinux
pre_install
download_files
config_shadowsocks
install_ss
if [ "$OS" == 'CentOS' ]; then
if check_sys packageManager yum; then
firewall_set
fi
install_cleanup