From a157e382df81ba1d40ba275730d7adf627508004 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Tue, 22 Nov 2022 16:57:37 +0800 Subject: [PATCH] librespeed-go: add new package Go backend for LibreSpeed. Signed-off-by: Tianling Shen --- net/librespeed-go/Makefile | 78 +++++++++++++++++++ net/librespeed-go/files/librespeed-go.config | 47 ++++++++++++ net/librespeed-go/files/librespeed-go.init | 80 ++++++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 net/librespeed-go/Makefile create mode 100644 net/librespeed-go/files/librespeed-go.config create mode 100644 net/librespeed-go/files/librespeed-go.init diff --git a/net/librespeed-go/Makefile b/net/librespeed-go/Makefile new file mode 100644 index 0000000000..bb5557b0de --- /dev/null +++ b/net/librespeed-go/Makefile @@ -0,0 +1,78 @@ +# SPDX-License-Identifier: GPL-3.0-only +# +# Copyright (C) ImmortalWrt.org + +include $(TOPDIR)/rules.mk + +PKG_NAME:=librespeed-go +PKG_VERSION:=1.1.5 +PKG_RELEASE:=1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/librespeed/speedtest-go/tar.gz/v$(PKG_VERSION)? +PKG_HASH:=a65bbb94868d9ad73f85950264cb18fafb2ba5cf4788ac67981d78b863ca67c4 + +PKG_MAINTAINER:=Tianling Shen +PKG_LICENSE:=LGPL-3.0-only +PKG_LICENSE_FILES:=LICENSE + +PKG_BUILD_DEPENDS:=golang/host +PKG_BUILD_PARALLEL:=1 +PKG_USE_MIPS16:=0 + +GO_PKG:=github.com/librespeed/speedtest + +include $(INCLUDE_DIR)/package.mk +include ../../lang/golang/golang-package.mk + +TAR_OPTIONS+= --strip-components 1 +TAR_CMD=$(HOST_TAR) -C $(1) $(TAR_OPTIONS) + +define Package/librespeed-go + SECTION:=net + CATEGORY:=Network + SUBMENU:=Web Servers/Proxies + TITLE:=Go backend for LibreSpeed + URL:=https://github.com/librespeed/speedtest-go + DEPENDS:=$(GO_ARCH_DEPENDS) + USERID:=librespeed:librespeed +endef + +define Package/librespeed-go/description + No Flash, No Java, No WebSocket, No Bullshit. + + This is a very lightweight speed test implemented in JavaScript, + using XMLHttpRequest and Web Workers. +endef + +define Package/librespeed-go/conffiles +/etc/librespeed-go +endef + +define Build/Prepare + $(call Build/Prepare/Default) + + $(CP) $(PKG_BUILD_DIR)/web/assets/example-singleServer-progressBar.html \ + $(PKG_BUILD_DIR)/web/assets/index.html + + $(SED) 's,LibreSpeed Example,LibreSpeed for OpenWrt,g' \ + $(PKG_BUILD_DIR)/web/assets/*.html +endef + +define Package/librespeed-go/install + $(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR)) + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/speedtest $(1)/usr/bin/librespeed-go + + $(INSTALL_DIR) $(1)/etc/librespeed-go + $(CP) $(PKG_BUILD_DIR)/database/mysql/telemetry_mysql.sql $(1)/etc/librespeed-go/ + $(CP) $(PKG_BUILD_DIR)/database/postgresql/telemetry_postgresql.sql $(1)/etc/librespeed-go/ + + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_CONF) $(CURDIR)/files/librespeed-go.config $(1)/etc/config/librespeed-go + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) $(CURDIR)/files/librespeed-go.init $(1)/etc/init.d/librespeed-go +endef + +$(eval $(call GoBinPackage,librespeed-go)) +$(eval $(call BuildPackage,librespeed-go)) diff --git a/net/librespeed-go/files/librespeed-go.config b/net/librespeed-go/files/librespeed-go.config new file mode 100644 index 0000000000..e43dc912a5 --- /dev/null +++ b/net/librespeed-go/files/librespeed-go.config @@ -0,0 +1,47 @@ + +config librespeed-go 'config' + option enabled '0' + + # bind address, use empty string to bind to all interfaces + option bind_address '' + # backend listen port + option listen_port '8989' + + # change the base URL + # option url_base '/librespeed' + # proxy protocol port, use 0 to disable + option proxyprotocol_port '0' + # Server location, use zeroes to fetch from API automatically + option server_lat '0' + option server_lng '0' + # ipinfo.io API key, if applicable + option ipinfo_api_key '' + + # assets directory path, defaults to `assets` in the same directory + # if the path cannot be found, embedded default assets will be used + option assets_path '' + + # password for logging into statistics page, change this to enable stats page + # option statistics_password 'PASSWORD' + # redact IP addresses (boolean) + option redact_ip_addresses '0' + + # 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 + option database_type 'none' + # option database_hostname '' + # option database_name '' + # option database_username '' + # option database_password '' + + # if you use `bolt` as database, set database_file to database file location + # option database_file '/etc/librespeed-go/speedtest.db' + + # TLS and HTTP/2 settings. TLS is required for HTTP/2 (boolean) + option enable_tls '0' + option enable_http2 '0' + + # if you use HTTP/2 or TLS, you need to prepare certificates and private keys + # option tls_cert_file '/etc/librespeed-go/cert.pem' + # option tls_key_file '/etc/librespeed-go/privkey.pem' + diff --git a/net/librespeed-go/files/librespeed-go.init b/net/librespeed-go/files/librespeed-go.init new file mode 100644 index 0000000000..484a283dba --- /dev/null +++ b/net/librespeed-go/files/librespeed-go.init @@ -0,0 +1,80 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2022 Tianling Shen + +USE_PROCD=1 +START=99 + +CONF="librespeed-go" +PROG="/usr/bin/librespeed-go" +TMPCONF="/var/run/$CONF/settings.json" + +start_service() { + config_load "$CONF" + + local enabled + config_get_bool enabled "config" "enabled" "0" + [ "$enabled" -eq "1" ] || return 1 + + mkdir -p "${TMPCONF%/*}" + + json_init + option_cb() { + local name="$1" + local value="$2" + + case "$name" in + "enabled") ;; + "enable_tls"|"enable_http2"|"redact_ip_addresses") + json_add_boolean "$name" "$value" ;; + *) + json_add_string "$name" "$value" ;; + esac + } + config_load "$CONF" + json_dump > "$TMPCONF" + + local database_file + config_get database_file "config" "database_file" + if [ -n "$database_file" ]; then + mkdir -p "${database_file%/*}" + touch "$database_file" + chown librespeed "$database_file" + fi + + procd_open_instance "$CONF" + procd_set_param command "$PROG" + procd_append_param command -c "$TMPCONF" + + procd_set_param limits core="unlimited" + procd_set_param limits nofile="1000000 1000000" + procd_set_param respawn + procd_set_param stderr 1 + procd_set_param user librespeed + + procd_add_jail "$CONF" log + procd_add_jail_mount "$TMPCONF" + [ -z "$database_file" ] || procd_add_jail_mount_rw "$database_file" + + local assets_path tls_cert_file tls_key_file + config_get assets_path "config" "assets_path" + config_get tls_cert_file "config" "tls_cert_file" + config_get tls_key_file "config" "tls_key_file" + [ -z "$assets_path" ] || procd_add_jail_mount "$assets_path" + [ -z "$tls_cert_file" ] || procd_add_jail_mount "$tls_cert_file" + [ -z "$tls_key_file" ] || procd_add_jail_mount "$tls_key_file" + + procd_close_instance +} + +stop_service() { + rm -rf "${TMPCONF%/*}" +} + +reload_service() { + stop + start +} + +service_triggers() { + procd_add_reload_trigger "$CONF" +} -- 2.30.2