From 7c56873205c1288d52bc2448573681976434f886 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Thu, 25 May 2023 22:38:38 -0700 Subject: [PATCH 1/2] Remove console-window code --- README.md | 1 + examples/MANUAL.md | 2 +- go.mod | 2 -- go.sum | 5 ----- main.go | 3 --- pkg/ui/ui_darwin.go | 6 ------ pkg/ui/ui_other.go | 6 ------ pkg/ui/ui_windows.go | 22 ---------------------- 8 files changed, 2 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index c34af847..eedead9b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ documentation support. This project succeeds because of them. Thank you! [![Docker Cloud](https://docs.golift.io/integrations/docker.png "Docker Cloud")](https://cloud.docker.com) [![Homebrew](https://docs.golift.io/integrations/homebrew.png "Homebrew")](https://brew.sh) [![Go Lift](https://docs.golift.io/integrations/golift.png "Go Lift")](https://golift.io) +[![CloudFlare](https://docs.golift.io/integrations/cloudflare.png "CloudFlare")](https://cloudflare.com) ## Contributing diff --git a/examples/MANUAL.md b/examples/MANUAL.md index 6e8617ba..c63ed767 100644 --- a/examples/MANUAL.md +++ b/examples/MANUAL.md @@ -64,4 +64,4 @@ AUTHOR LOCATION --- -* [github.com/Unpackerr/unpackerr](https://github.com/Unpackerr/unpackerr) +* [unpackerr.zip](https://unpackerr.zip) diff --git a/go.mod b/go.mod index 45fe046a..45c0e9c1 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,6 @@ require ( github.com/fsnotify/fsnotify v1.6.0 github.com/gen2brain/dlgs v0.0.0-20220603100644-40c77870fa8d github.com/getlantern/systray v1.2.2 - github.com/gonutz/w32 v1.0.0 - github.com/gonutz/w32/v2 v2.9.0 github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b github.com/julienschmidt/httprouter v1.3.0 github.com/lestrrat-go/apache-logformat/v2 v2.0.6 diff --git a/go.sum b/go.sum index 857b8766..a525dee7 100644 --- a/go.sum +++ b/go.sum @@ -99,9 +99,6 @@ github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaW github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/gonutz/w32 v1.0.0 h1:3t1z6ZfkFvirjFYBx9pHeHBuKoN/VBVk9yHb/m2Ll/k= -github.com/gonutz/w32 v1.0.0/go.mod h1:Rc/YP5K9gv0FW4p6X9qL3E7Y56lfMflEol1fLElfMW4= -github.com/gonutz/w32/v2 v2.9.0/go.mod h1:MgtHx0AScDVNKyB+kjyPder4xIi3XAcHS6LDDU2DmdE= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -183,8 +180,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd/go.mod h1:hPqNNc0+uJM6H+SuU8sEs5K5IQeKccPqeSjfgcKGgPk= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= -github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c h1:zqmyTlQyufRC65JnImJ6H1Sf7BDj8bG31EV919NVEQc= -github.com/spf13/pflag v1.0.6-0.20201009195203-85dd5c8bc61c/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace h1:9PNP1jnUjRhfmGMlkXHjYPishpcw4jpSt/V/xYY3FMA= github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/main.go b/main.go index 52c6baa3..4f23fbe5 100644 --- a/main.go +++ b/main.go @@ -10,11 +10,8 @@ import ( // Keep it simple. func main() { - ui.HideConsoleWindow() - defer func() { if r := recover(); r != nil { - ui.ShowConsoleWindow() log.Printf("[PANIC] %v\n%s", r, string(debug.Stack())) } }() diff --git a/pkg/ui/ui_darwin.go b/pkg/ui/ui_darwin.go index adf5db8d..e79ce7b9 100644 --- a/pkg/ui/ui_darwin.go +++ b/pkg/ui/ui_darwin.go @@ -16,12 +16,6 @@ func HasGUI() bool { return hasGUI } -// HideConsoleWindow does nothing on OSes besides Windows. -func HideConsoleWindow() {} - -// ShowConsoleWindow does nothing on OSes besides Windows. -func ShowConsoleWindow() {} - // StartCmd starts a command. func StartCmd(c string, v ...string) error { cmd := exec.Command(c, v...) diff --git a/pkg/ui/ui_other.go b/pkg/ui/ui_other.go index c4654a19..0d7630db 100644 --- a/pkg/ui/ui_other.go +++ b/pkg/ui/ui_other.go @@ -17,12 +17,6 @@ func HasGUI() bool { return false } -// HideConsoleWindow does nothing on OSes besides Windows. -func HideConsoleWindow() {} - -// ShowConsoleWindow does nothing on OSes besides Windows. -func ShowConsoleWindow() {} - // StartCmd starts a command. func StartCmd(c string, v ...string) error { cmd := exec.Command(c, v...) diff --git a/pkg/ui/ui_windows.go b/pkg/ui/ui_windows.go index 2ec8e9c0..94e53fba 100644 --- a/pkg/ui/ui_windows.go +++ b/pkg/ui/ui_windows.go @@ -7,8 +7,6 @@ import ( "os/exec" "strings" "syscall" - - "github.com/gonutz/w32" ) // SystrayIcon is the icon in the system tray or task bar. @@ -20,26 +18,6 @@ func HasGUI() bool { return hasGUI } -// HideConsoleWindow hides the windows console window. -func HideConsoleWindow() { - if console := w32.GetConsoleWindow(); console != 0 { - _, consoleProcID := w32.GetWindowThreadProcessId(console) - if w32.GetCurrentProcessId() == consoleProcID { - w32.ShowWindowAsync(console, w32.SW_HIDE) - } - } -} - -// ShowConsoleWindow does nothing on OSes besides Windows. -func ShowConsoleWindow() { - if console := w32.GetConsoleWindow(); console != 0 { - _, consoleProcID := w32.GetWindowThreadProcessId(console) - if w32.GetCurrentProcessId() == consoleProcID { - w32.ShowWindowAsync(console, w32.SW_SHOW) - } - } -} - // StartCmd starts a command. func StartCmd(c string, v ...string) error { cmd := exec.Command(c, v...) From cad651e2f1c34e0cf266e6b5bc4713d2aea1f833 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Fri, 26 May 2023 00:05:31 -0700 Subject: [PATCH 2/2] create config file in docker if /config exists --- pkg/unpackerr/cnfgfile.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/unpackerr/cnfgfile.go b/pkg/unpackerr/cnfgfile.go index 8cca0b8f..993275d4 100644 --- a/pkg/unpackerr/cnfgfile.go +++ b/pkg/unpackerr/cnfgfile.go @@ -25,7 +25,9 @@ const ( func (u *Unpackerr) unmarshalConfig() (uint64, uint64, string, error) { var f, msg string + // Load up the default file path and a list of alternate paths. def, cfl := configFileLocactions() + // Search for one, starting with the default. for _, f = range append([]string{u.Flags.ConfigFile}, cfl...) { d, err := homedir.Expand(f) if err == nil { @@ -33,12 +35,13 @@ func (u *Unpackerr) unmarshalConfig() (uint64, uint64, string, error) { } if _, err := os.Stat(f); err == nil { - break + break // found one, bail out. } // else { u.Print("rip:", err) } f = "" } + // it's possible to get here with or without a file found. msg = msgNoConfigFile if f != "" { @@ -93,6 +96,7 @@ func configFileLocactions() (string, []string) { case "android", "dragonfly", "linux", "nacl", "plan9", "solaris": fallthrough default: + // Adding a default here, or to freebsd changes the behavior of createConfigFile, so don't. return "", []string{ "/etc/unpackerr/unpackerr.conf", "/config/unpackerr.conf", @@ -161,8 +165,16 @@ func (u *Unpackerr) validateConfig() (uint64, uint64) { //nolint:cyclop return fm, dm } +// createConfigFile attempts to avoid creating a config file on linux or freebsd. +// It used to avoid it when running on macos from homebrew, but not anymore. func (u *Unpackerr) createConfigFile(file string) (string, error) { - if !ui.HasGUI() { + if isRunningInDocker() { + if stat, err := os.Stat("/config"); err == nil && stat.IsDir() { + file = "/config/unpackerr.conf" + } + } + + if file == "" { return "", nil }