Last active
June 30, 2024 09:42
-
-
Save NNdroid/402d7532b606752cb33e60ddf3cdc9d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROXY="" | |
RELEASE_API="https://api.github.com/repos/librespeed/speedtest-go/releases/latest" | |
BIN_DST_DIR=/usr/local/bin | |
RESOURCE_DST_DIR=/usr/local/etc/speedtest-backend | |
function getReleaseInfo() { | |
response=$(curl ${RELEASE_API}) | |
if [ $? == 0 ]; then | |
echo $response | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
function check_error() { | |
if [ $? == 1 ]; then | |
echo $1 | |
exit 1 | |
fi | |
} | |
function install() { | |
assetDownloadUrl=$PROXY"https://github.com/librespeed/speedtest-go/releases/download/v1.1.5/speedtest-go_1.1.5_linux_amd64.tar.gz" | |
echo $assetDownloadUrl | |
wget -O /tmp/speedtest-go.tar.gz $assetDownloadUrl | |
check_error "download binary error!" | |
tar -zxvf /tmp/speedtest-go.tar.gz -C /tmp | |
check_error "uncompression error!" | |
mv /tmp/speedtest-backend ${BIN_DST_DIR}/speedtest-backend | |
chmod +x ${BIN_DST_DIR}/speedtest-backend | |
mkdir $RESOURCE_DST_DIR | |
mv /tmp/settings.toml $RESOURCE_DST_DIR | |
cat << EOT > ${RESOURCE_DST_DIR}/settings.toml | |
# bind address, use empty string to bind to all interfaces | |
bind_address="" | |
# backend listen port | |
listen_port=8989 | |
# change the base URL | |
# url_base="/librespeed" | |
# proxy protocol port, use 0 to disable | |
proxyprotocol_port=0 | |
# Server location | |
server_lat=1 | |
server_lng=1 | |
# ipinfo.io API key, if applicable | |
ipinfo_api_key="" | |
# assets directory path, defaults to assets in the same directory | |
assets_path="/usr/local/etc/speedtest-backend/assets" | |
# password for logging into statistics page | |
statistics_password="PASSWORD" | |
# redact IP addresses | |
redact_ip_addresses=false | |
# database type for statistics data, currently supports: none, memory, bolt, mysql, postgresql | |
# if none is specified, no telemetry/stats will be recorded, and no result PNG will be generated | |
database_type="bolt" | |
database_hostname="" | |
database_name="" | |
database_username="" | |
database_password="" | |
# if you use bolt as database, set database_file to database file location | |
database_file="/usr/local/etc/speedtest-backend/speedtest.db" | |
# TLS and HTTP/2 settings. TLS is required for HTTP/2 | |
enable_tls=false | |
enable_http2=false | |
# if you use HTTP/2 or TLS, you need to prepare certificates and private keys | |
# tls_cert_file="cert.pem" | |
# tls_key_file="privkey.pem" | |
EOT | |
mkdir ${RESOURCE_DST_DIR}/assets | |
wget -O ${RESOURCE_DST_DIR}/assets/index.html ${PROXY}https://github.com/librespeed/speedtest-go/raw/master/web/assets/example-singleServer-progressBar.html | |
wget -O ${RESOURCE_DST_DIR}/assets/speedtest.js ${PROXY}https://github.com/librespeed/speedtest-go/raw/master/web/assets/speedtest.js | |
wget -O ${RESOURCE_DST_DIR}/assets/speedtest_worker.js ${PROXY}https://github.com/librespeed/speedtest-go/raw/master/web/assets/speedtest_worker.js | |
cat << EOT > /etc/systemd/system/speedtest-backend.service | |
[Unit] | |
Description=speedtest-backend | |
Wants=network.target | |
After=syslog.target network-online.target | |
[Service] | |
Type=simple | |
Environment=GOGC=20 | |
ExecStart=/usr/local/bin/speedtest-backend -c /usr/local/etc/speedtest-backend/settings.toml | |
Restart=on-failure | |
RestartSec=10 | |
KillMode=process | |
LimitNOFILE=65535 | |
[Install] | |
WantedBy=multi-user.target | |
EOT | |
systemctl enable --now speedtest-backend | |
clear | |
echo "finished" | |
} | |
function remove() { | |
systemctl stop speedtest-backend | |
systemctl disable speedtest-backend | |
rm -rf /etc/systemd/system/speedtest-backend.service | |
rm -rf ${BIN_DST_DIR}/speedtest-backend | |
rm -rf $RESOURCE_DST_DIR | |
clear | |
echo "remove finished!" | |
} | |
function help() { | |
cat << EOF | |
speedtest-backend install helper!!! | |
usage: | |
./speedtest-backend.sh menu | |
install: install speedtest-backend | |
remove: remove speedtest-backend | |
EOF | |
} | |
function main() { | |
if [ $# -lt 1 ]; then | |
help | |
else | |
case $1 in | |
install) | |
install | |
;; | |
remove) | |
remove | |
;; | |
*) | |
echo 'command not found!' | |
help | |
;; | |
esac | |
fi | |
exit 0 | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment