From 2ca5dbf0715ac85149d323a596bda4b8f82e81c2 Mon Sep 17 00:00:00 2001 From: udarnik386 Date: Mon, 5 Jul 2021 09:02:19 +0300 Subject: [PATCH] Add RPM package SPEC (#23) --- rpm/el7/README.md | 14 ++++ rpm/el7/SOURCES/librespeedgo.firewalld | 6 ++ rpm/el7/SOURCES/librespeedgo.mainconfig | 29 +++++++ rpm/el7/SOURCES/librespeedgo.service | 29 +++++++ rpm/el7/SPECS/librespeedgo.spec | 101 ++++++++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 rpm/el7/README.md create mode 100644 rpm/el7/SOURCES/librespeedgo.firewalld create mode 100644 rpm/el7/SOURCES/librespeedgo.mainconfig create mode 100644 rpm/el7/SOURCES/librespeedgo.service create mode 100644 rpm/el7/SPECS/librespeedgo.spec diff --git a/rpm/el7/README.md b/rpm/el7/README.md new file mode 100644 index 0000000..38a4bc9 --- /dev/null +++ b/rpm/el7/README.md @@ -0,0 +1,14 @@ +# librespeedgo-rpm + +Librespeedtest Go version package (tested for el7) +upstream: https://github.com/librespeed/speedtest-go + +custom rpmmacro vars: +* hk_version - define version +* hk_build - define build +* godir - change default GOPATH + +example: +``` +rpmbuild -D 'hk_build 3' -D 'hk_version 1.1.3' -D 'godir %{_builddir}/%{name}/.go' -bb SPECS/librespeedgo.spec +``` diff --git a/rpm/el7/SOURCES/librespeedgo.firewalld b/rpm/el7/SOURCES/librespeedgo.firewalld new file mode 100644 index 0000000..b71cec9 --- /dev/null +++ b/rpm/el7/SOURCES/librespeedgo.firewalld @@ -0,0 +1,6 @@ + + + librespeedgo + Libres speedtest service GO-version + + diff --git a/rpm/el7/SOURCES/librespeedgo.mainconfig b/rpm/el7/SOURCES/librespeedgo.mainconfig new file mode 100644 index 0000000..2847aad --- /dev/null +++ b/rpm/el7/SOURCES/librespeedgo.mainconfig @@ -0,0 +1,29 @@ +# bind address, use empty string to bind to all interfaces +bind_address="" +# backend listen port +listen_port=8989 +# proxy protocol port, use 0 to disable +proxyprotocol_port=0 +# Server location +server_lat=0 +server_lng=0 +# ipinfo.io API key, if applicable +ipinfo_api_key="" + +# assets directory path, defaults to `assets` in the same directory +assets_path="/usr/share/librespeedgo/assets" + +# password for logging into statistics page +statistics_password="PASSWORD" +# redact IP addresses +redact_ip_addresses=false + +# database type for statistics data, currently supports: bolt, mysql, postgresql +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="/var/lib/librespeedgo/speedtest.db" diff --git a/rpm/el7/SOURCES/librespeedgo.service b/rpm/el7/SOURCES/librespeedgo.service new file mode 100644 index 0000000..82c2a2c --- /dev/null +++ b/rpm/el7/SOURCES/librespeedgo.service @@ -0,0 +1,29 @@ +[Unit] +Description=Librespeed speed test +After=network.target + +[Service] +Type=simple +User=librespeedgo +Group=librespeedgo +WorkingDirectory=/usr/share/librespeedgo/ +ExecStart=/usr/bin/librespeedgo -c /etc/librespeedgo/settings.toml + +DevicePolicy=closed +NoNewPrivileges=yes +PrivateTmp=yes +PrivateUsers=yes +ProtectControlGroups=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +RestrictNamespaces=yes +RestrictRealtime=yes +ReadWritePaths=/var/lib/librespeedgo +ReadWritePaths=/etc/librespeedgo/settings.toml +PrivateDevices=yes +ProtectSystem=strict +ProtectHome=true +MemoryDenyWriteExecute=yes + +[Install] +WantedBy=multi-user.target diff --git a/rpm/el7/SPECS/librespeedgo.spec b/rpm/el7/SPECS/librespeedgo.spec new file mode 100644 index 0000000..c524554 --- /dev/null +++ b/rpm/el7/SPECS/librespeedgo.spec @@ -0,0 +1,101 @@ +%global appname librespeedgo +%global debug_package %{nil} +%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-.*[[:space:]].*$!!g') + +Name: %{appname} +Version: %{hk_version} +Release: %{hk_build}%{?dist} +Summary: LibreSpeed go-backend server + +Group: Applications/System +License: LGPL +URL: https://github.com/librespeed/speedtest-go +Source0: %{name}.tar.gz +Source1: %{name}.mainconfig +Source2: %{name}.service +Source3: %{name}.firewalld + +AutoReq: no +AutoProv: no +BuildArch: x86_64 +BuildRequires: golang >= 1.13 + +%description +Very lightweight speed test implemented in Javascript, using XMLHttpRequest and Web Workers. + +%prep +curl -sL 'https://github.com/librespeed/speedtest-go/archive/refs/tags/v%{version}.tar.gz' -o %{_sourcedir}/%{name}.tar.gz +if [[ -d %{_builddir}/%{name} ]];then + chmod 777 -R %{_builddir}/%{name} + rm -rf %{_builddir}/%{name} +fi +mkdir %{_builddir}/%{name} +tar xf %{_sourcedir}/%{name}.tar.gz -C %{_builddir}/%{name} --strip-components 1 +cd %{_builddir}/%{name} +cat << EOF >> %{name}.runtime +d /var/lib/librespeedgo 0750 librespeedgo librespeedgo +f /etc/librespeedgo/settings.toml 0640 root librespeedgo +f /var/lib/librespeedgo/speedtest.db 0640 librespeedgo librespeedgo +EOF +cp -a %{SOURCE1} %{SOURCE2} %{SOURCE3} ./ +pushd %{_builddir}/%{name}/assets +sed -i "s/LibreSpeed Example/LibreSpeed/" *.html +popd + +%build +pushd %{_builddir}/%{name} +%if 0%{?godir:1} +GOPATH=%{godir} go build -ldflags "-w -s" -trimpath -o %{name} main.go +%else +go build -ldflags "-w -s" -trimpath -o %{name} main.go +%endif +popd + +%install +pushd %{_builddir}/%{name} +install -D %{name} %{buildroot}%{_bindir}/%{name} +install -Dm644 %{name}.runtime %{buildroot}%{_sysconfdir}/tmpfiles.d/%{name}.conf +install -Dm640 %{name}.mainconfig %{buildroot}%{_sysconfdir}/%{name}/settings.toml +install -Dm644 %{name}.service %{buildroot}%{_prefix}/lib/systemd/system/%{name}.service +install -Dm644 %{name}.firewalld %{buildroot}%{_prefix}/lib/firewalld/services/%{name}.xml +install -dm750 %{buildroot}/var/lib/%{name} + +install -d %{buildroot}/%{_datadir}/%{name} +cp -r assets %{buildroot}/%{_datadir}/%{name} +install -m644 database/mysql/telemetry_mysql.sql %{buildroot}/%{_datadir}/%{name} +install -m644 database/postgresql/telemetry_postgresql.sql %{buildroot}/%{_datadir}/%{name} +popd + +%files +%config(noreplace) %{_sysconfdir}/%{name}/settings.toml +%config(noreplace) %{_prefix}/lib/firewalld/services/%{name}.xml +%config %{_sysconfdir}/tmpfiles.d/%{name}.conf +%config %{_prefix}/lib/systemd/system/%{name}.service +%{_bindir}/%{name} +%{_datadir}/%{name} +/var/lib/%{name} + +%post +if [ $1 == 1 ];then + if ! getent passwd %{name} > /dev/null; then + useradd -r -s /bin/false -m -d /var/lib/%{name} %{name} + fi + touch /var/lib/%{name}/speedtest.db + chown -R %{name}:%{name} /var/lib/%{name} + systemctl daemon-reload +elif [ $1 == 2 ];then + chown -R %{name}:%{name} /var/lib/%{name} + systemctl daemon-reload + if [ $(systemctl is-active --quiet %{name}.service) ];then + systemctl restart %{name}.service + fi +fi + +%preun +if [ $1 == 0 ];then + if [ $(systemctl is-active --quiet %{name}.service) ];then + systemctl stop %{name}.service + fi +fi + +%changelog