forked from ophub/amlogic-s9xxx-armbian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path301-frps.sh
executable file
·241 lines (207 loc) · 7.5 KB
/
301-frps.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
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
#============================================================================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the Rebuild Armbian
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Function: Execute software install/update/uninstall script
# Copyright (C) 2021- https://github.com/unifreq/openwrt_packit
# Copyright (C) 2021- https://github.com/ophub/amlogic-s9xxx-armbian
#
# Command: ${0} <install/update/remove>
# Example: ${0} install
# ${0} update
# ${0} remove
#
#============================== Functions list ==============================
#
# error_msg : Output error message
# software_download : Software download
# software_install : Software install
# software_update : Software update
# software_remove : Software remove
#
#========================== Set default parameters ==========================
#
# Define the software
software_name="frps"
software_core="/usr/bin/frps"
software_conf="/etc/frp/frps.ini"
software_service="/etc/systemd/system/frps.service"
#
# Set font color
STEPS="[\033[95m STEPS \033[0m]"
INFO="[\033[94m INFO \033[0m]"
SUCCESS="[\033[92m SUCCESS \033[0m]"
PROMPT="[\033[93m PROMPT \033[0m]"
ERROR="[\033[91m ERROR \033[0m]"
#
#============================================================================
# Show error message
error_msg() {
echo -e "${ERROR} ${1}"
exit 1
}
software_download() {
echo -e "${STEPS} Start downloading [ ${software_name} ] software..."
# Software version query api
software_api="https://api.github.com/repos/fatedier/frp/releases"
# Check the latest version, E.g: v0.43.0
software_latest_version="$(curl -s "${software_api}" | grep "tag_name" | awk -F '"' '{print $4}' | tr " " "\n" | sort -rV | head -n 1)"
# Query download address, E.g: https://github.com/fatedier/frp/releases/download/v0.43.0/frp_0.43.0_linux_arm64.tar.gz
software_url="$(curl -s "${software_api}" | grep -oE "https:.*${software_latest_version}.*linux_arm64.*.tar.gz")"
[[ -n "${software_url}" ]] || error_msg "The download address is empty!"
echo -e "${INFO} Software download from: [ ${software_url} ]"
# Download software, E.g: /tmp/tmp.xxx/frp_0.43.0_linux_arm64.tar.gz
tmp_download="$(mktemp -d)"
software_filename="${software_url##*/}"
curl -fsSL "${software_url}" -o "${tmp_download}/${software_filename}"
[[ "${?}" -eq "0" && -s "${tmp_download}/${software_filename}" ]] || error_msg "Software download failed!"
echo -e "${INFO} Software downloaded successfully: $(ls ${tmp_download} -l)"
# Unzip the download file
tar -xf ${tmp_download}/${software_filename} -C ${tmp_download} && sync
# software directory, E.g: /tmp/tmp.xxx/frp_0.43.0_linux_arm64
software_dir="${tmp_download}/${software_filename/.tar.gz/}"
echo -e "${INFO} Software directory: [ ${software_dir} ]"
}
software_install() {
echo -e "${STEPS} Start installing [ ${software_name} ] software..."
software_download
# Generate random token
random_token="$(cat /proc/sys/kernel/random/uuid)"
# Generate random account
random_account="$(cat /proc/sys/kernel/random/uuid)"
random_user="${random_account:0:18}"
random_pwd="${random_account:19}"
# Add frps.ini
echo -e "${INFO} Add frps.ini to: [ ${software_conf} ]"
[[ -d "/etc/frp" ]] || sudo mkdir -p "/etc/frp"
# Copy the complete setup example
sudo cp -f ${software_dir}/frps_full.ini /etc/frp
# Generate common custom settings file
sudo cat >${software_conf} <<EOF
[common]
bind_addr = 0.0.0.0
bind_port = 7000
bind_udp_port = 7001
kcp_bind_port = 7000
vhost_http_port = 80
vhost_https_port = 443
dashboard_addr = 0.0.0.0
dashboard_port = 7500
dashboard_user = ${random_user}
dashboard_pwd = ${random_pwd}
log_file = /tmp/frps.log
log_level = info
log_max_days = 1
token = ${random_token}
subdomain_host = frps.com
max_pool_count = 5
tcp_mux = true
EOF
# Copy frps
echo -e "${INFO} Copy frps to: [ ${software_core} ]"
sudo cp -f ${software_dir}/frps /usr/bin && chmod +x ${software_core}
# Add frps.service
echo -e "${INFO} Add frps.service to: [ ${software_service} ]"
sudo cat >${software_service} <<EOF
[Unit]
Description=frps
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=${software_core} -c ${software_conf}
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
EOF
sync
# Set up to start automatically
echo -e "${INFO} Start service..."
sudo systemctl daemon-reload
sudo systemctl enable --now frps
sudo systemctl restart frps
echo -e "${PROMPT} Instructions for use:"
cat <<EOF
============================================[ Instructions for use of frps ]============================================
Official website: https://github.com/fatedier/frp
Documentation: https://github.com/ophub/amlogic-s9xxx-armbian/blob/main/build-armbian/documents/armbian_software.md
Core file path: [ ${software_core} ]
Config file path: [ ${software_conf} ]
Service file path: [ ${software_service} ]
Operate:
1. Edit config file: [ vi ${software_conf} ]
2. restart the service: [ sudo systemctl restart frps ]
3. Check running status: [ sudo systemctl status frps ]
Service management commands:
sudo systemctl start frps
sudo systemctl stop frps
sudo systemctl restart frps
sudo systemctl enable frps
sudo systemctl status frps
========================================================================================================================
EOF
echo -e "${SUCCESS} Software installed successfully."
exit 0
}
software_update() {
echo -e "${STEPS} Start updating [ ${software_name} ] software..."
software_download
# Stop frps.service
sudo systemctl stop frps
sync && sleep 3
# Copy frps
echo -e "${INFO} Copy frps to: [ ${software_core} ]"
sudo cp -f ${software_dir}/frps /usr/bin && chmod +x ${software_core}
sync
# Set up to start automatically
sudo systemctl daemon-reload
sudo systemctl enable --now frps
sudo systemctl restart frps
echo -e "${SUCCESS} Software update successfully."
exit 0
}
software_remove() {
echo -e "${STEPS} Start removing [ ${software_name} ] software..."
# Stop frps.service
sudo systemctl stop frps
sync && sleep 3
# Remove frps and frps.service
sudo rm -rf /etc/frp
sudo rm -f ${software_core}
sudo rm -f ${software_service} 2>/dev/null
sudo systemctl daemon-reload
echo -e "${SUCCESS} Software removed successfully."
exit 0
}
software_help() {
echo -e "${STEPS} Script usage instructions."
cat <<EOF
=====================================================================
Function : [ Command ]
---------------------------------------------------------------------
Install Software : [ ${0} install ]
Update Software : [ ${0} update ]
Remove Software : [ ${0} remove ]
=====================================================================
EOF
exit 0
}
# Check script permission, supports running on Armbian system.
echo -e "${STEPS} Welcome to [ ${software_name} ] software script: [ ${0} ]"
[[ "$(id -u)" == "0" ]] || error_msg "Please run this script as root: [ sudo ${0} ]"
#
# Execute script assist functions
case "${1}" in
install) software_install ;;
update) software_update ;;
remove) software_remove ;;
*) software_help ;;
esac