-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathss-server.sh
executable file
·177 lines (143 loc) · 3.64 KB
/
ss-server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
SS_DIR=/opt/shadowsocks
SS_CONFIG=$SS_DIR/conf.json
DEFAULT__SS_CIPHER=aes-256-gcm
DEFAULT__SS_SERVER_ADDR=0.0.0.0
DEFAULT__SS_PORT=443
DEFAULT__SS_PASSWORD=75dI6Riw
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
)
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# check and install ss-server
if ! command -v ss-server &> /dev/null
then
echo "Update apt repository"
apt -y update
echo "\"ss-server\" could not be found, so it's going to install"
apt -y install shadowsocks-libev
else
echo "\"ss-server\" already exist."
fi
# create working directory
if [ ! -d "$SS_DIR" ]; then
echo "Creating working dir ..."
mkdir -p $SS_DIR
fi
echo
echo "Working directory: $SS_DIR"
echo
# server address
read -p "Please enter your server address [$DEFAULT__SS_SERVER_ADDR]: " SS_SERVER_ADDR
SS_SERVER_ADDR=${SS_SERVER_ADDR:-$DEFAULT__SS_SERVER_ADDR}
# cipher
echo "Please select stream cipher:"
echo "Supported chipers:"
for CIPHER in "${CIPHERS[@]}"
do
echo -e "\t$CIPHER"
done
echo
# select cipher
while true
do
read -p "Which cipher you'd select [$DEFAULT__SS_CIPHER]: " SS_CIPHER
if [ -z "$SS_CIPHER" ] # use default cipher if input is empty
then
SS_CIPHER=$DEFAULT__SS_CIPHER
break
elif [[ " ${CIPHERS[*]} " =~ " ${SS_CIPHER} " ]]; then # check input cipher with supported ciphers
break # brake if cipher exist in the supported ciphers
else
echo
echo "Invalid cipher: \"$SS_CIPHER\""
echo
fi
done
# port
while true
do
read -p "Please enter server port [$DEFAULT__SS_PORT]: " SS_PORT
if [ -z "$SS_PORT" ] # use default port if input is empty
then
SS_PORT=$DEFAULT__SS_PORT
break
elif [ "$SS_PORT" -lt 0 ] || [ "$SS_PORT" -gt 65535 ]
then
echo
echo "\"$SS_PORT\" is invalid it must be between [1-65535]!"
echo
elif [[ $(lsof -i:"$SS_PORT" | grep LISTEN) ]] &> /dev/null
then
echo
echo "\"$SS_PORT\" is already in use!"
echo
else
break
fi
done
# password
read -p "Please enter your server password [$DEFAULT__SS_PASSWORD]: " SS_PASSWORD
SS_PASSWORD=${SS_PASSWORD:-$DEFAULT__SS_PASSWORD}
#V2-RAY plugin
echo
echo "Install v2ray-plugin..."
echo
# install v2ray
set -e
./v2ray.sh $SS_DIR
# configuration file
if test -f "$SS_CONFIG"; then
echo
while true; do
read -p "Config file already exist [$SS_CONFIG], do you want to overwrite it? (Y/N): " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
fi
echo
# create config file
if ! command -v jq &> /dev/null
then
echo "Install jq for create json file"
apt -y install jq
fi
jq -n \
--arg server "$SS_SERVER_ADDR" \
--arg server_port "$SS_PORT" \
--arg local_port "$SS_PORT" \
--arg password "$SS_PASSWORD" \
--arg method "$SS_CIPHER" \
--arg timeout 300 \
--arg user "nobody" \
--arg plugin "v2ray-plugin" \
--arg plugin_opts "server" \
'{server: $server, server_port: ($server_port|tonumber), local_port: ($local_port|tonumber), password: $password, method: $method, timeout: ($timeout|tonumber), user: $user, plugin : $plugin, plugin_opts: $plugin_opts}' > $SS_CONFIG
echo "Server config ($SS_CONFIG):"
cat $SS_CONFIG
echo
echo "Now you can start shadowsocks server using following command: "
echo "################################################################"
echo -e "\t ss-server -c $SS_CONFIG start"
echo "################################################################"