From 98a9b4469b81d760aac75ade83b0f193618875cb Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 27 Apr 2023 17:53:08 +0200 Subject: [PATCH 01/10] [test] leverage launchd tool to implement autostart feature on macos --- config/autostart.go | 98 +++++++++++++++++++++++++++++++++++++++++++++ config/config.go | 16 ++++++++ config/config.ini | 3 +- main.go | 55 ++++++++++++++++++------- 4 files changed, 156 insertions(+), 16 deletions(-) create mode 100644 config/autostart.go diff --git a/config/autostart.go b/config/autostart.go new file mode 100644 index 000000000..5fb5c6880 --- /dev/null +++ b/config/autostart.go @@ -0,0 +1,98 @@ +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package config + +import ( + "fmt" + "os" + "os/exec" + + "github.com/arduino/go-paths-helper" + log "github.com/sirupsen/logrus" +) + +// getLaunchdAgentPath will return the path of the launchd agent default path +func getLaunchdAgentPath() *paths.Path { + return GetDefaultHomeDir().Join("Library", "LaunchAgents", "ArduinoCreateAgent.plist") +} + +// WritePlistFile function will write the required plist file to $HOME/Library/LaunchAgents/ArduinoCreateAgent.plist +// it will return nil in case of success, +// it will error if the file is already there or in any other case +func WritePlistFile() error { + src, err := os.Executable() + if err != nil { + return err + } + + launchdAgentPath := getLaunchdAgentPath() + + // For now this file comes from the installbuilder autogenerated one + launchdAgentDefinition := ` + + + + KeepAlive + + Label + ArduinoCreateAgent + ProgramArguments + + ` + src + ` + + RunAtLoad + + + AbandonProcessGroup + + + +` + if launchdAgentPath.Exist() { + // TODO check for differences in files(?) + // we already have an existing launchd plist file, so we don't have to do anything + return fmt.Errorf("the autostart file %s already exists", launchdAgentPath) + } + // we need to create a new one + return launchdAgentPath.WriteFile([]byte(launchdAgentDefinition)) +} + +// LoadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong +func LoadLaunchdAgent() error { + oscmd := exec.Command("launchctl", "load", getLaunchdAgentPath().String()) + err := oscmd.Run() + return err +} + +// UnloadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong +func UnloadLaunchdAgent() error { + oscmd := exec.Command("launchctl", "unload", getLaunchdAgentPath().String()) + err := oscmd.Run() + return err +} + +// RemovePlistFile function will remove the plist file from $HOME/Library/LaunchAgents/ArduinoCreateAgent.plist and return an error +// it will not do anything if the file is not there +func RemovePlistFile() error { + launchdAgentPath := getLaunchdAgentPath() + if launchdAgentPath.Exist() { + log.Infof("removing: %s", launchdAgentPath) + return launchdAgentPath.Remove() + } + return nil +} + +// TODO win/linux ? +// TODO read the doc about launchd https://www.launchd.info/ diff --git a/config/config.go b/config/config.go index 303aadce8..437437e59 100644 --- a/config/config.go +++ b/config/config.go @@ -91,6 +91,22 @@ func GetDefaultConfigDir() *paths.Path { return agentConfigDir } +// GetDefaultHomeDir returns the full path to the user's home directory. +func GetDefaultHomeDir() *paths.Path { + // UserHomeDir returns the current user's home directory. + + // On Unix, including macOS, it returns the $HOME environment variable. + // On Windows, it returns %USERPROFILE%. + // On Plan 9, it returns the $home environment variable. + + homeDir, err := os.UserHomeDir() + if err != nil { + log.Panicf("Can't get user home dir: %s", err) + } + + return paths.New(homeDir) +} + //go:embed config.ini var configContent []byte diff --git a/config/config.ini b/config/config.ini index 960e5f3d3..f63377db5 100644 --- a/config/config.ini +++ b/config/config.ini @@ -6,4 +6,5 @@ appName = CreateAgent/Stable updateUrl = https://downloads.arduino.cc/ origins = https://local.arduino.cc:8000 #httpProxy = http://your.proxy:port # Proxy server for HTTP requests -crashreport = false # enable crashreport logging \ No newline at end of file +crashreport = false # enable crashreport logging +autostartMacOS = true # the Arduino Create Agent is able to start automatically after login on macOS (launchd agent) \ No newline at end of file diff --git a/main.go b/main.go index 1011ccefe..bada58f87 100755 --- a/main.go +++ b/main.go @@ -66,21 +66,22 @@ var ( // iniflags var ( - address = iniConf.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost") - appName = iniConf.String("appName", "", "") - gcType = iniConf.String("gc", "std", "Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)") - hostname = iniConf.String("hostname", "unknown-hostname", "Override the hostname we get from the OS") - httpProxy = iniConf.String("httpProxy", "", "Proxy server for HTTP requests") - httpsProxy = iniConf.String("httpsProxy", "", "Proxy server for HTTPS requests") - indexURL = iniConf.String("indexURL", "https://downloads.arduino.cc/packages/package_staging_index.json", "The address from where to download the index json containing the location of upload tools") - iniConf = flag.NewFlagSet("ini", flag.ContinueOnError) - logDump = iniConf.String("log", "off", "off = (default)") - origins = iniConf.String("origins", "", "Allowed origin list for CORS") - regExpFilter = iniConf.String("regex", "usb|acm|com", "Regular expression to filter serial port list") - signatureKey = iniConf.String("signatureKey", "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvc0yZr1yUSen7qmE3cxF\nIE12rCksDnqR+Hp7o0nGi9123eCSFcJ7CkIRC8F+8JMhgI3zNqn4cUEn47I3RKD1\nZChPUCMiJCvbLbloxfdJrUi7gcSgUXrlKQStOKF5Iz7xv1M4XOP3JtjXLGo3EnJ1\npFgdWTOyoSrA8/w1rck4c/ISXZSinVAggPxmLwVEAAln6Itj6giIZHKvA2fL2o8z\nCeK057Lu8X6u2CG8tRWSQzVoKIQw/PKK6CNXCAy8vo4EkXudRutnEYHEJlPkVgPn\n2qP06GI+I+9zKE37iqj0k1/wFaCVXHXIvn06YrmjQw6I0dDj/60Wvi500FuRVpn9\ntwIDAQAB\n-----END PUBLIC KEY-----", "Pem-encoded public key to verify signed commandlines") - updateURL = iniConf.String("updateUrl", "", "") - verbose = iniConf.Bool("v", true, "show debug logging") - crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging") + address = iniConf.String("address", "127.0.0.1", "The address where to listen. Defaults to localhost") + appName = iniConf.String("appName", "", "") + gcType = iniConf.String("gc", "std", "Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage)") + hostname = iniConf.String("hostname", "unknown-hostname", "Override the hostname we get from the OS") + httpProxy = iniConf.String("httpProxy", "", "Proxy server for HTTP requests") + httpsProxy = iniConf.String("httpsProxy", "", "Proxy server for HTTPS requests") + indexURL = iniConf.String("indexURL", "https://downloads.arduino.cc/packages/package_staging_index.json", "The address from where to download the index json containing the location of upload tools") + iniConf = flag.NewFlagSet("ini", flag.ContinueOnError) + logDump = iniConf.String("log", "off", "off = (default)") + origins = iniConf.String("origins", "", "Allowed origin list for CORS") + regExpFilter = iniConf.String("regex", "usb|acm|com", "Regular expression to filter serial port list") + signatureKey = iniConf.String("signatureKey", "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvc0yZr1yUSen7qmE3cxF\nIE12rCksDnqR+Hp7o0nGi9123eCSFcJ7CkIRC8F+8JMhgI3zNqn4cUEn47I3RKD1\nZChPUCMiJCvbLbloxfdJrUi7gcSgUXrlKQStOKF5Iz7xv1M4XOP3JtjXLGo3EnJ1\npFgdWTOyoSrA8/w1rck4c/ISXZSinVAggPxmLwVEAAln6Itj6giIZHKvA2fL2o8z\nCeK057Lu8X6u2CG8tRWSQzVoKIQw/PKK6CNXCAy8vo4EkXudRutnEYHEJlPkVgPn\n2qP06GI+I+9zKE37iqj0k1/wFaCVXHXIvn06YrmjQw6I0dDj/60Wvi500FuRVpn9\ntwIDAQAB\n-----END PUBLIC KEY-----", "Pem-encoded public key to verify signed commandlines") + updateURL = iniConf.String("updateUrl", "", "") + verbose = iniConf.Bool("v", true, "show debug logging") + crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging") + autostartMacOS = iniConf.Bool("autostartMacOS", true, "the Arduino Create Agent is able to start automatically after login on macOS (launchd agent)") ) var homeTemplate = template.Must(template.New("home").Parse(homeTemplateHTML)) @@ -327,6 +328,30 @@ func loop() { } } + // osx agent launchd autostart + // TODO ignore setting if not on macos + if *autostartMacOS { + err := config.WritePlistFile() + if err != nil { + log.Info(err) + } else { + err = config.LoadLaunchdAgent() + if err != nil { + log.Error(err) + } + } + } else { + err := config.UnloadLaunchdAgent() + if err != nil { + log.Error(err) + } else { + err = config.RemovePlistFile() + if err != nil { + log.Error(err) + } + } + } + // launch the hub routine which is the singleton for the websocket server go h.run() // launch our serial port routine From bd7e83730af5f5dc322aba506b2c139ddf3a93e4 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 28 Apr 2023 15:28:25 +0200 Subject: [PATCH 02/10] use embed and template --- config/ArduinoCreateAgent.plist | 16 +++++++++ config/autostart.go | 58 +++++++++++++++------------------ 2 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 config/ArduinoCreateAgent.plist diff --git a/config/ArduinoCreateAgent.plist b/config/ArduinoCreateAgent.plist new file mode 100644 index 000000000..e1c2d0425 --- /dev/null +++ b/config/ArduinoCreateAgent.plist @@ -0,0 +1,16 @@ + + + + + KeepAlive + + Label + ArduinoCreateAgent + Program + {{.Program}} + RunAtLoad + <{{.RunAtLoad}}/> + AbandonProcessGroup + + + \ No newline at end of file diff --git a/config/autostart.go b/config/autostart.go index 5fb5c6880..a08dadab8 100644 --- a/config/autostart.go +++ b/config/autostart.go @@ -15,14 +15,20 @@ package config import ( + // we need this for the ArduinoCreateAgent.plist in this package + _ "embed" "fmt" "os" "os/exec" + "text/template" "github.com/arduino/go-paths-helper" log "github.com/sirupsen/logrus" ) +//go:embed ArduinoCreateAgent.plist +var launchdAgentDefinition []byte + // getLaunchdAgentPath will return the path of the launchd agent default path func getLaunchdAgentPath() *paths.Path { return GetDefaultHomeDir().Join("Library", "LaunchAgents", "ArduinoCreateAgent.plist") @@ -32,45 +38,35 @@ func getLaunchdAgentPath() *paths.Path { // it will return nil in case of success, // it will error if the file is already there or in any other case func WritePlistFile() error { - src, err := os.Executable() - if err != nil { - return err - } launchdAgentPath := getLaunchdAgentPath() - - // For now this file comes from the installbuilder autogenerated one - launchdAgentDefinition := ` - - - - KeepAlive - - Label - ArduinoCreateAgent - ProgramArguments - - ` + src + ` - - RunAtLoad - - - AbandonProcessGroup - - - -` if launchdAgentPath.Exist() { - // TODO check for differences in files(?) // we already have an existing launchd plist file, so we don't have to do anything return fmt.Errorf("the autostart file %s already exists", launchdAgentPath) } - // we need to create a new one - return launchdAgentPath.WriteFile([]byte(launchdAgentDefinition)) + + src, err := os.Executable() + if err != nil { + return err + } + data := struct { + Program string + RunAtLoad bool + }{ + Program: src, + RunAtLoad: false, + } + + t := template.Must(template.New("launchdConfig").Parse(string(launchdAgentDefinition))) + + // we need to create a new launchd plist file + plistFile, _ := launchdAgentPath.Create() + return t.Execute(plistFile, data) } // LoadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong func LoadLaunchdAgent() error { + // https://www.launchd.info/ oscmd := exec.Command("launchctl", "load", getLaunchdAgentPath().String()) err := oscmd.Run() return err @@ -78,6 +74,7 @@ func LoadLaunchdAgent() error { // UnloadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong func UnloadLaunchdAgent() error { + // https://www.launchd.info/ oscmd := exec.Command("launchctl", "unload", getLaunchdAgentPath().String()) err := oscmd.Run() return err @@ -93,6 +90,3 @@ func RemovePlistFile() error { } return nil } - -// TODO win/linux ? -// TODO read the doc about launchd https://www.launchd.info/ From 5d1f0723bd17e06bf79dea7da5e1ba403ca841f4 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 28 Apr 2023 15:30:35 +0200 Subject: [PATCH 03/10] add check on macos --- main.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index bada58f87..e30926b69 100755 --- a/main.go +++ b/main.go @@ -328,26 +328,27 @@ func loop() { } } - // osx agent launchd autostart - // TODO ignore setting if not on macos - if *autostartMacOS { - err := config.WritePlistFile() - if err != nil { - log.Info(err) - } else { - err = config.LoadLaunchdAgent() + // macos agent launchd autostart + if runtime.GOOS == "darwin" { + if *autostartMacOS { + err := config.WritePlistFile() if err != nil { - log.Error(err) + log.Info(err) + } else { + err = config.LoadLaunchdAgent() + if err != nil { + log.Error(err) + } } - } - } else { - err := config.UnloadLaunchdAgent() - if err != nil { - log.Error(err) } else { - err = config.RemovePlistFile() + err := config.UnloadLaunchdAgent() if err != nil { log.Error(err) + } else { + err = config.RemovePlistFile() + if err != nil { + log.Error(err) + } } } } From 2ec6fdcc3516d2f4207b249352b8611e402f50ae Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 28 Apr 2023 17:32:17 +0200 Subject: [PATCH 04/10] exit after loading the agent, `launchctl load ...` will start the binary --- config/autostart.go | 2 +- main.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/autostart.go b/config/autostart.go index a08dadab8..c5511dedd 100644 --- a/config/autostart.go +++ b/config/autostart.go @@ -54,7 +54,7 @@ func WritePlistFile() error { RunAtLoad bool }{ Program: src, - RunAtLoad: false, + RunAtLoad: true, // This will start the agent right after login (and also after `launchctl load ...`) } t := template.Must(template.New("launchdConfig").Parse(string(launchdAgentDefinition))) diff --git a/main.go b/main.go index e30926b69..842f7061f 100755 --- a/main.go +++ b/main.go @@ -335,9 +335,12 @@ func loop() { if err != nil { log.Info(err) } else { - err = config.LoadLaunchdAgent() + err = config.LoadLaunchdAgent() // this will load the agent: basically starting a new instance if err != nil { log.Error(err) + } else { + log.Info("Quitting, another instance of the agent has been started by launchd") + os.Exit(0) } } } else { From 956fc3af5ee15aae76737358f01a2c63db14aeaf Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 28 Apr 2023 15:43:39 +0200 Subject: [PATCH 05/10] test new version of the installer config --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 541da69c3..8793aad97 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -380,6 +380,7 @@ jobs: uses: actions/checkout@v3 with: repository: 'bcmi-labs/arduino-create-agent-installer' # the repo which contains install.xml + ref: autostart token: ${{ secrets.ARDUINO_CREATE_AGENT_CI_PAT }} - name: Download artifact From 198e14fd8cdc82a13a8b492953eee62764061783 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 4 May 2023 17:33:00 +0200 Subject: [PATCH 06/10] change the Label in the plist file to comply with the apple convention --- config/ArduinoCreateAgent.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/ArduinoCreateAgent.plist b/config/ArduinoCreateAgent.plist index e1c2d0425..7e85cc3b5 100644 --- a/config/ArduinoCreateAgent.plist +++ b/config/ArduinoCreateAgent.plist @@ -5,7 +5,7 @@ KeepAlive Label - ArduinoCreateAgent + cc.arduino.arduino-create-agent Program {{.Program}} RunAtLoad From 7abc1c5e83a96cba6b0fa0834dce412c27225237 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 4 May 2023 17:50:44 +0200 Subject: [PATCH 07/10] factor out the logic of Install/Uninstall of the plist in config package --- config/autostart.go | 46 +++++++++++++++++++++++++++++++++++++-------- main.go | 23 ++--------------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/config/autostart.go b/config/autostart.go index c5511dedd..9813c52da 100644 --- a/config/autostart.go +++ b/config/autostart.go @@ -17,7 +17,6 @@ package config import ( // we need this for the ArduinoCreateAgent.plist in this package _ "embed" - "fmt" "os" "os/exec" "text/template" @@ -34,18 +33,36 @@ func getLaunchdAgentPath() *paths.Path { return GetDefaultHomeDir().Join("Library", "LaunchAgents", "ArduinoCreateAgent.plist") } -// WritePlistFile function will write the required plist file to $HOME/Library/LaunchAgents/ArduinoCreateAgent.plist -// it will return nil in case of success, -// it will error if the file is already there or in any other case -func WritePlistFile() error { - +// InstallPlistFile will handle the process of creating the plist file required for the autostart +// and loading it using launchd +func InstallPlistFile() { launchdAgentPath := getLaunchdAgentPath() - if launchdAgentPath.Exist() { + if !launchdAgentPath.Exist() { + err := WritePlistFile(launchdAgentPath) + if err != nil { + log.Error(err) + } else { + err = LoadLaunchdAgent() // this will load the agent: basically starting a new instance + if err != nil { + log.Error(err) + } else { + log.Info("Quitting, another instance of the agent has been started by launchd") + os.Exit(0) + } + } + } else { // we already have an existing launchd plist file, so we don't have to do anything - return fmt.Errorf("the autostart file %s already exists", launchdAgentPath) + log.Infof("the autostart file %s already exists: nothing to do", launchdAgentPath) + } +} +// WritePlistFile function will write the required plist file to launchdAgentPath +// it will return nil in case of success, +// it will error in any other case +func WritePlistFile(launchdAgentPath *paths.Path) error { src, err := os.Executable() + if err != nil { return err } @@ -72,6 +89,18 @@ func LoadLaunchdAgent() error { return err } +func UninstallPlistFile() { + err := UnloadLaunchdAgent() + if err != nil { + log.Error(err) + } else { + err = RemovePlistFile() + if err != nil { + log.Error(err) + } + } +} + // UnloadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong func UnloadLaunchdAgent() error { // https://www.launchd.info/ @@ -88,5 +117,6 @@ func RemovePlistFile() error { log.Infof("removing: %s", launchdAgentPath) return launchdAgentPath.Remove() } + log.Infof("the autostart file %s do not exists: nothing to do", launchdAgentPath) return nil } diff --git a/main.go b/main.go index 842f7061f..0cb55a325 100755 --- a/main.go +++ b/main.go @@ -331,28 +331,9 @@ func loop() { // macos agent launchd autostart if runtime.GOOS == "darwin" { if *autostartMacOS { - err := config.WritePlistFile() - if err != nil { - log.Info(err) - } else { - err = config.LoadLaunchdAgent() // this will load the agent: basically starting a new instance - if err != nil { - log.Error(err) - } else { - log.Info("Quitting, another instance of the agent has been started by launchd") - os.Exit(0) - } - } + config.InstallPlistFile() } else { - err := config.UnloadLaunchdAgent() - if err != nil { - log.Error(err) - } else { - err = config.RemovePlistFile() - if err != nil { - log.Error(err) - } - } + config.UninstallPlistFile() } } From 73154255470b51e33594d22cefe639f3f4b8287f Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 5 May 2023 11:18:41 +0200 Subject: [PATCH 08/10] made functions private --- config/autostart.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config/autostart.go b/config/autostart.go index 9813c52da..8757b3a65 100644 --- a/config/autostart.go +++ b/config/autostart.go @@ -38,11 +38,11 @@ func getLaunchdAgentPath() *paths.Path { func InstallPlistFile() { launchdAgentPath := getLaunchdAgentPath() if !launchdAgentPath.Exist() { - err := WritePlistFile(launchdAgentPath) + err := writePlistFile(launchdAgentPath) if err != nil { log.Error(err) } else { - err = LoadLaunchdAgent() // this will load the agent: basically starting a new instance + err = loadLaunchdAgent() // this will load the agent: basically starting a new instance if err != nil { log.Error(err) } else { @@ -57,10 +57,10 @@ func InstallPlistFile() { } } -// WritePlistFile function will write the required plist file to launchdAgentPath +// writePlistFile function will write the required plist file to launchdAgentPath // it will return nil in case of success, // it will error in any other case -func WritePlistFile(launchdAgentPath *paths.Path) error { +func writePlistFile(launchdAgentPath *paths.Path) error { src, err := os.Executable() if err != nil { @@ -81,8 +81,8 @@ func WritePlistFile(launchdAgentPath *paths.Path) error { return t.Execute(plistFile, data) } -// LoadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong -func LoadLaunchdAgent() error { +// loadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong +func loadLaunchdAgent() error { // https://www.launchd.info/ oscmd := exec.Command("launchctl", "load", getLaunchdAgentPath().String()) err := oscmd.Run() @@ -90,28 +90,28 @@ func LoadLaunchdAgent() error { } func UninstallPlistFile() { - err := UnloadLaunchdAgent() + err := unloadLaunchdAgent() if err != nil { log.Error(err) } else { - err = RemovePlistFile() + err = removePlistFile() if err != nil { log.Error(err) } } } -// UnloadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong -func UnloadLaunchdAgent() error { +// unloadLaunchdAgent will use launchctl to load the agent, will return an error if something goes wrong +func unloadLaunchdAgent() error { // https://www.launchd.info/ oscmd := exec.Command("launchctl", "unload", getLaunchdAgentPath().String()) err := oscmd.Run() return err } -// RemovePlistFile function will remove the plist file from $HOME/Library/LaunchAgents/ArduinoCreateAgent.plist and return an error +// removePlistFile function will remove the plist file from $HOME/Library/LaunchAgents/ArduinoCreateAgent.plist and return an error // it will not do anything if the file is not there -func RemovePlistFile() error { +func removePlistFile() error { launchdAgentPath := getLaunchdAgentPath() if launchdAgentPath.Exist() { log.Infof("removing: %s", launchdAgentPath) From 637ae2172e54cdb0f7bacf6d45d81867ad19e7a3 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 28 Apr 2023 15:43:46 +0200 Subject: [PATCH 09/10] Revert "test new version of the installer config" This reverts commit ff33dbc2bb6890e14f9f960beed4e1376f907097. --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8793aad97..541da69c3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -380,7 +380,6 @@ jobs: uses: actions/checkout@v3 with: repository: 'bcmi-labs/arduino-create-agent-installer' # the repo which contains install.xml - ref: autostart token: ${{ secrets.ARDUINO_CREATE_AGENT_CI_PAT }} - name: Download artifact From 77ac4e7afa89e93d1e2c7d7aaab9d9ef1da9267d Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Fri, 5 May 2023 12:12:23 +0200 Subject: [PATCH 10/10] fix lint --- config/autostart.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/autostart.go b/config/autostart.go index 8757b3a65..c6b2b8d52 100644 --- a/config/autostart.go +++ b/config/autostart.go @@ -89,6 +89,8 @@ func loadLaunchdAgent() error { return err } +// UninstallPlistFile will handle the process of unloading (unsing launchd) the file required for the autostart +// and removing the file func UninstallPlistFile() { err := unloadLaunchdAgent() if err != nil {