diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 996896a..9d48e8a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -237,9 +237,12 @@ homebrew_casks: previous = system_command "/usr/bin/plutil", args: ["-convert", "json", "-o", "-", File.expand_path("~/Library/LaunchAgents/run.driga.service.plist")], must_succeed: true - system_command "#{appdir}/Driga.app/Contents/MacOS/driga", - args: ["service", "install"], - env: JSON.parse(previous.stdout).fetch("EnvironmentVariables", {}), + # system_command shell-escapes env: values yet runs no shell, so a + # value with a space would gain a literal backslash. /usr/bin/env + # takes these assignments verbatim. + environment = JSON.parse(previous.stdout).fetch("EnvironmentVariables", {}).map { |name, value| "#{name}=#{value}" } + system_command "/usr/bin/env", + args: [*environment, "#{appdir}/Driga.app/Contents/MacOS/driga", "service", "install"], must_succeed: true end end diff --git a/scripts/macos_app_test.go b/scripts/macos_app_test.go index 8f13f78..64eb386 100644 --- a/scripts/macos_app_test.go +++ b/scripts/macos_app_test.go @@ -252,7 +252,7 @@ def appdir; "/Applications"; end def postflight; yield; end def system_command(name, **opts) $calls << [name, opts] - Struct.new(:stdout).new('{"EnvironmentVariables":{"DRIGA_DATA_DIR":"/custom/data","PATH":"/custom/bin:/usr/bin"}}') + Struct.new(:stdout).new('{"EnvironmentVariables":{"DRIGA_DATA_DIR":"/Users/me/Library/Application Support/driga","PATH":"/custom/bin:/usr/bin"}}') end class File def self.exist?(path) @@ -264,7 +264,8 @@ end check := ` if ENV["EXISTING_SERVICE"] == "true" raise "plist not read" unless $calls.length == 2 && $calls[0] == ["/usr/bin/plutil", {args: ["-convert", "json", "-o", "-", File.expand_path("~/Library/LaunchAgents/run.driga.service.plist")], must_succeed: true}] - expected = ["/Applications/Driga.app/Contents/MacOS/driga", {args: ["service", "install"], env: {"DRIGA_DATA_DIR" => "/custom/data", "PATH" => "/custom/bin:/usr/bin"}, must_succeed: true}] + # env: would reach the service as "Application\\ Support"; /usr/bin/env args do not. + expected = ["/usr/bin/env", {args: ["DRIGA_DATA_DIR=/Users/me/Library/Application Support/driga", "PATH=/custom/bin:/usr/bin", "/Applications/Driga.app/Contents/MacOS/driga", "service", "install"], must_succeed: true}] raise "environment or command changed: #{$calls}" unless $calls[1] == expected else raise "fresh install started service" unless $calls.empty? diff --git a/scripts/verify-release-dist.sh b/scripts/verify-release-dist.sh index a566871..6d7528a 100755 --- a/scripts/verify-release-dist.sh +++ b/scripts/verify-release-dist.sh @@ -169,9 +169,10 @@ if grep -Fq 'caskroom_path' "$cask"; then exit 1 fi if ! grep -Fq 'if File.exist?(File.expand_path("~/Library/LaunchAgents/run.driga.service.plist"))' "$cask" || - ! grep -Fq 'system_command "#{appdir}/Driga.app/Contents/MacOS/driga",' "$cask" || - ! grep -Fq 'args: ["service", "install"],' "$cask" || - ! grep -Fq 'env: JSON.parse(previous.stdout).fetch("EnvironmentVariables", {}),' "$cask"; then + ! grep -Fq 'environment = JSON.parse(previous.stdout).fetch("EnvironmentVariables", {}).map { |name, value| "#{name}=#{value}" }' "$cask" || + ! grep -Fq 'system_command "/usr/bin/env",' "$cask" || + ! grep -Fq 'args: [*environment, "#{appdir}/Driga.app/Contents/MacOS/driga", "service", "install"],' "$cask" || + grep -Fq 'env: JSON.parse' "$cask"; then echo "Homebrew Cask is missing the existing-service upgrade repair." >&2 exit 1 fi diff --git a/scripts/verify_release_dist_test.go b/scripts/verify_release_dist_test.go index 6a656cf..ac2cfb0 100644 --- a/scripts/verify_release_dist_test.go +++ b/scripts/verify_release_dist_test.go @@ -156,9 +156,9 @@ func releaseDistFixture(t *testing.T, version, tag string) (string, string) { previous = system_command "/usr/bin/plutil", args: ["-convert", "json", "-o", "-", File.expand_path("~/Library/LaunchAgents/run.driga.service.plist")], must_succeed: true - system_command "#{appdir}/Driga.app/Contents/MacOS/driga", - args: ["service", "install"], - env: JSON.parse(previous.stdout).fetch("EnvironmentVariables", {}), + environment = JSON.parse(previous.stdout).fetch("EnvironmentVariables", {}).map { |name, value| "#{name}=#{value}" } + system_command "/usr/bin/env", + args: [*environment, "#{appdir}/Driga.app/Contents/MacOS/driga", "service", "install"], must_succeed: true end end