Add support for unpacking resources

Switch start to use portmaster-app.zip as app
This commit is contained in:
Daniel
2020-11-24 16:41:21 +01:00
parent 4b694c5f84
commit f21c16956a
4 changed files with 64 additions and 24 deletions

View File

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

View File

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