Add RPM package SPEC (#23)

This commit is contained in:
udarnik386 2021-07-05 09:02:19 +03:00 committed by GitHub
parent dcb9882978
commit 2ca5dbf071
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 179 additions and 0 deletions

14
rpm/el7/README.md Normal file
View File

@ -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
```

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>librespeedgo</short>
<description>Libres speedtest service GO-version</description>
<port protocol="tcp" port="8989"/>
</service>

View File

@ -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"

View File

@ -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

View File

@ -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