mirror of
https://github.com/safing/portmaster
synced 2025-09-02 10:39:22 +00:00
Add support for unpacking resources
Switch start to use portmaster-app.zip as app
This commit is contained in:
parent
4b694c5f84
commit
f21c16956a
4 changed files with 64 additions and 24 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -19,6 +20,9 @@ const (
|
||||||
// RestartExitCode is the exit code that any service started by portmaster-start
|
// RestartExitCode is the exit code that any service started by portmaster-start
|
||||||
// can return in order to trigger a restart after a clean shutdown.
|
// can return in order to trigger a restart after a clean shutdown.
|
||||||
RestartExitCode = 23
|
RestartExitCode = 23
|
||||||
|
|
||||||
|
exeSuffix = ".exe"
|
||||||
|
zipSuffix = ".zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -49,7 +53,7 @@ func init() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Portmaster App",
|
Name: "Portmaster App",
|
||||||
Identifier: "app/portmaster-app",
|
Identifier: "app/portmaster-app.zip",
|
||||||
AllowDownload: false,
|
AllowDownload: false,
|
||||||
AllowHidingWindow: false,
|
AllowHidingWindow: false,
|
||||||
},
|
},
|
||||||
|
@ -62,7 +66,6 @@ func init() {
|
||||||
{
|
{
|
||||||
Name: "Safing Privacy Network",
|
Name: "Safing Privacy Network",
|
||||||
Identifier: "hub/spn-hub",
|
Identifier: "hub/spn-hub",
|
||||||
ShortIdentifier: "hub",
|
|
||||||
AllowDownload: true,
|
AllowDownload: true,
|
||||||
AllowHidingWindow: true,
|
AllowHidingWindow: true,
|
||||||
},
|
},
|
||||||
|
@ -147,8 +150,8 @@ func run(opts *Options, cmdArgs []string) (err error) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// adapt identifier
|
// adapt identifier
|
||||||
if onWindows {
|
if onWindows && !strings.HasSuffix(opts.Identifier, zipSuffix) {
|
||||||
opts.Identifier += ".exe"
|
opts.Identifier += exeSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup logging
|
// setup logging
|
||||||
|
@ -275,16 +278,30 @@ func execute(opts *Options, args []string) (cont bool, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, fmt.Errorf("could not get component: %w", err)
|
return true, fmt.Errorf("could not get component: %w", err)
|
||||||
}
|
}
|
||||||
|
binPath := file.Path()
|
||||||
|
|
||||||
|
// Adapt path for packaged software.
|
||||||
|
if strings.HasSuffix(binPath, zipSuffix) {
|
||||||
|
// Remove suffix from binary path.
|
||||||
|
binPath = strings.TrimSuffix(binPath, zipSuffix)
|
||||||
|
// Add binary with the same name to access the unpacked binary.
|
||||||
|
binPath = filepath.Join(binPath, filepath.Base(binPath))
|
||||||
|
|
||||||
|
// Adapt binary path on Windows.
|
||||||
|
if onWindows {
|
||||||
|
binPath += exeSuffix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check permission
|
// check permission
|
||||||
if err := fixExecPerm(file.Path()); err != nil {
|
if err := fixExecPerm(binPath); err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("starting %s %s\n", file.Path(), strings.Join(args, " "))
|
log.Printf("starting %s %s\n", binPath, strings.Join(args, " "))
|
||||||
|
|
||||||
// create command
|
// create command
|
||||||
exc := exec.Command(file.Path(), args...) //nolint:gosec // everything is okay
|
exc := exec.Command(binPath, args...) //nolint:gosec // everything is okay
|
||||||
|
|
||||||
if !runningInConsole && opts.AllowHidingWindow {
|
if !runningInConsole && opts.AllowHidingWindow {
|
||||||
// Windows only:
|
// Windows only:
|
||||||
|
|
|
@ -15,8 +15,8 @@ func init() {
|
||||||
var showCmd = &cobra.Command{
|
var showCmd = &cobra.Command{
|
||||||
Use: "show",
|
Use: "show",
|
||||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||||
// all show sub-commands need the data-root but no logging.
|
// All show sub-commands need the registry but no logging.
|
||||||
return configureDataRoot(false)
|
return configureRegistry(false)
|
||||||
},
|
},
|
||||||
Short: "Show the command to run a Portmaster component yourself",
|
Short: "Show the command to run a Portmaster component yourself",
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ func show(opts *Options, cmdArgs []string) error {
|
||||||
|
|
||||||
// adapt identifier
|
// adapt identifier
|
||||||
if onWindows {
|
if onWindows {
|
||||||
opts.Identifier += ".exe"
|
opts.Identifier += exeSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := registry.GetFile(platform(opts.Identifier))
|
file, err := registry.GetFile(platform(opts.Identifier))
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -82,7 +84,6 @@ func init() {
|
||||||
MandatoryUpdates = []string{
|
MandatoryUpdates = []string{
|
||||||
platform("core/portmaster-core.exe"),
|
platform("core/portmaster-core.exe"),
|
||||||
platform("start/portmaster-start.exe"),
|
platform("start/portmaster-start.exe"),
|
||||||
platform("app/portmaster-app.exe"),
|
|
||||||
platform("notifier/portmaster-notifier.exe"),
|
platform("notifier/portmaster-notifier.exe"),
|
||||||
platform("notifier/portmaster-snoretoast.exe"),
|
platform("notifier/portmaster-snoretoast.exe"),
|
||||||
}
|
}
|
||||||
|
@ -90,10 +91,15 @@ func init() {
|
||||||
MandatoryUpdates = []string{
|
MandatoryUpdates = []string{
|
||||||
platform("core/portmaster-core"),
|
platform("core/portmaster-core"),
|
||||||
platform("start/portmaster-start"),
|
platform("start/portmaster-start"),
|
||||||
platform("app/portmaster-app"),
|
|
||||||
platform("notifier/portmaster-notifier"),
|
platform("notifier/portmaster-notifier"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MandatoryUpdates = append(
|
||||||
|
MandatoryUpdates,
|
||||||
|
platform("app/portmaster-app.zip"),
|
||||||
|
"all/ui/modules/portmaster.zip",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prep() error {
|
func prep() error {
|
||||||
|
@ -139,9 +145,12 @@ func start() error {
|
||||||
},
|
},
|
||||||
UserAgent: UserAgent,
|
UserAgent: UserAgent,
|
||||||
MandatoryUpdates: MandatoryUpdates,
|
MandatoryUpdates: MandatoryUpdates,
|
||||||
Beta: releaseChannel() == releaseChannelBeta,
|
AutoUnpack: []string{
|
||||||
DevMode: devMode(),
|
platform("app/portmaster-app.zip"),
|
||||||
Online: true,
|
},
|
||||||
|
Beta: releaseChannel() == releaseChannelBeta,
|
||||||
|
DevMode: devMode(),
|
||||||
|
Online: true,
|
||||||
}
|
}
|
||||||
if userAgentFromFlag != "" {
|
if userAgentFromFlag != "" {
|
||||||
// override with flag value
|
// override with flag value
|
||||||
|
@ -159,18 +168,21 @@ func start() error {
|
||||||
Beta: false,
|
Beta: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
registry.AddIndex(updater.Index{
|
if registry.Beta {
|
||||||
Path: "beta.json",
|
registry.AddIndex(updater.Index{
|
||||||
Stable: false,
|
Path: "beta.json",
|
||||||
Beta: true,
|
Stable: false,
|
||||||
})
|
Beta: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
registry.AddIndex(updater.Index{
|
registry.AddIndex(updater.Index{
|
||||||
Path: "all/intel/intel.json",
|
Path: "all/intel/intel.json",
|
||||||
Stable: true,
|
Stable: true,
|
||||||
Beta: false,
|
Beta: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
err = registry.LoadIndexes(module.Ctx)
|
err = registry.LoadIndexes(module.Ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warningf("updates: failed to load indexes: %s", err)
|
log.Warningf("updates: failed to load indexes: %s", err)
|
||||||
|
@ -184,6 +196,7 @@ func start() error {
|
||||||
registry.SelectVersions()
|
registry.SelectVersions()
|
||||||
module.TriggerEvent(VersionUpdateEvent, nil)
|
module.TriggerEvent(VersionUpdateEvent, nil)
|
||||||
|
|
||||||
|
// Initialize the version export - this requires the registry to be set up.
|
||||||
err = initVersionExport()
|
err = initVersionExport()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -257,7 +270,7 @@ func checkForUpdates(ctx context.Context) (err error) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
module.Resolve(updateInProgress)
|
module.Resolve(updateInProgress)
|
||||||
} else {
|
} else {
|
||||||
module.Warning(updateFailed, "Failed to check for updates: "+err.Error())
|
module.Warning(updateFailed, "Failed to update: "+err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -273,6 +286,13 @@ func checkForUpdates(ctx context.Context) (err error) {
|
||||||
|
|
||||||
registry.SelectVersions()
|
registry.SelectVersions()
|
||||||
|
|
||||||
|
// Unpack selected resources.
|
||||||
|
err = registry.UnpackResources()
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("failed to update: %w", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
module.TriggerEvent(ResourceUpdateEvent, nil)
|
module.TriggerEvent(ResourceUpdateEvent, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
processInfo "github.com/shirou/gopsutil/process"
|
processInfo "github.com/shirou/gopsutil/process"
|
||||||
"github.com/tevino/abool"
|
"github.com/tevino/abool"
|
||||||
|
|
||||||
|
"github.com/safing/portbase/dataroot"
|
||||||
"github.com/safing/portbase/info"
|
"github.com/safing/portbase/info"
|
||||||
"github.com/safing/portbase/log"
|
"github.com/safing/portbase/log"
|
||||||
"github.com/safing/portbase/notifications"
|
"github.com/safing/portbase/notifications"
|
||||||
|
@ -206,12 +207,11 @@ func upgradePortmasterStart() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update portmaster-start in data root
|
// update portmaster-start in data root
|
||||||
rootPmStartPath := filepath.Join(filepath.Dir(registry.StorageDir().Path), filename)
|
rootPmStartPath := filepath.Join(dataroot.Root().Path, filename)
|
||||||
err := upgradeFile(rootPmStartPath, pmCtrlUpdate)
|
err := upgradeFile(rootPmStartPath, pmCtrlUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Infof("updates: upgraded %s", rootPmStartPath)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -290,6 +290,7 @@ func upgradeFile(fileToUpgrade string, file *updater.File) error {
|
||||||
// abort if version matches
|
// abort if version matches
|
||||||
currentVersion = strings.Trim(strings.TrimSpace(string(out)), "*")
|
currentVersion = strings.Trim(strings.TrimSpace(string(out)), "*")
|
||||||
if currentVersion == file.Version() {
|
if currentVersion == file.Version() {
|
||||||
|
log.Tracef("updates: %s is already v%s", fileToUpgrade, file.Version())
|
||||||
// already up to date!
|
// already up to date!
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -352,6 +353,8 @@ func upgradeFile(fileToUpgrade string, file *updater.File) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("updates: upgraded %s to v%s", fileToUpgrade, file.Version())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue