-
Notifications
You must be signed in to change notification settings - Fork 17
/
sb-pc-linux.sh
231 lines (219 loc) · 5.87 KB
/
sb-pc-linux.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/bash
textcolor='\033[0;36m'
red='\033[1;31m'
clear='\033[0m'
check_root() {
if [[ $EUID -ne 0 ]]
then
echo ""
echo -e "${red}Error: this script should be run as root, use \"sudo -i\" command${clear}"
echo ""
exit 1
fi
}
enter_language() {
echo ""
echo -e "${textcolor}Select the language:${clear}"
echo "1 - Russian"
echo "2 - English"
read language
echo ""
}
enter_data_ru() {
while [[ -z $link ]]
do
echo -e "${textcolor}[?]${clear} Введите ссылку на ваш клиентский конфиг:"
read link
echo ""
done
echo -e "${textcolor}[?]${clear} Введите новую команду для этого прокси (и запомните её):"
read newcomm
echo ""
while [ -f /usr/local/bin/${newcomm} ] || [[ -z $newcomm ]]
do
if [ -f /usr/local/bin/${newcomm} ]
then
echo -e "${red}Ошибка: эта команда уже существует в /usr/local/bin${clear}"
echo ""
elif [[ -z $newcomm ]]
then
:
fi
echo -e "${textcolor}[?]${clear} Введите новую команду для этого прокси (и запомните её):"
read newcomm
echo ""
done
}
create_sbupdate_ru() {
if [ ! -d /etc/sing-box ]
then
echo "Установка Sing-Box..."
echo ""
touch /usr/local/bin/sbupdate
cat > /usr/local/bin/sbupdate <<-EOF
#!/bin/bash
red='\033[1;31m'
clear='\033[0m'
if [[ \$EUID -ne 0 ]]
then
echo ""
echo -e "\${red}Ошибка: эту команду нужно запускать от имени root\${clear}"
echo ""
exit 1
fi
curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc
chmod a+r /etc/apt/keyrings/sagernet.asc
echo "deb [arch=\`dpkg --print-architecture\` signed-by=/etc/apt/keyrings/sagernet.asc] https://deb.sagernet.org/ * *" | tee /etc/apt/sources.list.d/sagernet.list > /dev/null
apt-get update
apt-get install sing-box -y
systemctl disable sing-box.service
EOF
chmod +x /usr/local/bin/sbupdate
sbupdate
echo ""
echo "Sing-Box установлен"
echo ""
fi
}
create_proxy_command_ru() {
touch /usr/local/bin/${newcomm}
cat > /usr/local/bin/${newcomm} <<-EOF
#!/bin/bash
textcolor='\033[1;36m'
red='\033[1;31m'
clear='\033[0m'
if [[ \$EUID -ne 0 ]]
then
echo ""
echo -e "\${red}Ошибка: эту команду нужно запускать от имени root\${clear}"
echo ""
exit 1
fi
wget -q -O /etc/sing-box/config.json ${link}
systemctl start sing-box.service
echo ""
echo "Sing-Box запущен"
echo "Не закрывайте это окно, пока Sing-Box работает"
echo -e "Введите \${textcolor}x\${clear}, чтобы отключиться:"
while [[ \$run != "x" ]] && [[ \$run != "х" ]]
do
read run
done
run=""
echo ""
systemctl stop sing-box.service
EOF
chmod +x /usr/local/bin/${newcomm}
}
message_ru() {
echo -e "Вы можете использовать команду ${textcolor}${newcomm}${clear} для подключения к прокси и команду ${textcolor}sbupdate${clear} для обновления Sing-Box"
echo ""
echo "Если вы хотите добавить больше клиентских конфигов, то запустите этот скрипт ещё раз"
echo ""
}
enter_data_en() {
while [[ -z $link ]]
do
echo -e "${textcolor}[?]${clear} Enter your client config link:"
read link
echo ""
done
echo -e "${textcolor}[?]${clear} Enter the new command for this proxy (and remember it):"
read newcomm
echo ""
while [ -f /usr/local/bin/${newcomm} ] || [[ -z $newcomm ]]
do
if [ -f /usr/local/bin/${newcomm} ]
then
echo -e "${red}Error: this command already exists in /usr/local/bin${clear}"
echo ""
elif [[ -z $newcomm ]]
then
:
fi
echo -e "${textcolor}[?]${clear} Enter the new command for this proxy (and remember it):"
read newcomm
echo ""
done
}
create_sbupdate_en() {
if [ ! -d /etc/sing-box ]
then
echo "Installing Sing-Box..."
echo ""
touch /usr/local/bin/sbupdate
cat > /usr/local/bin/sbupdate <<-EOF
#!/bin/bash
red='\033[1;31m'
clear='\033[0m'
if [[ \$EUID -ne 0 ]]
then
echo ""
echo -e "\${red}Error: this command should be run as root\${clear}"
echo ""
exit 1
fi
curl -fsSL https://sing-box.app/gpg.key -o /etc/apt/keyrings/sagernet.asc
chmod a+r /etc/apt/keyrings/sagernet.asc
echo "deb [arch=\`dpkg --print-architecture\` signed-by=/etc/apt/keyrings/sagernet.asc] https://deb.sagernet.org/ * *" | tee /etc/apt/sources.list.d/sagernet.list > /dev/null
apt-get update
apt-get install sing-box -y
systemctl disable sing-box.service
EOF
chmod +x /usr/local/bin/sbupdate
sbupdate
echo ""
echo "Sing-Box is installed"
echo ""
fi
}
create_proxy_command_en() {
touch /usr/local/bin/${newcomm}
cat > /usr/local/bin/${newcomm} <<-EOF
#!/bin/bash
textcolor='\033[1;36m'
red='\033[1;31m'
clear='\033[0m'
if [[ \$EUID -ne 0 ]]
then
echo ""
echo -e "\${red}Error: this command should be run as root\${clear}"
echo ""
exit 1
fi
wget -q -O /etc/sing-box/config.json ${link}
systemctl start sing-box.service
echo ""
echo "Started Sing-Box"
echo "Do not close this window while Sing-Box is running"
echo -e "Enter \${textcolor}x\${clear} to disconnect:"
while [[ \$run != "x" ]] && [[ \$run != "х" ]]
do
read run
done
run=""
echo ""
systemctl stop sing-box.service
EOF
chmod +x /usr/local/bin/${newcomm}
}
message_en() {
echo -e "You can use ${textcolor}${newcomm}${clear} command to connect to the proxy and ${textcolor}sbupdate${clear} command to update Sing-Box"
echo ""
echo "Run this script again if you want to add more client configs"
echo ""
}
check_root
enter_language
if [[ "$language" == "1" ]]
then
enter_data_ru
create_sbupdate_ru
create_proxy_command_ru
message_ru
else
enter_data_en
create_sbupdate_en
create_proxy_command_en
message_en
fi