From de78b0f359092f9ed371f5ef0e719a825254d64e Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Wed, 5 Feb 2014 10:10:32 -0500 Subject: [PATCH] sleep during uninstall, allow :must_succeed on script directives. followups from #1802. amend private-eye Cask. --- CONTRIBUTING.md | 1 + Casks/private-eye.rb | 12 ++++++++++-- lib/cask/artifact/pkg.rb | 16 ++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 488ff29f3..30510b99b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -261,6 +261,7 @@ is the most useful. - `:executable` - relative path to an uninstall script to be run via sudo (required for hash form) - `:args` - array of arguments to the uninstall script - `:input` - array of lines of input to be sent to `stdin` of the script + - `:must_succeed` - set to `false` if the script is allowed to fail * `:files` (array) - absolute paths of files or directories to remove. `:files` should only be used as a last resort. `:pkgutil` is strongly preferred Each `uninstall` technique is applied according to the order above. The order diff --git a/Casks/private-eye.rb b/Casks/private-eye.rb index c71fdc540..245b669e2 100644 --- a/Casks/private-eye.rb +++ b/Casks/private-eye.rb @@ -4,6 +4,14 @@ class PrivateEye < Cask version 'latest' no_checksum install 'Private Eye.pkg' - # We have to try unloading the kext twice to work around a bug. See https://github.com/phinze/homebrew-cask/pull/1802#issuecomment-34171151 - uninstall :kext => ['com.radiosilenceapp.nke.PrivateEye', 'com.radiosilenceapp.nke.PrivateEye'], :pkgutil => 'com.radiosilenceapp.privateEye.*' + # We intentionally unload the kext twice as a workaround + # See https://github.com/phinze/homebrew-cask/pull/1802#issuecomment-34171151 + uninstall :early_script => { + :executable => '/sbin/kextunload', + :args => ['-b', 'com.radiosilenceapp.nke.PrivateEye'], + :must_succeed => false, + }, + :quit => 'com.radiosilenceapp.PrivateEye', + :kext => 'com.radiosilenceapp.nke.PrivateEye', + :pkgutil => 'com.radiosilenceapp.privateEye.*' end diff --git a/lib/cask/artifact/pkg.rb b/lib/cask/artifact/pkg.rb index 69ec9f1b4..1ad3f47a7 100644 --- a/lib/cask/artifact/pkg.rb +++ b/lib/cask/artifact/pkg.rb @@ -13,7 +13,7 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base end # key sanity - permitted_keys = [:args, :input, :executable] + permitted_keys = [:args, :input, :executable, :must_succeed] unknown_keys = script_arguments.keys - permitted_keys unless unknown_keys.empty? opoo "Unknown arguments to uninstall :#{key} -- :#{unknown_keys.join(", :")} (ignored). Running `brew update; brew upgrade brew-cask` will likely fix it.'" @@ -27,6 +27,10 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base executable = nil end + unless script_arguments.key?(:must_succeed) + script_arguments[:must_succeed] = true + end + script_arguments.merge!(:sudo => true, :print => true) return executable, script_arguments end @@ -64,7 +68,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base executable, script_arguments = self.class.read_script_arguments(uninstall_options, :early_script) ohai "Running uninstall script #{executable}" raise "Error in Cask #{@cask}: uninstall :early_script without :executable." if executable.nil? - @command.run!(@cask.destination_path.join(executable), script_arguments) + @command.run(@cask.destination_path.join(executable), script_arguments) + sleep 1 end # :launchctl must come before :quit for cases where app would instantly re-launch @@ -75,6 +80,7 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base xml_status = @command.run('/bin/launchctl', :args => ['list', '-x', service], :sudo => with_sudo) if %r{^<\?xml}.match(xml_status) @command.run!('/bin/launchctl', :args => ['remove', '--', service], :sudo => with_sudo) + sleep 1 end end end @@ -87,6 +93,7 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base num_running = @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application "System Events" to count processes whose bundle identifier is "#{id}"}], :sudo => true).to_i if num_running > 0 @command.run!('/usr/bin/osascript', :args => ['-e', %Q{tell application id "#{id}" to quit}], :sudo => true) + sleep 3 end end end @@ -98,6 +105,7 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base is_loaded = @command.run!('/usr/sbin/kextstat', :args => ['-l', '-b', kext], :sudo => true) if is_loaded.length > 1 @command.run!('/sbin/kextunload', :args => ['-b', '--', kext], :sudo => true) + sleep 1 end end end @@ -106,7 +114,8 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base if uninstall_options.key? :script executable, script_arguments = self.class.read_script_arguments(uninstall_options, :script) raise "Error in Cask #{@cask}: uninstall :script without :executable." if executable.nil? - @command.run!(@cask.destination_path.join(executable), script_arguments) + @command.run(@cask.destination_path.join(executable), script_arguments) + sleep 1 end if uninstall_options.key? :pkgutil @@ -123,4 +132,3 @@ class Cask::Artifact::Pkg < Cask::Artifact::Base end end end -