From d828aacd0fb31bfba3325bacc5593de80ac95f51 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 10 Apr 2025 17:07:48 +0100 Subject: [PATCH 01/17] Fixed SPN HUB using wrong instance --- spn/docks/module_test.go | 2 +- spn/instance.go | 15 +++++++++++++++ spn/testing/simple/entrypoint.sh | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spn/docks/module_test.go b/spn/docks/module_test.go index 47e34b43..2f333b93 100644 --- a/spn/docks/module_test.go +++ b/spn/docks/module_test.go @@ -47,7 +47,7 @@ func (stub *testInstance) Stopping() bool { func (stub *testInstance) SetCmdLineOperation(f func() error) {} func runTest(m *testing.M) error { - _ = log.Start() + _ = log.Start("info", true, "") ds, err := config.InitializeUnitTestDataroot("test-docks") if err != nil { diff --git a/spn/instance.go b/spn/instance.go index e8fa1789..89878843 100644 --- a/spn/instance.go +++ b/spn/instance.go @@ -508,6 +508,21 @@ func (i *Instance) ExitCode() int { return int(i.exitCode.Load()) } +// ShouldRestartIsSet returns whether the service/instance should be restarted. +func (i *Instance) ShouldRestartIsSet() bool { + return i.ShouldRestart +} + +// CommandLineOperationIsSet returns whether the command line option is set. +func (i *Instance) CommandLineOperationIsSet() bool { + return i.CommandLineOperation != nil +} + +// CommandLineOperationExecute executes the set command line option. +func (i *Instance) CommandLineOperationExecute() error { + return i.CommandLineOperation() +} + // SPNGroup fakes interface conformance. // SPNGroup is only needed on SPN clients. func (i *Instance) SPNGroup() *mgr.ExtendedGroup { diff --git a/spn/testing/simple/entrypoint.sh b/spn/testing/simple/entrypoint.sh index 5fe516e0..95f0efb8 100755 --- a/spn/testing/simple/entrypoint.sh +++ b/spn/testing/simple/entrypoint.sh @@ -14,4 +14,4 @@ cat /opt/shared/config-template.json | sed "s/\$HUBNAME/$HUBNAME/g" > /opt/data/ BIN=$(ls /opt/ | grep hub) # Start Hub. -/opt/$BIN --data /opt/data --log trace --spn-map test --bootstrap-file /opt/shared/bootstrap.dsd --api-address 0.0.0.0:817 --devmode +/opt/$BIN --log trace --spn-map test --bootstrap-file /opt/shared/bootstrap.dsd --api-address 0.0.0.0:817 --devmode From 38d49f43c9c9402b4f92411dd14ad879c969bd43 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 10 Apr 2025 17:12:06 +0100 Subject: [PATCH 02/17] Fixed SPN HUB using wrong instance --- base/config/get_test.go | 2 +- cmds/hub/build | 6 ++++++ cmds/hub/main.go | 3 ++- cmds/winkext-test/main.go | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/base/config/get_test.go b/base/config/get_test.go index d16b6c51..448983d7 100644 --- a/base/config/get_test.go +++ b/base/config/get_test.go @@ -55,7 +55,7 @@ func TestGet(t *testing.T) { //nolint:paralleltest // reset options = make(map[string]*Option) - err := log.Start() + err := log.Start("info", true, "") if err != nil { t.Fatal(err) } diff --git a/cmds/hub/build b/cmds/hub/build index c95f6e73..fbffc928 100755 --- a/cmds/hub/build +++ b/cmds/hub/build @@ -51,6 +51,12 @@ if [[ $1 == "dev" ]]; then DEV="-race" fi +# Set GOOS and GOARCH for Darwin to use Linux architecture +if [[ "$(uname)" == "Darwin" ]]; then + export GOOS=linux + export GOARCH=amd64 +fi + echo "Please notice, that this build script includes metadata into the build." echo "This information is useful for debugging and license compliance." echo "Run the compiled binary with the -version flag to see the information included." diff --git a/cmds/hub/main.go b/cmds/hub/main.go index 807d9290..3316b046 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -14,6 +14,7 @@ import ( "github.com/safing/portmaster/service" "github.com/safing/portmaster/service/configure" "github.com/safing/portmaster/service/updates" + "github.com/safing/portmaster/spn" "github.com/safing/portmaster/spn/conf" ) @@ -75,7 +76,7 @@ func initializeGlobals(cmd *cobra.Command, args []string) { // Configure service. cmdbase.SvcFactory = func(svcCfg *service.ServiceConfig) (cmdbase.ServiceInstance, error) { - svc, err := service.New(svcCfg) + svc, err := spn.New(svcCfg) return svc, err } diff --git a/cmds/winkext-test/main.go b/cmds/winkext-test/main.go index f67382b5..dd6c60f4 100644 --- a/cmds/winkext-test/main.go +++ b/cmds/winkext-test/main.go @@ -45,7 +45,7 @@ func main() { } // logging - err := log.Start() + err := log.Start("info", true, "") if err != nil { fmt.Printf("failed to start logging: %s\n", err) os.Exit(1) From fc049757225895a416f76ab14434ec8d39980761 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Fri, 11 Apr 2025 11:50:09 +0100 Subject: [PATCH 03/17] Added logs --- cmds/hub/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index 3316b046..b4536328 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/safing/portmaster/base/info" + "github.com/safing/portmaster/base/log" "github.com/safing/portmaster/base/metrics" "github.com/safing/portmaster/cmds/cmdbase" "github.com/safing/portmaster/service" @@ -74,6 +75,10 @@ func initializeGlobals(cmd *cobra.Command, args []string) { // Set SPN public hub mode. conf.EnablePublicHub(true) + // Set default log level. + log.SetLogLevel(log.WarningLevel) + _ = log.Start(log.InfoLevel.String(), true, "") + // Configure service. cmdbase.SvcFactory = func(svcCfg *service.ServiceConfig) (cmdbase.ServiceInstance, error) { svc, err := spn.New(svcCfg) From 7d33aaff89fbfdc00b6991882d8ccbd8137361c2 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Fri, 11 Apr 2025 12:15:53 +0100 Subject: [PATCH 04/17] Enable SPN auto download/apply --- spn/instance.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spn/instance.go b/spn/instance.go index 89878843..4d65af74 100644 --- a/spn/instance.go +++ b/spn/instance.go @@ -136,6 +136,11 @@ func New(svcCfg *service.ServiceConfig) (*Instance, error) { if err != nil { return instance, fmt.Errorf("create updates config: %w", err) } + + //Enable autodownload and autoapply + binaryUpdateConfig.AutoDownload = true + binaryUpdateConfig.AutoApply = true + instance.binaryUpdates, err = updates.New(instance, "Binary Updater", *binaryUpdateConfig) if err != nil { return instance, fmt.Errorf("create updates module: %w", err) From ecce583296e62f5748a6001ba0840b4d0e87226d Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Fri, 11 Apr 2025 12:38:34 +0100 Subject: [PATCH 05/17] task(spn): Update SPN binary index url --- cmds/hub/main.go | 2 +- service/configure/updates.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index b4536328..ee369b77 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -93,7 +93,7 @@ func initializeGlobals(cmd *cobra.Command, args []string) { LogDir: logDir, LogLevel: logLevel, - BinariesIndexURLs: configure.DefaultStableBinaryIndexURLs, + BinariesIndexURLs: configure.DefaultSpnStableBinaryIndexURLs, IntelIndexURLs: configure.DefaultIntelIndexURLs, VerifyBinaryUpdates: configure.BinarySigningTrustStore, } diff --git a/service/configure/updates.go b/service/configure/updates.go index 0625ff26..1540f83b 100644 --- a/service/configure/updates.go +++ b/service/configure/updates.go @@ -11,6 +11,9 @@ var ( DefaultStableBinaryIndexURLs = []string{ "https://updates.safing.io/stable.v3.json", } + DefaultSpnStableBinaryIndexURLs = []string{ + "https://updates.safing.io/stable.v3.json", + } DefaultBetaBinaryIndexURLs = []string{ "https://updates.safing.io/beta.v3.json", } From 6d22b9347afa37f50882e3b39004c1209342f5fd Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Fri, 11 Apr 2025 12:41:57 +0100 Subject: [PATCH 06/17] task(spn): Update SPN binary index url --- service/configure/updates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/configure/updates.go b/service/configure/updates.go index 1540f83b..e765fca3 100644 --- a/service/configure/updates.go +++ b/service/configure/updates.go @@ -12,7 +12,7 @@ var ( "https://updates.safing.io/stable.v3.json", } DefaultSpnStableBinaryIndexURLs = []string{ - "https://updates.safing.io/stable.v3.json", + "https://updates.safing.io/spn-stable.v3.json", } DefaultBetaBinaryIndexURLs = []string{ "https://updates.safing.io/beta.v3.json", From 589b1afa640b1192d3a50edc8163852e9caa5954 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Fri, 11 Apr 2025 14:05:59 +0100 Subject: [PATCH 07/17] task(spn): Updated default intel index name --- service/configure/updates.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/configure/updates.go b/service/configure/updates.go index e765fca3..a84042c6 100644 --- a/service/configure/updates.go +++ b/service/configure/updates.go @@ -6,7 +6,7 @@ import ( var ( DefaultBinaryIndexName = "Portmaster Binaries" - DefaultIntelIndexName = "intel" + DefaultIntelIndexName = "Portmaster Intel" DefaultStableBinaryIndexURLs = []string{ "https://updates.safing.io/stable.v3.json", From 846646c7e9e12674237f7401f804da369f3c2771 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Mon, 14 Apr 2025 09:57:14 +0100 Subject: [PATCH 08/17] task(spn): added missing instance method from interface --- spn/instance.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spn/instance.go b/spn/instance.go index 4d65af74..0b0bd5c3 100644 --- a/spn/instance.go +++ b/spn/instance.go @@ -21,6 +21,7 @@ import ( "github.com/safing/portmaster/service/intel/geoip" "github.com/safing/portmaster/service/mgr" "github.com/safing/portmaster/service/netenv" + "github.com/safing/portmaster/service/ui" "github.com/safing/portmaster/service/updates" "github.com/safing/portmaster/spn/access" "github.com/safing/portmaster/spn/cabin" @@ -74,6 +75,7 @@ type Instance struct { ships *ships.Ships sluice *sluice.SluiceModule terminal *terminal.TerminalModule + ui *ui.UI CommandLineOperation func() error ShouldRestart bool @@ -376,6 +378,11 @@ func (i *Instance) Terminal() *terminal.TerminalModule { return i.terminal } +// UI returns the ui module. +func (i *Instance) UI() *ui.UI { + return i.ui +} + // FilterLists returns the filterLists module. func (i *Instance) FilterLists() *filterlists.FilterLists { return i.filterLists From 9801aae3e71a1ea9382ad9d28e53644bffa5f7e0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 15 Apr 2025 11:26:59 +0200 Subject: [PATCH 09/17] Fix SPN intel updates --- cmds/hub/main.go | 17 ++++++++++++++++- service/configure/updates.go | 3 --- service/updates/index.go | 5 ++++- service/updates/module.go | 3 +-- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index ee369b77..58f587e4 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -79,6 +79,21 @@ func initializeGlobals(cmd *cobra.Command, args []string) { log.SetLogLevel(log.WarningLevel) _ = log.Start(log.InfoLevel.String(), true, "") + // Configure SPN binary updates. + configure.DefaultBinaryIndexName = "SPN Binaries" + configure.DefaultStableBinaryIndexURLs = []string{ + "https://updates.safing.io/spn-stable.v3.json", + } + configure.DefaultBetaBinaryIndexURLs = []string{ + "https://updates.safing.io/spn-beta.v3.json", + } + configure.DefaultStagingBinaryIndexURLs = []string{ + "https://updates.safing.io/spn-staging.v3.json", + } + configure.DefaultSupportBinaryIndexURLs = []string{ + "https://updates.safing.io/spn-support.v3.json", + } + // Configure service. cmdbase.SvcFactory = func(svcCfg *service.ServiceConfig) (cmdbase.ServiceInstance, error) { svc, err := spn.New(svcCfg) @@ -93,7 +108,7 @@ func initializeGlobals(cmd *cobra.Command, args []string) { LogDir: logDir, LogLevel: logLevel, - BinariesIndexURLs: configure.DefaultSpnStableBinaryIndexURLs, + BinariesIndexURLs: configure.DefaultStableBinaryIndexURLs, IntelIndexURLs: configure.DefaultIntelIndexURLs, VerifyBinaryUpdates: configure.BinarySigningTrustStore, } diff --git a/service/configure/updates.go b/service/configure/updates.go index a84042c6..d3eb20e0 100644 --- a/service/configure/updates.go +++ b/service/configure/updates.go @@ -11,9 +11,6 @@ var ( DefaultStableBinaryIndexURLs = []string{ "https://updates.safing.io/stable.v3.json", } - DefaultSpnStableBinaryIndexURLs = []string{ - "https://updates.safing.io/spn-stable.v3.json", - } DefaultBetaBinaryIndexURLs = []string{ "https://updates.safing.io/beta.v3.json", } diff --git a/service/updates/index.go b/service/updates/index.go index 13285f9d..63546012 100644 --- a/service/updates/index.go +++ b/service/updates/index.go @@ -241,7 +241,10 @@ func (index *Index) ShouldUpgradeTo(newIndex *Index) error { return nil case index.Name != newIndex.Name: - return errors.New("new index name does not match") + return fmt.Errorf( + "new index name (%q) does not match current index name (%q)", + newIndex.Name, index.Name, + ) case index.isLocallyGenerated: if newIndex.versionNum.GreaterThan(index.versionNum) { diff --git a/service/updates/module.go b/service/updates/module.go index 024496c8..03ba6cb8 100644 --- a/service/updates/module.go +++ b/service/updates/module.go @@ -18,7 +18,6 @@ import ( "github.com/safing/portmaster/base/log" "github.com/safing/portmaster/base/notifications" "github.com/safing/portmaster/base/utils" - "github.com/safing/portmaster/service/configure" "github.com/safing/portmaster/service/mgr" "github.com/safing/portmaster/service/ui" ) @@ -203,7 +202,7 @@ func New(instance instance, name string, cfg Config) (*Updater, error) { module.corruptedInstallation = fmt.Errorf("invalid index: %w", err) } index, err = GenerateIndexFromDir(cfg.Directory, IndexScanConfig{ - Name: configure.DefaultBinaryIndexName, + Name: cfg.Name, Version: info.VersionNumber(), }) if err == nil && index.init(currentPlatform) == nil { From 1ed4cba1e1c1c695af15f147f4bc6717dccb0032 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 24 Apr 2025 17:54:19 +0100 Subject: [PATCH 10/17] SPN: Set SPN binary path --- cmds/hub/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index 58f587e4..6a502d20 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -94,6 +94,9 @@ func initializeGlobals(cmd *cobra.Command, args []string) { "https://updates.safing.io/spn-support.v3.json", } + binDir = "/opt/safing/spn" + dataDir = "/opt/safing/spn" + // Configure service. cmdbase.SvcFactory = func(svcCfg *service.ServiceConfig) (cmdbase.ServiceInstance, error) { svc, err := spn.New(svcCfg) From 2444209834f4eb0ec0cfe7e448436024f3371606 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Sat, 24 May 2025 17:40:15 +0100 Subject: [PATCH 11/17] Updated spn-hub to remove teh portmaster-start dependency. --- spn/tools/Dockerfile | 8 ++++---- spn/tools/container-init.sh | 11 ++++------- spn/tools/install.sh | 28 ++++++++++++++-------------- spn/tools/start-checksum.txt | 2 +- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/spn/tools/Dockerfile b/spn/tools/Dockerfile index dbe39af1..ef6ec68b 100644 --- a/spn/tools/Dockerfile +++ b/spn/tools/Dockerfile @@ -3,18 +3,18 @@ FROM alpine as builder # Ensure ca-certficates are up to date # RUN update-ca-certificates -# Download and verify portmaster-start binary. +# Download and verify spn-hub binary. RUN mkdir /init -RUN wget https://updates.safing.io/linux_amd64/start/portmaster-start_v0-9-6 -O /init/portmaster-start +RUN wget https://updates.safing.io/latest/linux_amd64/hub/spn-hub -O /init/spn-hub COPY start-checksum.txt /init/start-checksum RUN cd /init && sha256sum -c /init/start-checksum -RUN chmod 555 /init/portmaster-start +RUN chmod 555 /init/spn-hub # Use minimal image as base. FROM alpine # Copy the static executable. -COPY --from=builder /init/portmaster-start /init/portmaster-start +COPY --from=builder /init/spn-hub /init/spn-hub # Copy the init script COPY container-init.sh /init.sh diff --git a/spn/tools/container-init.sh b/spn/tools/container-init.sh index e5120872..eff651e9 100755 --- a/spn/tools/container-init.sh +++ b/spn/tools/container-init.sh @@ -1,8 +1,8 @@ #!/bin/sh DATA="/data" -START="/data/portmaster-start" -INIT_START="/init/portmaster-start" +START="/data/spn-hub" +INIT_START="/init/spn-hub" # Set safe shell options. set -euf -o pipefail @@ -18,13 +18,10 @@ if [ ! -f $START ]; then cp $INIT_START $START fi -# Download updates. -echo "running: $START update --data /data --intel-only" -$START update --data /data --intel-only # Remove PID file, which could have been left after a crash. rm -f $DATA/hub-lock.pid # Always start the SPN Hub with the updated main start binary. -echo "running: $START hub --data /data -- $@" -$START hub --data /data -- $@ +echo "running: $START" +$START -- $@ diff --git a/spn/tools/install.sh b/spn/tools/install.sh index e7cf8fd7..585f830a 100755 --- a/spn/tools/install.sh +++ b/spn/tools/install.sh @@ -14,7 +14,7 @@ set -e ARCH= INSTALLDIR= -PMSTART= +SPNBINARY= ENABLENOW= INSTALLSYSTEMD= SYSTEMDINSTALLPATH= @@ -22,7 +22,7 @@ SYSTEMDINSTALLPATH= apply_defaults() { ARCH=${ARCH:-amd64} INSTALLDIR=${INSTALLDIR:-/opt/safing/spn} - PMSTART=${PMSTART:-https://updates.safing.io/latest/linux_${ARCH}/start/portmaster-start} + SPNBINARY=${SPNBINARY:-https://updates.safing.io/latest/linux_${ARCH}/hub/spn-hub} SYSTEMDINSTALLPATH=${SYSTEMDINSTALLPATH:-/etc/systemd/system/spn.service} if command_exists systemctl; then @@ -98,14 +98,14 @@ ensure_install_dir() { mkdir -p ${INSTALLDIR} } -download_pmstart() { - log "Downloading portmaster-start ..." - local dest="${INSTALLDIR}/portmaster-start" +download_spnbinary() { + log "Downloading SPN binary ..." + local dest="${INSTALLDIR}/hub" if [ -f "${dest}" ]; then - warn "Overwriting existing portmaster-start at ${dest}" + warn "Overwriting existing hub at ${dest}" fi - download_file ${PMSTART} ${dest} + download_file ${SPNBINARY} ${dest} log "Changing permissions" chmod a+x ${dest} @@ -113,7 +113,7 @@ download_pmstart() { download_updates() { log "Downloading updates ..." - ${INSTALLDIR}/portmaster-start --data=${INSTALLDIR} update + ${INSTALLDIR}/hub update } setup_systemd() { @@ -122,7 +122,7 @@ setup_systemd() { warn "Skipping setup of systemd service unit" echo "To launch the hub, execute the following as root:" echo "" - echo "${INSTALLDIR}/portmaster-start --data ${INSTALLDIR} hub" + echo "${INSTALLDIR}/hub" echo "" return fi @@ -146,7 +146,7 @@ LimitNOFILE=infinity Environment=LOGLEVEL=warning Environment=SPN_ARGS= EnvironmentFile=-/etc/default/spn -ExecStart=${INSTALLDIR}/portmaster-start --data ${INSTALLDIR} hub -- --log \$LOGLEVEL \$SPN_ARGS +ExecStart=${INSTALLDIR}/hub --log \$LOGLEVEL \$SPN_ARGS [Install] WantedBy=multi-user.target @@ -210,7 +210,7 @@ confirm_config() { log "Installation configuration:" echo "" echo " Architecture: ${BOLD}${ARCH}${RESET}" - echo " Download-URL: ${BOLD}${PMSTART}${RESET}" + echo " Download-URL: ${BOLD}${SPNBINARY}${RESET}" echo " Target Dir: ${BOLD}${INSTALLDIR}${RESET}" echo "Install systemd: ${BOLD}${INSTALLSYSTEMD}${RESET}" echo " Unit path: ${BOLD}${SYSTEMDINSTALLPATH}${RESET}" @@ -247,7 +247,7 @@ ${BOLD}Options:${RESET} ${GREEN}-t, --target PATH${RESET} Configure the installation directory. ${GREEN}-h, --help${RESET} Display this help text ${GREEN}-a, --arch${RESET} Configure the binary architecture. - ${GREEN}-u, --url URL${RESET} Set download URL for portmaster start. + ${GREEN}-u, --url URL${RESET} Set download URL for spn-hub. ${GREEN}-S, --no-systemd${RESET} Do not install systemd service unit. ${GREEN}-s, --service-path PATH${RESET} Location for the systemd unit file. EOT @@ -278,7 +278,7 @@ main() { shift ;; --url | -u) - PMSTART=$2 + SPNBINARY=$2 shift ;; --no-systemd | -S) @@ -315,7 +315,7 @@ EOT # Setup hub ensure_install_dir - download_pmstart + download_spnbinary download_updates write_config_file "${INSTALLDIR}/config.json" diff --git a/spn/tools/start-checksum.txt b/spn/tools/start-checksum.txt index 3094e580..73f716f5 100644 --- a/spn/tools/start-checksum.txt +++ b/spn/tools/start-checksum.txt @@ -1 +1 @@ -3f45f0814c6db28c3899b39ae0ab01f8f20a8cc98697dbe8039162ccd9590bf8 ./portmaster-start +da0ca5ca57f3f5e80a7cb61a8e0ad9b1423051fc12e518b0539c7c69b7a68ee8 ./spn-hub From 25c150477186c1084ae9bbc178d8246ecc9eea0f Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Sat, 24 May 2025 17:57:02 +0100 Subject: [PATCH 12/17] Updated spn-hub install script to remove portmaster-start dependency. --- spn/tools/install.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spn/tools/install.sh b/spn/tools/install.sh index 585f830a..77a5ec2c 100755 --- a/spn/tools/install.sh +++ b/spn/tools/install.sh @@ -111,11 +111,6 @@ download_spnbinary() { chmod a+x ${dest} } -download_updates() { - log "Downloading updates ..." - ${INSTALLDIR}/hub update -} - setup_systemd() { log "Installing systemd service unit ..." if [ ! "${INSTALLSYSTEMD}" = "yes" ]; then @@ -316,7 +311,6 @@ EOT # Setup hub ensure_install_dir download_spnbinary - download_updates write_config_file "${INSTALLDIR}/config.json" # setup systemd From dff43809e20c1738f7567a6d5225a7de36bfcb2d Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Wed, 28 May 2025 11:40:15 +0100 Subject: [PATCH 13/17] Updated spn-hub install script to remove portmaster-start dependency. --- spn/tools/install.sh | 34 +++-- spn/tools/install.v2.sh | 320 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 340 insertions(+), 14 deletions(-) create mode 100644 spn/tools/install.v2.sh diff --git a/spn/tools/install.sh b/spn/tools/install.sh index 77a5ec2c..aab11ede 100755 --- a/spn/tools/install.sh +++ b/spn/tools/install.sh @@ -14,7 +14,7 @@ set -e ARCH= INSTALLDIR= -SPNBINARY= +PMSTART= ENABLENOW= INSTALLSYSTEMD= SYSTEMDINSTALLPATH= @@ -22,7 +22,7 @@ SYSTEMDINSTALLPATH= apply_defaults() { ARCH=${ARCH:-amd64} INSTALLDIR=${INSTALLDIR:-/opt/safing/spn} - SPNBINARY=${SPNBINARY:-https://updates.safing.io/latest/linux_${ARCH}/hub/spn-hub} + PMSTART=${PMSTART:-https://updates.safing.io/latest/linux_${ARCH}/start/portmaster-start} SYSTEMDINSTALLPATH=${SYSTEMDINSTALLPATH:-/etc/systemd/system/spn.service} if command_exists systemctl; then @@ -98,26 +98,31 @@ ensure_install_dir() { mkdir -p ${INSTALLDIR} } -download_spnbinary() { - log "Downloading SPN binary ..." - local dest="${INSTALLDIR}/hub" +download_pmstart() { + log "Downloading portmaster-start ..." + local dest="${INSTALLDIR}/portmaster-start" if [ -f "${dest}" ]; then - warn "Overwriting existing hub at ${dest}" + warn "Overwriting existing portmaster-start at ${dest}" fi - download_file ${SPNBINARY} ${dest} + download_file ${PMSTART} ${dest} log "Changing permissions" chmod a+x ${dest} } +download_updates() { + log "Downloading updates ..." + ${INSTALLDIR}/portmaster-start --data=${INSTALLDIR} update +} + setup_systemd() { log "Installing systemd service unit ..." if [ ! "${INSTALLSYSTEMD}" = "yes" ]; then warn "Skipping setup of systemd service unit" echo "To launch the hub, execute the following as root:" echo "" - echo "${INSTALLDIR}/hub" + echo "${INSTALLDIR}/portmaster-start --data ${INSTALLDIR} hub" echo "" return fi @@ -141,7 +146,7 @@ LimitNOFILE=infinity Environment=LOGLEVEL=warning Environment=SPN_ARGS= EnvironmentFile=-/etc/default/spn -ExecStart=${INSTALLDIR}/hub --log \$LOGLEVEL \$SPN_ARGS +ExecStart=${INSTALLDIR}/portmaster-start --data ${INSTALLDIR} hub -- --log \$LOGLEVEL \$SPN_ARGS [Install] WantedBy=multi-user.target @@ -205,7 +210,7 @@ confirm_config() { log "Installation configuration:" echo "" echo " Architecture: ${BOLD}${ARCH}${RESET}" - echo " Download-URL: ${BOLD}${SPNBINARY}${RESET}" + echo " Download-URL: ${BOLD}${PMSTART}${RESET}" echo " Target Dir: ${BOLD}${INSTALLDIR}${RESET}" echo "Install systemd: ${BOLD}${INSTALLSYSTEMD}${RESET}" echo " Unit path: ${BOLD}${SYSTEMDINSTALLPATH}${RESET}" @@ -242,7 +247,7 @@ ${BOLD}Options:${RESET} ${GREEN}-t, --target PATH${RESET} Configure the installation directory. ${GREEN}-h, --help${RESET} Display this help text ${GREEN}-a, --arch${RESET} Configure the binary architecture. - ${GREEN}-u, --url URL${RESET} Set download URL for spn-hub. + ${GREEN}-u, --url URL${RESET} Set download URL for portmaster start. ${GREEN}-S, --no-systemd${RESET} Do not install systemd service unit. ${GREEN}-s, --service-path PATH${RESET} Location for the systemd unit file. EOT @@ -273,7 +278,7 @@ main() { shift ;; --url | -u) - SPNBINARY=$2 + PMSTART=$2 shift ;; --no-systemd | -S) @@ -310,11 +315,12 @@ EOT # Setup hub ensure_install_dir - download_spnbinary + download_pmstart + download_updates write_config_file "${INSTALLDIR}/config.json" # setup systemd setup_systemd } -main "$@" +main "$@" \ No newline at end of file diff --git a/spn/tools/install.v2.sh b/spn/tools/install.v2.sh new file mode 100644 index 00000000..5034b5ee --- /dev/null +++ b/spn/tools/install.v2.sh @@ -0,0 +1,320 @@ +#!/bin/sh +# +# This script should be run via curl as root: +# sudo sh -c "$(curl -fsSL https://raw.githubusercontent.com/safing/portmaster/master/spn/tools/install-spn.sh)" +# or wget +# sudo sh -c "$(wget -qO- https://raw.githubusercontent.com/safing/portmaster/master/spn/tools/install-spn.sh)" +# +# As an alternative, you can first download the install script and run it afterwards: +# wget https://raw.githubusercontent.com/safing/portmaster/master/spn/tools/install-spn.sh +# sudo sh ./install.sh +# +# +set -e + +ARCH= +INSTALLDIR= +SPNBINARY= +ENABLENOW= +INSTALLSYSTEMD= +SYSTEMDINSTALLPATH= + +apply_defaults() { + ARCH=${ARCH:-amd64} + INSTALLDIR=${INSTALLDIR:-/opt/safing/spn} + SPNBINARY=${SPNBINARY:-https://updates.safing.io/latest/linux_${ARCH}/hub/spn-hub} + SYSTEMDINSTALLPATH=${SYSTEMDINSTALLPATH:-/etc/systemd/system/spn.service} + + if command_exists systemctl; then + INSTALLSYSTEMD=${INSTALLSYSTEMD:-yes} + ENABLENOW=${ENABLENOW:-yes} + else + INSTALLSYSTEMD=${INSTALLSYSTEMD:-no} + ENABLENOW=${ENABLENOW:-no} + fi + + # The hostname may be freshly set, ensure the ENV variable is correct. + export HOSTNAME=$(hostname) +} + +command_exists() { + command -v "$@" >/dev/null 2>&1 +} + +setup_tty() { + if [ -t 0 ]; then + interactive=yes + fi + + if [ -t 1 ]; then + RED=$(printf '\033[31m') + GREEN=$(printf '\033[32m') + YELLOW=$(printf '\033[33m') + BLUE=$(printf '\033[34m') + BOLD=$(printf '\033[1m') + RESET=$(printf '\033[m') + else + RED="" + GREEN="" + YELLOW="" + BLUE="" + BOLD="" + RESET="" + fi +} + +log() { + echo ${GREEN}${BOLD}"-> "${RESET}"$@" >&2 +} + +error() { + echo ${RED}"Error: $@"${RESET} >&2 +} + +warn() { + echo ${YELLOW}"warn: $@"${RESET} >&2 +} + +run_systemctl() { + systemctl $@ >/dev/null 2>&1 +} + +download_file() { + local src=$1 + local dest=$2 + + if command_exists curl; then + curl --silent --fail --show-error --location --output $dest $src + elif command_exists wget; then + wget --quiet -O $dest $src + else + error "No suitable download command found, either curl or wget must be installed" + exit 1 + fi +} + +ensure_install_dir() { + log "Creating ${INSTALLDIR}" + mkdir -p ${INSTALLDIR} +} + +download_spnbinary() { + log "Downloading SPN binary ..." + local dest="${INSTALLDIR}/hub" + if [ -f "${dest}" ]; then + warn "Overwriting existing hub at ${dest}" + fi + + download_file ${SPNBINARY} ${dest} + + log "Changing permissions" + chmod a+x ${dest} +} + +setup_systemd() { + log "Installing systemd service unit ..." + if [ ! "${INSTALLSYSTEMD}" = "yes" ]; then + warn "Skipping setup of systemd service unit" + echo "To launch the hub, execute the following as root:" + echo "" + echo "${INSTALLDIR}/hub --data-dir ${INSTALLDIR}" + echo "" + return + fi + + if [ -f "${SYSTEMDINSTALLPATH}" ]; then + warn "Overwriting existing unit path" + fi + + cat >${SYSTEMDINSTALLPATH} < " HOSTNAME + fi + if [ "${METRICS_COMMENT}" = "" ]; then + log "Please enter metrics comment:" + read -p "> " METRICS_COMMENT + fi +} + +write_config_file() { + cat >${1} < Date: Wed, 28 May 2025 11:49:32 +0100 Subject: [PATCH 14/17] Updated spn-hub install script to remove portmaster-start dependency. --- cmds/hub/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index 6a502d20..28a0188c 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -94,8 +94,12 @@ func initializeGlobals(cmd *cobra.Command, args []string) { "https://updates.safing.io/spn-support.v3.json", } - binDir = "/opt/safing/spn" - dataDir = "/opt/safing/spn" + if binDir == "" { + binDir = "/opt/safing/spn" + } + if dataDir == "" { + dataDir = "/opt/safing/spn" + } // Configure service. cmdbase.SvcFactory = func(svcCfg *service.ServiceConfig) (cmdbase.ServiceInstance, error) { From 42714750399a78c25841a28aa9d90bba2daf60aa Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 29 May 2025 11:14:08 +0100 Subject: [PATCH 15/17] fix(spn-hub): Updated wrong log level --- cmds/hub/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index 28a0188c..faef69ae 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -77,7 +77,7 @@ func initializeGlobals(cmd *cobra.Command, args []string) { // Set default log level. log.SetLogLevel(log.WarningLevel) - _ = log.Start(log.InfoLevel.String(), true, "") + _ = log.Start("warning", true, "") // Configure SPN binary updates. configure.DefaultBinaryIndexName = "SPN Binaries" From e25871d513a330d5469b256d4f7937c6702671b8 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 29 May 2025 12:04:09 +0100 Subject: [PATCH 16/17] fix(spn-hub): Disable duplicated logging --- cmds/hub/main.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cmds/hub/main.go b/cmds/hub/main.go index faef69ae..e7258fe4 100644 --- a/cmds/hub/main.go +++ b/cmds/hub/main.go @@ -9,7 +9,6 @@ import ( "github.com/spf13/cobra" "github.com/safing/portmaster/base/info" - "github.com/safing/portmaster/base/log" "github.com/safing/portmaster/base/metrics" "github.com/safing/portmaster/cmds/cmdbase" "github.com/safing/portmaster/service" @@ -75,10 +74,6 @@ func initializeGlobals(cmd *cobra.Command, args []string) { // Set SPN public hub mode. conf.EnablePublicHub(true) - // Set default log level. - log.SetLogLevel(log.WarningLevel) - _ = log.Start("warning", true, "") - // Configure SPN binary updates. configure.DefaultBinaryIndexName = "SPN Binaries" configure.DefaultStableBinaryIndexURLs = []string{ From 4c6da554f1a65667044f56f876dde1493d7322e9 Mon Sep 17 00:00:00 2001 From: Natanael Rodriguez Ramos Date: Thu, 29 May 2025 12:16:24 +0100 Subject: [PATCH 17/17] fix(spn-hub): Added logging directory on V2 install script --- spn/tools/install.v2.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spn/tools/install.v2.sh b/spn/tools/install.v2.sh index 5034b5ee..b8edceb7 100644 --- a/spn/tools/install.v2.sh +++ b/spn/tools/install.v2.sh @@ -18,12 +18,14 @@ SPNBINARY= ENABLENOW= INSTALLSYSTEMD= SYSTEMDINSTALLPATH= +LOGDIR= apply_defaults() { ARCH=${ARCH:-amd64} INSTALLDIR=${INSTALLDIR:-/opt/safing/spn} SPNBINARY=${SPNBINARY:-https://updates.safing.io/latest/linux_${ARCH}/hub/spn-hub} SYSTEMDINSTALLPATH=${SYSTEMDINSTALLPATH:-/etc/systemd/system/spn.service} + LOGDIR=${LOGDIR:-/opt/safing/spn} if command_exists systemctl; then INSTALLSYSTEMD=${INSTALLSYSTEMD:-yes} @@ -141,7 +143,7 @@ LimitNOFILE=infinity Environment=LOGLEVEL=warning Environment=SPN_ARGS= EnvironmentFile=-/etc/default/spn -ExecStart=${INSTALLDIR}/hub --data-dir ${INSTALLDIR} --log \$LOGLEVEL \$SPN_ARGS +ExecStart=${INSTALLDIR}/hub --data-dir ${INSTALLDIR} --log \$LOGLEVEL --log-dir ${LOGDIR} \$SPN_ARGS [Install] WantedBy=multi-user.target