Add support for unpacking resources
Switch start to use portmaster-app.zip as app
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -19,6 +20,9 @@ const (
|
||||
// RestartExitCode is the exit code that any service started by portmaster-start
|
||||
// can return in order to trigger a restart after a clean shutdown.
|
||||
RestartExitCode = 23
|
||||
|
||||
exeSuffix = ".exe"
|
||||
zipSuffix = ".zip"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -49,7 +53,7 @@ func init() {
|
||||
},
|
||||
{
|
||||
Name: "Portmaster App",
|
||||
Identifier: "app/portmaster-app",
|
||||
Identifier: "app/portmaster-app.zip",
|
||||
AllowDownload: false,
|
||||
AllowHidingWindow: false,
|
||||
},
|
||||
@@ -62,7 +66,6 @@ func init() {
|
||||
{
|
||||
Name: "Safing Privacy Network",
|
||||
Identifier: "hub/spn-hub",
|
||||
ShortIdentifier: "hub",
|
||||
AllowDownload: true,
|
||||
AllowHidingWindow: true,
|
||||
},
|
||||
@@ -147,8 +150,8 @@ func run(opts *Options, cmdArgs []string) (err error) {
|
||||
}()
|
||||
|
||||
// adapt identifier
|
||||
if onWindows {
|
||||
opts.Identifier += ".exe"
|
||||
if onWindows && !strings.HasSuffix(opts.Identifier, zipSuffix) {
|
||||
opts.Identifier += exeSuffix
|
||||
}
|
||||
|
||||
// setup logging
|
||||
@@ -275,16 +278,30 @@ func execute(opts *Options, args []string) (cont bool, err error) {
|
||||
if err != nil {
|
||||
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
|
||||
if err := fixExecPerm(file.Path()); err != nil {
|
||||
if err := fixExecPerm(binPath); err != nil {
|
||||
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
|
||||
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 {
|
||||
// Windows only:
|
||||
|
||||
@@ -15,8 +15,8 @@ func init() {
|
||||
var showCmd = &cobra.Command{
|
||||
Use: "show",
|
||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||
// all show sub-commands need the data-root but no logging.
|
||||
return configureDataRoot(false)
|
||||
// All show sub-commands need the registry but no logging.
|
||||
return configureRegistry(false)
|
||||
},
|
||||
Short: "Show the command to run a Portmaster component yourself",
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func show(opts *Options, cmdArgs []string) error {
|
||||
|
||||
// adapt identifier
|
||||
if onWindows {
|
||||
opts.Identifier += ".exe"
|
||||
opts.Identifier += exeSuffix
|
||||
}
|
||||
|
||||
file, err := registry.GetFile(platform(opts.Identifier))
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@@ -82,7 +84,6 @@ func init() {
|
||||
MandatoryUpdates = []string{
|
||||
platform("core/portmaster-core.exe"),
|
||||
platform("start/portmaster-start.exe"),
|
||||
platform("app/portmaster-app.exe"),
|
||||
platform("notifier/portmaster-notifier.exe"),
|
||||
platform("notifier/portmaster-snoretoast.exe"),
|
||||
}
|
||||
@@ -90,10 +91,15 @@ func init() {
|
||||
MandatoryUpdates = []string{
|
||||
platform("core/portmaster-core"),
|
||||
platform("start/portmaster-start"),
|
||||
platform("app/portmaster-app"),
|
||||
platform("notifier/portmaster-notifier"),
|
||||
}
|
||||
}
|
||||
|
||||
MandatoryUpdates = append(
|
||||
MandatoryUpdates,
|
||||
platform("app/portmaster-app.zip"),
|
||||
"all/ui/modules/portmaster.zip",
|
||||
)
|
||||
}
|
||||
|
||||
func prep() error {
|
||||
@@ -139,9 +145,12 @@ func start() error {
|
||||
},
|
||||
UserAgent: UserAgent,
|
||||
MandatoryUpdates: MandatoryUpdates,
|
||||
Beta: releaseChannel() == releaseChannelBeta,
|
||||
DevMode: devMode(),
|
||||
Online: true,
|
||||
AutoUnpack: []string{
|
||||
platform("app/portmaster-app.zip"),
|
||||
},
|
||||
Beta: releaseChannel() == releaseChannelBeta,
|
||||
DevMode: devMode(),
|
||||
Online: true,
|
||||
}
|
||||
if userAgentFromFlag != "" {
|
||||
// override with flag value
|
||||
@@ -159,18 +168,21 @@ func start() error {
|
||||
Beta: false,
|
||||
})
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "beta.json",
|
||||
Stable: false,
|
||||
Beta: true,
|
||||
})
|
||||
if registry.Beta {
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "beta.json",
|
||||
Stable: false,
|
||||
Beta: true,
|
||||
})
|
||||
}
|
||||
|
||||
registry.AddIndex(updater.Index{
|
||||
Path: "all/intel/intel.json",
|
||||
Stable: true,
|
||||
Beta: false,
|
||||
Beta: true,
|
||||
})
|
||||
|
||||
|
||||
err = registry.LoadIndexes(module.Ctx)
|
||||
if err != nil {
|
||||
log.Warningf("updates: failed to load indexes: %s", err)
|
||||
@@ -184,6 +196,7 @@ func start() error {
|
||||
registry.SelectVersions()
|
||||
module.TriggerEvent(VersionUpdateEvent, nil)
|
||||
|
||||
// Initialize the version export - this requires the registry to be set up.
|
||||
err = initVersionExport()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -257,7 +270,7 @@ func checkForUpdates(ctx context.Context) (err error) {
|
||||
if err == nil {
|
||||
module.Resolve(updateInProgress)
|
||||
} 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()
|
||||
|
||||
// Unpack selected resources.
|
||||
err = registry.UnpackResources()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to update: %w", err)
|
||||
return
|
||||
}
|
||||
|
||||
module.TriggerEvent(ResourceUpdateEvent, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
processInfo "github.com/shirou/gopsutil/process"
|
||||
"github.com/tevino/abool"
|
||||
|
||||
"github.com/safing/portbase/dataroot"
|
||||
"github.com/safing/portbase/info"
|
||||
"github.com/safing/portbase/log"
|
||||
"github.com/safing/portbase/notifications"
|
||||
@@ -206,12 +207,11 @@ func upgradePortmasterStart() error {
|
||||
}
|
||||
|
||||
// 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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("updates: upgraded %s", rootPmStartPath)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -290,6 +290,7 @@ func upgradeFile(fileToUpgrade string, file *updater.File) error {
|
||||
// abort if version matches
|
||||
currentVersion = strings.Trim(strings.TrimSpace(string(out)), "*")
|
||||
if currentVersion == file.Version() {
|
||||
log.Tracef("updates: %s is already v%s", fileToUpgrade, file.Version())
|
||||
// already up to date!
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user