Skip to content
Snippets Groups Projects
Commit c12441df authored by jkito's avatar jkito :skull:
Browse files

installer: provide app name to post-install as an argument

the post-install tool run by the installer needs to know the path
for the app bundle as the bitmask privilege helper is located  in
the app bundle, earlier it was using a glob pattern "*VPN.app" to
find it, but since in the previous commit the BitmaskVPN name was
dropped and now uses Bitmask instead, this glob pattern no longer
works, so the app name is passed as argument to the tool
parent 5523856f
No related branches found
No related tags found
1 merge request!237gui: show bridge icon when transport is kcp and other misc UI fixes
Pipeline #232187 passed
......@@ -2,6 +2,7 @@ package main
import (
"bytes"
"errors"
"flag"
"fmt"
"io"
......@@ -72,33 +73,25 @@ var (
return filepath.Dir(execPath)
}()
appBundlePath = func() string {
names, err := filepath.Glob(filepath.Join(curdir, "*VPN.app"))
if err != nil {
log.Printf("error finding .app bundle path: %v", err)
return ""
}
if len(names) >= 1 {
return names[0]
}
return ""
}()
// flags
installerAction string
installerStage string
appName string
)
func init() {
const (
action = "action"
stage = "stage"
appname = "appname"
)
var usageAction = fmt.Sprintf("the installer actions: %s", strings.Join([]string{actionPostInstall, actionUninstall}, ","))
var usageStage = fmt.Sprintf("the installer action stage: preinstall, uninstall")
var usageStage = "the installer action stage: preinstall, uninstall"
var usageAppName = "name of the application being installed this is used to form the app bundle name by appending .app to it"
flag.StringVar(&installerAction, action, "", usageAction)
flag.StringVar(&installerStage, stage, stageUninstall, usageStage)
flag.StringVar(&appName, appname, "", usageAppName)
flag.Parse()
}
......@@ -113,7 +106,7 @@ func main() {
log.Fatal(err)
}
log.Println("running action: post-install")
if appBundlePath == "" {
if appBundlePath() == "" {
log.Fatal("could not find path to .app bundle")
}
err := postInstall()
......@@ -128,6 +121,18 @@ func main() {
}
}
func appBundlePath() string {
path := filepath.Join(curdir, appName+".app")
_, err := os.Stat(path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Printf("unable to find the app bundle path: %v", err)
return ""
}
}
return path
}
func setupLogFile(logFile string) error {
f, err := os.Create(logFile)
if err != nil {
......@@ -147,7 +152,7 @@ func postInstall() error {
log.Println("Changing ownership of 'bitmask-helper'")
// change ownership of bitmask-helper to root
if err := os.Chown(filepath.Join(appBundlePath, helperName), 0, 0); err != nil {
if err := os.Chown(filepath.Join(appBundlePath(), helperName), 0, 0); err != nil {
log.Println("error while changing ownership of 'bitmask-helper': ", err)
}
// copy launchd plist file to target location /Library/LaunchDaemons
......@@ -174,7 +179,7 @@ func postInstall() error {
// change ownership of 'helper' dir
log.Println("Changing ownership of 'helper' dir")
if err := os.Chown(filepath.Join(appBundlePath, "helper"), 0, 0); err != nil {
if err := os.Chown(filepath.Join(appBundlePath(), "helper"), 0, 0); err != nil {
log.Println("error while changing ownership of dir 'helper': ", err)
}
return nil
......@@ -186,7 +191,7 @@ func uninstall(stage string) {
if err := setupLogFile(filepath.Join("/tmp", fmt.Sprintf("bitmask-%s.log", stage))); err != nil {
log.Fatal(err)
}
if appBundlePath == "" {
if appBundlePath() == "" {
log.Fatal("could not find path to .app bundle")
}
default:
......@@ -247,7 +252,7 @@ func generatePlist() (string, error) {
appPath := struct {
Path string
}{
Path: appBundlePath,
Path: appBundlePath(),
}
t, err := template.New("plist").Parse(plistTemplate)
......
......@@ -194,7 +194,7 @@ function uninstallOSX() {
// TODO use installer filepath??
component.addElevatedOperation(
"Execute", "{0}",
"@TargetDir@/post-install", "-action=uninstall", "-stage=preinstall",
"@TargetDir@/post-install", "-action=uninstall", "-stage=preinstall", "-appname=@ProductName@",
"errormessage=There was an error during the pre-installation script, things might be broken. Please report this error and attach /tmp/bitmask-uninstall.log"
);
}
......@@ -203,10 +203,10 @@ function postInstallOSX() {
console.log("Post-installation for OSX");
component.addElevatedOperation(
"Execute", "{0}",
"@TargetDir@/post-install", "-action=post-install",
"@TargetDir@/post-install", "-action=post-install", "-appname=@ProductName@",
"errormessage=There was an error during the post-installation script, things might be broken. Please report this error and attach the post-install.log file.",
"UNDOEXECUTE",
"@TargetDir@/post-install", "-action=uninstall"
"@TargetDir@/post-install", "-action=uninstall", "-appname=@ProductName@"
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment