Skip to content

Commit

Permalink
update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
teddysun committed Sep 17, 2016
1 parent 00979d4 commit 8c1bd08
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 79 deletions.
70 changes: 32 additions & 38 deletions shadowsocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ 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 )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
[ ! -z ${IP} ] && echo ${IP} || echo
}

# Make sure only root can run our script
rootness(){
if [[ $EUID -ne 0 ]]; then
Expand All @@ -38,6 +30,14 @@ rootness(){
fi
}

# Disable selinux
disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
}

#Check system
check_sys(){
local checkType=$1
Expand Down Expand Up @@ -109,12 +109,12 @@ centosversion(){
fi
}

# Disable selinux
disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
# 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 )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
[ ! -z ${IP} ] && echo ${IP} || echo
}

# Pre-installation settings
Expand Down Expand Up @@ -154,10 +154,10 @@ pre_install(){
echo
break
else
echo "Input error! Please input correct numbers."
echo "Input error, please input correct number"
fi
else
echo "Input error! Please input correct numbers."
echo "Input error, please input correct number"
fi
done
get_char(){
Expand All @@ -174,8 +174,7 @@ pre_install(){
char=`get_char`
#Install necessary dependencies
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 automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel
yum install -y unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel
elif check_sys packageManager apt; then
apt-get -y update
apt-get -y install python python-dev python-pip python-setuptools python-m2crypto curl wget unzip gcc swig automake make perl cpio build-essential
Expand All @@ -195,7 +194,7 @@ download_files(){
echo "Failed to download shadowsocks python file!"
exit 1
fi
# Download Shadowsocks chkconfig file
# Download Shadowsocks init script
if check_sys packageManager yum; then
if ! wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks -O /etc/init.d/shadowsocks; then
echo "Failed to download shadowsocks chkconfig file!"
Expand Down Expand Up @@ -225,7 +224,7 @@ config_shadowsocks(){
EOF
}

# firewall set
# Firewall set
firewall_set(){
echo "firewall set start..."
if centosversion 6; then
Expand All @@ -245,14 +244,14 @@ firewall_set(){
fi
elif centosversion 7; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ];then
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
firewall-cmd --reload
else
echo "Firewalld looks like not running, try to start..."
systemctl start firewalld
if [ $? -eq 0 ];then
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
firewall-cmd --reload
Expand All @@ -265,10 +264,10 @@ firewall_set(){
}

# Install Shadowsocks
install_ss(){
install(){
# Install libsodium
tar zxf libsodium-1.0.11.tar.gz
cd libsodium-1.0.11/
cd libsodium-1.0.11
./configure && make && make install
if [ $? -ne 0 ]; then
echo "libsodium install failed!"
Expand All @@ -291,21 +290,20 @@ install_ss(){

if [ -f /usr/bin/ssserver ] || [ -f /usr/local/bin/ssserver ]; then
chmod +x /etc/init.d/shadowsocks
# Add run on system start up
if check_sys packageManager yum; then
chkconfig --add shadowsocks
chkconfig shadowsocks on
elif check_sys packageManager apt; then
update-rc.d -f shadowsocks defaults
fi
# Run shadowsocks in the background
/etc/init.d/shadowsocks start
else
echo
echo "Shadowsocks install failed! please visit https://teddysun.com/342.html and contact."
install_cleanup
exit 1
fi

clear
echo
echo "Congratulations, shadowsocks server install completed!"
Expand All @@ -324,10 +322,7 @@ install_ss(){
# Install cleanup
install_cleanup(){
cd ${cur_dir}
rm -f shadowsocks-master.zip
rm -rf shadowsocks-master
rm -f libsodium-1.0.11.tar.gz
rm -rf libsodium-1.0.11
rm -rf shadowsocks-master.zip shadowsocks-master libsodium-1.0.11.tar.gz libsodium-1.0.11
}

# Uninstall Shadowsocks
Expand Down Expand Up @@ -356,7 +351,9 @@ uninstall_shadowsocks(){
fi
echo "Shadowsocks uninstall success!"
else
echo
echo "uninstall cancelled, nothing to do..."
echo
fi
}

Expand All @@ -370,22 +367,19 @@ install_shadowsocks(){
if check_sys packageManager yum; then
firewall_set
fi
install_ss
install
install_cleanup
}

# Initialization step
action=$1
[ -z $1 ] && action=install
case "$action" in
install)
install_shadowsocks
;;
uninstall)
uninstall_shadowsocks
install|uninstall)
${action}_shadowsocks
;;
*)
echo "Arguments error! [${action} ]"
*)
echo "Arguments error! [${action}]"
echo "Usage: `basename $0` {install|uninstall}"
;;
esac
76 changes: 35 additions & 41 deletions shadowsocksR.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ 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 )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
[ ! -z ${IP} ] && echo ${IP} || echo
}

# Make sure only root can run our script
rootness(){
if [[ $EUID -ne 0 ]]; then
echo "Error:This script must be run as root!" 1>&2
echo "Error: This script must be run as root!" 1>&2
exit 1
fi
}

# Disable selinux
disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
}

#Check system
check_sys(){
local checkType=$1
Expand Down Expand Up @@ -109,12 +109,12 @@ centosversion(){
fi
}

# Disable selinux
disable_selinux(){
if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
fi
# 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 )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
[ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
[ ! -z ${IP} ] && echo ${IP} || echo
}

# Pre-installation settings
Expand Down Expand Up @@ -154,10 +154,10 @@ pre_install(){
echo
break
else
echo "Input error! Please input correct number."
echo "Input error, please input correct number"
fi
else
echo "Input error! Please input correct number."
echo "Input error, please input correct number"
fi
done
get_char(){
Expand All @@ -174,8 +174,7 @@ pre_install(){
char=`get_char`
# Install necessary dependencies
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
yum install -y unzip openssl-devel gcc swig python python-devel python-setuptools autoconf libtool libevent automake make curl curl-devel zlib-devel perl perl-devel cpio expat-devel gettext-devel
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
Expand All @@ -195,7 +194,7 @@ download_files(){
echo "Failed to download ShadowsocksR file!"
exit 1
fi
# Download ShadowsocksR chkconfig file
# Download ShadowsocksR init script
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!"
Expand All @@ -209,7 +208,7 @@ download_files(){
fi
}

# firewall set
# Firewall set
firewall_set(){
echo "firewall set start..."
if centosversion 6; then
Expand All @@ -229,14 +228,14 @@ firewall_set(){
fi
elif centosversion 7; then
systemctl status firewalld > /dev/null 2>&1
if [ $? -eq 0 ];then
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
firewall-cmd --reload
else
echo "Firewalld looks like not running, try to start..."
systemctl start firewalld
if [ $? -eq 0 ];then
if [ $? -eq 0 ]; then
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
firewall-cmd --reload
Expand Down Expand Up @@ -273,10 +272,10 @@ EOF
}

# Install ShadowsocksR
install_ss(){
install(){
# Install libsodium
tar zxf libsodium-1.0.11.tar.gz
cd libsodium-1.0.11/
cd libsodium-1.0.11
./configure && make && make install
if [ $? -ne 0 ]; then
echo "libsodium install failed!"
Expand All @@ -291,15 +290,14 @@ install_ss(){
mv shadowsocks-manyuser/shadowsocks /usr/local/
if [ -f /usr/local/shadowsocks/server.py ]; then
chmod +x /etc/init.d/shadowsocks
# Add run on system start up
if check_sys packageManager yum; then
chkconfig --add shadowsocks
chkconfig shadowsocks on
elif check_sys packageManager apt; then
update-rc.d -f shadowsocks defaults
fi
# Run ShadowsocksR in the background
/etc/init.d/shadowsocks start

clear
echo
echo "Congratulations, ShadowsocksR install completed!"
Expand All @@ -319,7 +317,7 @@ install_ss(){
echo "Enjoy it!"
echo
else
echo "Shadowsocks install failed! Please Email to Teddysun <[email protected]> and contact."
echo "ShadowsocksR install failed, please Email to Teddysun <[email protected]> and contact"
install_cleanup
exit 1
fi
Expand All @@ -328,16 +326,13 @@ install_ss(){
# Install cleanup
install_cleanup(){
cd ${cur_dir}
rm -f manyuser.zip
rm -rf shadowsocks-manyuser
rm -f libsodium-1.0.11.tar.gz
rm -rf libsodium-1.0.11
rm -rf manyuser.zip shadowsocks-manyuser libsodium-1.0.11.tar.gz libsodium-1.0.11
}


# Uninstall ShadowsocksR
uninstall_shadowsocks(){
printf "Are you sure uninstall ShadowsocksR? (y/n) "
printf "Are you sure uninstall ShadowsocksR? (y/n)"
printf "\n"
read -p "(Default: n):" answer
[ -z ${answer} ] && answer="n"
Expand All @@ -357,7 +352,9 @@ uninstall_shadowsocks(){
rm -rf /usr/local/shadowsocks
echo "ShadowsocksR uninstall success!"
else
echo
echo "uninstall cancelled, nothing to do..."
echo
fi
}

Expand All @@ -368,7 +365,7 @@ install_shadowsocks(){
pre_install
download_files
config_shadowsocks
install_ss
install
if check_sys packageManager yum; then
firewall_set
fi
Expand All @@ -379,14 +376,11 @@ install_shadowsocks(){
action=$1
[ -z $1 ] && action=install
case "$action" in
install)
install_shadowsocks
;;
uninstall)
uninstall_shadowsocks
install|uninstall)
${action}_shadowsocks
;;
*)
echo "Arguments error! [${action} ]"
*)
echo "Arguments error! [${action}]"
echo "Usage: `basename $0` {install|uninstall}"
;;
esac

0 comments on commit 8c1bd08

Please sign in to comment.