diff --git a/shadowsocks-go.sh b/shadowsocks-go.sh index 65a9348..e2072f4 100644 --- a/shadowsocks-go.sh +++ b/shadowsocks-go.sh @@ -168,7 +168,7 @@ pre_install(){ echo -e "Please input port for shadowsocks-go [1-65535]:" read -p "(Default port: 8989):" shadowsocksport [ -z "${shadowsocksport}" ] && shadowsocksport="8989" - expr ${shadowsocksport} + 0 &>/dev/null + expr ${shadowsocksport} + 1 &>/dev/null if [ $? -eq 0 ]; then if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ]; then echo @@ -195,7 +195,7 @@ pre_install(){ done read -p "Which cipher you'd select(Default: ${ciphers[0]}):" pick [ -z "$pick" ] && pick=1 - expr ${pick} + 0 &>/dev/null + expr ${pick} + 1 &>/dev/null if [ $? -ne 0 ]; then echo -e "[${red}Error${plain}] Input error, please input a number" continue diff --git a/shadowsocks-libev-debian.sh b/shadowsocks-libev-debian.sh index a5e36be..2b19d20 100644 --- a/shadowsocks-libev-debian.sh +++ b/shadowsocks-libev-debian.sh @@ -16,15 +16,35 @@ libsodium_file="libsodium-1.0.13" libsodium_url="https://github.com/jedisct1/libsodium/releases/download/1.0.13/libsodium-1.0.13.tar.gz" mbedtls_file="mbedtls-2.5.1" -mbedtls_url="https://tls.mbed.org/download/mbedtls-2.5.1-gpl.tgz" +mbedtls_url="http://dl.teddysun.com/files/mbedtls-2.5.1-gpl.tgz" + +# Stream Ciphers +ciphers=( +aes-256-gcm +aes-192-gcm +aes-128-gcm +aes-256-ctr +aes-192-ctr +aes-128-ctr +aes-256-cfb +aes-192-cfb +aes-128-cfb +camellia-128-cfb +camellia-192-cfb +camellia-256-cfb +chacha20-ietf-poly1305 +chacha20-ietf +chacha20 +rc4-md5 +) +# Color +red='\033[0;31m' +green='\033[0;32m' +yellow='\033[0;33m' +plain='\033[0m' # 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 - exit 1 - fi -} +[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1 # Disable selinux disable_selinux(){ @@ -174,7 +194,7 @@ debianversion(){ pre_install(){ # Check OS system if ! check_sys packageManager apt; then - echo "Error: Your OS is not supported to run it! Please change OS to Debian/Ubuntu and try again." + echo -e "[${red}Error${plain}] Your OS is not supported to run it, please change OS to Debian/Ubuntu and try again." exit 1 fi @@ -182,13 +202,12 @@ pre_install(){ check_version status=$? if [ ${status} -eq 0 ]; then - echo "Latest version ${shadowsocks_libev_ver} has been installed, nothing to do..." - echo + echo -e "[${green}Info${plain}] Latest version ${green}${shadowsocks_libev_ver}${plain} has already been installed, nothing to do..." exit 0 elif [ ${status} -eq 1 ]; then - echo "Installed version: ${installed_ver}" - echo "Latest version: ${latest_ver}" - echo "Upgrade shadowsocks libev to latest version..." + echo -e "Installed version: ${red}${installed_ver}${plain}" + echo -e "Latest version: ${red}${latest_ver}${plain}" + echo -e "[${green}Info${plain}] Upgrade shadowsocks libev to latest version..." ps -ef | grep -v grep | grep -i "ss-server" > /dev/null 2>&1 if [ $? -eq 0 ]; then /etc/init.d/shadowsocks stop @@ -196,11 +215,11 @@ pre_install(){ elif [ ${status} -eq 2 ]; then print_info get_latest_version - echo "Latest version: ${shadowsocks_libev_ver}" + echo -e "[${green}Info${plain}] Latest version: ${green}${shadowsocks_libev_ver}${plain}" echo fi - #Set shadowsocks-libev config password + # Set shadowsocks-libev config password echo "Please input password for shadowsocks-libev:" read -p "(Default password: teddysun.com):" shadowsockspwd [ -z "${shadowsockspwd}" ] && shadowsockspwd="teddysun.com" @@ -210,13 +229,13 @@ pre_install(){ echo "---------------------------" echo - #Set shadowsocks-libev config port + # Set shadowsocks-libev config port while true do echo -e "Please input port for shadowsocks-libev [1-65535]:" read -p "(Default port: 8989):" shadowsocksport [ -z "$shadowsocksport" ] && shadowsocksport="8989" - expr ${shadowsocksport} + 0 &>/dev/null + expr ${shadowsocksport} + 1 &>/dev/null if [ $? -eq 0 ]; then if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ]; then echo @@ -226,13 +245,41 @@ pre_install(){ echo break else - echo "Input error, please input correct number" + echo -e "[${red}Error${plain}] Input error, please input a number between 1 and 65535" fi else - echo "Input error, please input correct numbers" + echo -e "[${red}Error${plain}] Input error, please input a number between 1 and 65535" fi done + # Set shadowsocks config stream ciphers + while true + do + echo -e "Please select stream cipher for shadowsocks-libev:" + for ((i=1;i<=${#ciphers[@]};i++ )); do + hint="${ciphers[$i-1]}" + echo -e "${green}${i}${plain}) ${hint}" + done + read -p "Which cipher you'd select(Default: ${ciphers[0]}):" pick + [ -z "$pick" ] && pick=1 + expr ${pick} + 1 &>/dev/null + if [ $? -ne 0 ]; then + echo -e "[${red}Error${plain}] Input error, please input a number" + continue + fi + if [[ "$pick" -lt 1 || "$pick" -gt ${#ciphers[@]} ]]; then + echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#ciphers[@]}" + continue + fi + shadowsockscipher=${ciphers[$pick-1]} + echo + echo "---------------------------" + echo "cipher = ${shadowsockscipher}" + echo "---------------------------" + echo + break + done + echo echo "Press any key to start...or press Ctrl+C to cancel" char=`get_char` @@ -251,14 +298,17 @@ pre_install(){ } download() { - local filename=$(basename $1) - if [ -f ${1} ]; then - echo "${filename} [found]" + local filename=${1} + local cur_dir=`pwd` + if [ -s ${filename} ]; then + echo -e "[${green}Info${plain}] ${filename} [found]" else - echo "${filename} not found, download now..." - wget --no-check-certificate -c -t3 -T60 -O ${1} ${2} - if [ $? -ne 0 ]; then - echo "Error: Download ${filename} failed." + echo -e "[${green}Info${plain}] ${filename} not found, download now..." + wget --no-check-certificate -cq -t3 -T3 -O ${1} ${2} + if [ $? -eq 0 ]; then + echo -e "[${green}Info${plain}] ${filename} download completed..." + else + echo -e "[${red}Error${plain}] Failed to download ${filename}, please download it to ${cur_dir} directory manually and try again." exit 1 fi fi @@ -281,11 +331,11 @@ install_libsodium() { cd ${libsodium_file} ./configure --prefix=/usr && make && make install if [ $? -ne 0 ]; then - echo "Error: ${libsodium_file} install failed." + echo -e "[${red}Error${plain}] ${libsodium_file} install failed." exit 1 fi else - echo "Info: ${libsodium_file} already installed." + echo -e "[${green}Info${plain}] ${libsodium_file} already installed." fi } @@ -296,8 +346,12 @@ install_mbedtls() { cd ${mbedtls_file} make SHARED=1 CFLAGS=-fPIC make DESTDIR=/usr install + if [ $? -ne 0 ]; then + echo -e "[${red}Error${plain}] ${mbedtls_file} install failed." + exit 1 + fi else - echo "Info: ${mbedtls_file} already installed." + echo -e "[${green}Info${plain}] ${mbedtls_file} already installed." fi } @@ -319,7 +373,7 @@ config_shadowsocks(){ "local_port":1080, "password":"${shadowsockspwd}", "timeout":600, - "method":"aes-256-cfb" + "method":"${shadowsockscipher}" } EOF } @@ -330,7 +384,6 @@ install_shadowsocks(){ install_mbedtls ldconfig - cd ${cur_dir} tar zxf ${shadowsocks_libev_ver}.tar.gz cd ${shadowsocks_libev_ver} @@ -339,17 +392,16 @@ install_shadowsocks(){ if [ $? -eq 0 ]; then chmod +x /etc/init.d/shadowsocks update-rc.d -f shadowsocks defaults - ldconfig - # Run shadowsocks in the background + # Start shadowsocks /etc/init.d/shadowsocks start if [ $? -eq 0 ]; then - echo "Shadowsocks-libev start success!" + echo -e "[${green}Info${plain}] Shadowsocks-libev start success!" else - echo "Shadowsocks-libev start failure!" + echo -e "[${yellow}Warning${plain}] Shadowsocks-libev start failure!" fi else echo - echo "Shadowsocks-libev install failed! Please visit https://teddysun.com/358.html and contact." + echo -e "[${red}Error${plain}] Shadowsocks-libev install failed. please visit https://teddysun.com/358.html and contact." exit 1 fi @@ -360,13 +412,11 @@ install_shadowsocks(){ clear echo - echo "Congratulations, Shadowsocks-libev install completed!" - echo -e "Your Server IP: \033[41;37m $(get_ip) \033[0m" - echo -e "Your Server Port: \033[41;37m ${shadowsocksport} \033[0m" - echo -e "Your Password: \033[41;37m ${shadowsockspwd} \033[0m" - echo -e "Your Local IP: \033[41;37m 127.0.0.1 \033[0m" - echo -e "Your Local Port: \033[41;37m 1080 \033[0m" - echo -e "Your Encryption Method: \033[41;37m aes-256-cfb \033[0m" + echo -e "Congratulations, Shadowsocks-libev server install completed!" + echo -e "Your Server IP : \033[41;37m $(get_ip) \033[0m" + echo -e "Your Server Port : \033[41;37m ${shadowsocksport} \033[0m" + echo -e "Your Password : \033[41;37m ${shadowsockspwd} \033[0m" + echo -e "Your Encryption Method: \033[41;37m ${shadowsockscipher} \033[0m" echo echo "Welcome to visit:https://teddysun.com/358.html" echo "Enjoy it!" @@ -375,7 +425,6 @@ install_shadowsocks(){ # Install Shadowsocks-libev install_shadowsocks_libev(){ - rootness disable_selinux pre_install download_files diff --git a/shadowsocks-libev.sh b/shadowsocks-libev.sh index 937ddcd..63e5c47 100644 --- a/shadowsocks-libev.sh +++ b/shadowsocks-libev.sh @@ -16,15 +16,35 @@ libsodium_file="libsodium-1.0.13" libsodium_url="https://github.com/jedisct1/libsodium/releases/download/1.0.13/libsodium-1.0.13.tar.gz" mbedtls_file="mbedtls-2.5.1" -mbedtls_url="https://tls.mbed.org/download/mbedtls-2.5.1-gpl.tgz" +mbedtls_url="http://dl.teddysun.com/files/mbedtls-2.5.1-gpl.tgz" + +# Stream Ciphers +ciphers=( +aes-256-gcm +aes-192-gcm +aes-128-gcm +aes-256-ctr +aes-192-ctr +aes-128-ctr +aes-256-cfb +aes-192-cfb +aes-128-cfb +camellia-128-cfb +camellia-192-cfb +camellia-256-cfb +chacha20-ietf-poly1305 +chacha20-ietf +chacha20 +rc4-md5 +) +# Color +red='\033[0;31m' +green='\033[0;32m' +yellow='\033[0;33m' +plain='\033[0m' # 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 - exit 1 - fi -} +[[ $EUID -ne 0 ]] && echo -e "[${red}Error${plain}] This script must be run as root!" && exit 1 # Disable selinux disable_selinux(){ @@ -180,11 +200,11 @@ pre_install(){ if check_sys sysRelease centos; then # Not support CentOS 5 if centosversion 5; then - echo "Not support CentOS 5, please change to CentOS 6 or 7 and try again." + echo -e "[${red}Error${plain}] Not support CentOS 5, please change to CentOS 6 or 7 and try again." exit 1 fi else - echo "Error: Your OS is not supported to run it, please change OS to CentOS and try again." + echo -e "[${red}Error${plain}] Your OS is not supported to run it, please change OS to CentOS and try again." exit 1 fi @@ -192,13 +212,12 @@ pre_install(){ check_version status=$? if [ ${status} -eq 0 ]; then - echo "Latest version ${shadowsocks_libev_ver} has been installed, nothing to do..." - echo + echo -e "[${green}Info${plain}] Latest version ${green}${shadowsocks_libev_ver}${plain} has already been installed, nothing to do..." exit 0 elif [ ${status} -eq 1 ]; then - echo "Installed version: ${installed_ver}" - echo "Latest version: ${latest_ver}" - echo "Upgrade shadowsocks libev to latest version..." + echo -e "Installed version: ${red}${installed_ver}${plain}" + echo -e "Latest version: ${red}${latest_ver}${plain}" + echo -e "[${green}Info${plain}] Upgrade shadowsocks libev to latest version..." ps -ef | grep -v grep | grep -i "ss-server" > /dev/null 2>&1 if [ $? -eq 0 ]; then /etc/init.d/shadowsocks stop @@ -206,12 +225,12 @@ pre_install(){ elif [ ${status} -eq 2 ]; then print_info get_latest_version - echo "Latest version: ${shadowsocks_libev_ver}" + echo -e "[${green}Info${plain}] Latest version: ${green}${shadowsocks_libev_ver}${plain}" echo fi # Set shadowsocks-libev config password - echo "Please input password for shadowsocks-libev" + echo "Please input password for shadowsocks-libev:" read -p "(Default password: teddysun.com):" shadowsockspwd [ -z "${shadowsockspwd}" ] && shadowsockspwd="teddysun.com" echo @@ -223,10 +242,10 @@ pre_install(){ # Set shadowsocks-libev config port while true do - echo -e "Please input port for shadowsocks-libev [1-65535]" + echo -e "Please input port for shadowsocks-libev [1-65535]:" read -p "(Default port: 8989):" shadowsocksport [ -z "$shadowsocksport" ] && shadowsocksport="8989" - expr ${shadowsocksport} + 0 &>/dev/null + expr ${shadowsocksport} + 1 &>/dev/null if [ $? -eq 0 ]; then if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ]; then echo @@ -236,31 +255,61 @@ pre_install(){ echo break else - echo "Input error, please input correct number" + echo -e "[${red}Error${plain}] Input error, please input a number between 1 and 65535" fi else - echo "Input error, please input correct number" + echo -e "[${red}Error${plain}] Input error, please input a number between 1 and 65535" fi done + # Set shadowsocks config stream ciphers + while true + do + echo -e "Please select stream cipher for shadowsocks-libev:" + for ((i=1;i<=${#ciphers[@]};i++ )); do + hint="${ciphers[$i-1]}" + echo -e "${green}${i}${plain}) ${hint}" + done + read -p "Which cipher you'd select(Default: ${ciphers[0]}):" pick + [ -z "$pick" ] && pick=1 + expr ${pick} + 1 &>/dev/null + if [ $? -ne 0 ]; then + echo -e "[${red}Error${plain}] Input error, please input a number" + continue + fi + if [[ "$pick" -lt 1 || "$pick" -gt ${#ciphers[@]} ]]; then + echo -e "[${red}Error${plain}] Input error, please input a number between 1 and ${#ciphers[@]}" + continue + fi + shadowsockscipher=${ciphers[$pick-1]} + echo + echo "---------------------------" + echo "cipher = ${shadowsockscipher}" + echo "---------------------------" + echo + break + done + echo echo "Press any key to start...or press Ctrl+C to cancel" char=`get_char` #Install necessary dependencies - yum install -y epel-release - yum install -y gcc gettext-devel unzip autoconf automake make zlib-devel libtool udns-devel libev-devel - yum install -y pcre pcre-devel perl perl-devel cpio expat-devel openssl-devel + yum install -y epel-release && yum makecache + yum install -y unzip openssl openssl-devel gettext gcc autoconf libtool automake make asciidoc xmlto udns-devel libev-devel } download() { - local filename=$(basename $1) - if [ -f ${1} ]; then - echo "${filename} [found]" + local filename=${1} + local cur_dir=`pwd` + if [ -s ${filename} ]; then + echo -e "[${green}Info${plain}] ${filename} [found]" else - echo "${filename} not found, download now..." - wget --no-check-certificate -c -t3 -T60 -O ${1} ${2} - if [ $? -ne 0 ]; then - echo "Error: Download ${filename} failed." + echo -e "[${green}Info${plain}] ${filename} not found, download now..." + wget --no-check-certificate -cq -t3 -T3 -O ${1} ${2} + if [ $? -eq 0 ]; then + echo -e "[${green}Info${plain}] ${filename} download completed..." + else + echo -e "[${red}Error${plain}] Failed to download ${filename}, please download it to ${cur_dir} directory manually and try again." exit 1 fi fi @@ -283,11 +332,11 @@ install_libsodium() { cd ${libsodium_file} ./configure --prefix=/usr && make && make install if [ $? -ne 0 ]; then - echo "Error: ${libsodium_file} install failed." + echo -e "[${red}Error${plain}] ${libsodium_file} install failed." exit 1 fi else - echo "Info: ${libsodium_file} already installed." + echo -e "[${green}Info${plain}] ${libsodium_file} already installed." fi } @@ -298,8 +347,12 @@ install_mbedtls() { cd ${mbedtls_file} make SHARED=1 CFLAGS=-fPIC make DESTDIR=/usr install + if [ $? -ne 0 ]; then + echo -e "[${red}Error${plain}] ${mbedtls_file} install failed." + exit 1 + fi else - echo "Info: ${mbedtls_file} already installed." + echo -e "[${green}Info${plain}] ${mbedtls_file} already installed." fi } @@ -321,14 +374,14 @@ config_shadowsocks(){ "local_port":1080, "password":"${shadowsockspwd}", "timeout":600, - "method":"aes-256-cfb" + "method":"${shadowsockscipher}" } EOF } # Firewall set firewall_set(){ - echo "firewall set start..." + echo -e "[${green}Info${plain}] firewall set start..." if centosversion 6; then /etc/init.d/iptables status > /dev/null 2>&1 if [ $? -eq 0 ]; then @@ -339,10 +392,10 @@ firewall_set(){ /etc/init.d/iptables save /etc/init.d/iptables restart else - echo "port ${shadowsocksport} has been set up." + echo -e "[${green}Info${plain}] port ${shadowsocksport} has been set up." fi else - echo "WARNING: iptables looks like shutdown or not installed, please manually set it if necessary." + echo -e "[${yellow}Warning${plain}] iptables looks like shutdown or not installed, please manually set it if necessary." fi elif centosversion 7; then systemctl status firewalld > /dev/null 2>&1 @@ -351,18 +404,18 @@ firewall_set(){ firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp firewall-cmd --reload else - echo "Firewalld looks like not running, try to start..." + echo -e "[${green}Info${plain}] Firewalld looks like not running, try to start..." systemctl start firewalld 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 "WARNING: Try to start firewalld failed. please enable port ${shadowsocksport} manually if necessary." + echo -e "[${yellow}Warning${plain}] Try to start firewalld failed. please enable port ${shadowsocksport} manually if necessary." fi fi fi - echo "firewall set completed..." + echo -e "[${green}Info${plain}] firewall set completed..." } # Install Shadowsocks-libev @@ -378,45 +431,54 @@ install_shadowsocks(){ make && make install if [ $? -eq 0 ]; then chmod +x /etc/init.d/shadowsocks - # Add run on system start up chkconfig --add shadowsocks chkconfig shadowsocks on # Start shadowsocks /etc/init.d/shadowsocks start if [ $? -eq 0 ]; then - echo "Shadowsocks-libev start success!" + echo -e "[${green}Info${plain}] Shadowsocks-libev start success!" else - echo "Shadowsocks-libev start failure!" + echo -e "[${yellow}Warning${plain}] Shadowsocks-libev start failure!" fi else echo - echo "Shadowsocks-libev install failed! Please visit https://teddysun.com/357.html and contact." + echo -e "[${red}Error${plain}] Shadowsocks-libev install failed. please visit https://teddysun.com/357.html and contact." exit 1 fi cd ${cur_dir} rm -rf ${shadowsocks_libev_ver} ${shadowsocks_libev_ver}.tar.gz rm -rf ${libsodium_file} ${libsodium_file}.tar.gz + rm -rf ${mbedtls_file} ${mbedtls_file}-gpl.tgz clear echo - echo "Congratulations, Shadowsocks-libev install completed!" - echo -e "Your Server IP: \033[41;37m $(get_ip) \033[0m" - echo -e "Your Server Port: \033[41;37m ${shadowsocksport} \033[0m" - echo -e "Your Password: \033[41;37m ${shadowsockspwd} \033[0m" - echo -e "Your Local IP: \033[41;37m 127.0.0.1 \033[0m" - echo -e "Your Local Port: \033[41;37m 1080 \033[0m" - echo -e "Your Encryption Method: \033[41;37m aes-256-cfb \033[0m" + echo -e "Congratulations, Shadowsocks-libev server install completed!" + echo -e "Your Server IP : \033[41;37m $(get_ip) \033[0m" + echo -e "Your Server Port : \033[41;37m ${shadowsocksport} \033[0m" + echo -e "Your Password : \033[41;37m ${shadowsockspwd} \033[0m" + echo -e "Your Encryption Method: \033[41;37m ${shadowsockscipher} \033[0m" echo echo "Welcome to visit:https://teddysun.com/357.html" echo "Enjoy it!" echo } +# Install Shadowsocks-libev +install_shadowsocks_libev(){ + disable_selinux + pre_install + download_files + config_shadowsocks + firewall_set + install_shadowsocks +} + # Uninstall Shadowsocks-libev uninstall_shadowsocks_libev(){ + clear print_info - printf "Are you sure uninstall shadowsocks-libev? (y/n)" + printf "Are you sure uninstall Shadowsocks-libev? (y/n)" printf "\n" read -p "(Default: n):" answer [ -z ${answer} ] && answer="n" @@ -455,17 +517,6 @@ uninstall_shadowsocks_libev(){ fi } -# Install Shadowsocks-libev -install_shadowsocks_libev(){ - rootness - disable_selinux - pre_install - download_files - config_shadowsocks - firewall_set - install_shadowsocks -} - # Initialization step action=$1 [ -z $1 ] && action=install diff --git a/shadowsocks.sh b/shadowsocks.sh index 80f85d2..54b6a20 100644 --- a/shadowsocks.sh +++ b/shadowsocks.sh @@ -173,7 +173,7 @@ pre_install(){ echo "Please input port for shadowsocks-python [1-65535]" read -p "(Default port: 8989):" shadowsocksport [ -z "$shadowsocksport" ] && shadowsocksport="8989" - expr ${shadowsocksport} + 0 &>/dev/null + expr ${shadowsocksport} + 1 &>/dev/null if [ $? -eq 0 ]; then if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ]; then echo @@ -200,7 +200,7 @@ pre_install(){ done read -p "Which cipher you'd select(Default: ${ciphers[0]}):" pick [ -z "$pick" ] && pick=1 - expr ${pick} + 0 &>/dev/null + expr ${pick} + 1 &>/dev/null if [ $? -ne 0 ]; then echo -e "[${red}Error${plain}] Input error, please input a number" continue