From 5140c741f3544390972af45dfa64aa35f7aa7c9e Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Fri, 13 Oct 2017 13:26:14 -0500 Subject: [PATCH 1/3] caveats.rb: empty method on Linux --- Library/Homebrew/extend/os/linux/caveats.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Library/Homebrew/extend/os/linux/caveats.rb diff --git a/Library/Homebrew/extend/os/linux/caveats.rb b/Library/Homebrew/extend/os/linux/caveats.rb new file mode 100644 index 0000000000..f30aead87e --- /dev/null +++ b/Library/Homebrew/extend/os/linux/caveats.rb @@ -0,0 +1,3 @@ +class Caveats + def plist_caveats; end +end From 336fbb5db2aa349022dae6892cab63a6dad4f2e1 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 16 Oct 2017 11:15:54 -0500 Subject: [PATCH 2/3] caveats: making plist_caveats macOS-only --- Library/Homebrew/caveats.rb | 46 ++------------------- Library/Homebrew/extend/os/caveats.rb | 1 + Library/Homebrew/extend/os/linux/caveats.rb | 3 -- Library/Homebrew/extend/os/mac/caveats.rb | 46 +++++++++++++++++++++ 4 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 Library/Homebrew/extend/os/caveats.rb delete mode 100644 Library/Homebrew/extend/os/linux/caveats.rb create mode 100644 Library/Homebrew/extend/os/mac/caveats.rb diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 1849ea79b3..ef80283394 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -161,49 +161,7 @@ class Caveats EOS end - def plist_caveats - s = [] - if f.plist || (keg&.plist_installed?) - plist_domain = f.plist_path.basename(".plist") - - # we readlink because this path probably doesn't exist since caveats - # occurs before the link step of installation - # Yosemite security measures mildly tighter rules: - # https://github.com/Homebrew/legacy-homebrew/issues/33815 - if !plist_path.file? || !plist_path.symlink? - if f.plist_startup - s << "To have launchd start #{f.full_name} now and restart at startup:" - s << " sudo brew services start #{f.full_name}" - else - s << "To have launchd start #{f.full_name} now and restart at login:" - s << " brew services start #{f.full_name}" - end - # For startup plists, we cannot tell whether it's running on launchd, - # as it requires for `sudo launchctl list` to get real result. - elsif f.plist_startup - s << "To restart #{f.full_name} after an upgrade:" - s << " sudo brew services restart #{f.full_name}" - elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" - s << "To restart #{f.full_name} after an upgrade:" - s << " brew services restart #{f.full_name}" - else - s << "To start #{f.full_name}:" - s << " brew services start #{f.full_name}" - end - - if f.plist_manual - s << "Or, if you don't want/need a background service you can just run:" - s << " #{f.plist_manual}" - end - - # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default - # check if this is being run under `tmux` to avoid failing - if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") - s << "" << "WARNING: brew services will fail when run under tmux." - end - end - s.join("\n") + "\n" unless s.empty? - end + def plist_caveats; end def plist_path destination = if f.plist_startup @@ -222,3 +180,5 @@ class Caveats destination_path/plist_filename end end + +require "extend/os/caveats" diff --git a/Library/Homebrew/extend/os/caveats.rb b/Library/Homebrew/extend/os/caveats.rb new file mode 100644 index 0000000000..e67138087b --- /dev/null +++ b/Library/Homebrew/extend/os/caveats.rb @@ -0,0 +1 @@ +require "extend/os/mac/caveats" if OS.mac? diff --git a/Library/Homebrew/extend/os/linux/caveats.rb b/Library/Homebrew/extend/os/linux/caveats.rb deleted file mode 100644 index f30aead87e..0000000000 --- a/Library/Homebrew/extend/os/linux/caveats.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Caveats - def plist_caveats; end -end diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb new file mode 100644 index 0000000000..2398b1a81a --- /dev/null +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -0,0 +1,46 @@ +class Caveats + def plist_caveats + s = [] + if f.plist || (keg&.plist_installed?) + plist_domain = f.plist_path.basename(".plist") + + # we readlink because this path probably doesn't exist since caveats + # occurs before the link step of installation + # Yosemite security measures mildly tighter rules: + # https://github.com/Homebrew/legacy-homebrew/issues/33815 + if !plist_path.file? || !plist_path.symlink? + if f.plist_startup + s << "To have launchd start #{f.full_name} now and restart at startup:" + s << " sudo brew services start #{f.full_name}" + else + s << "To have launchd start #{f.full_name} now and restart at login:" + s << " brew services start #{f.full_name}" + end + # For startup plists, we cannot tell whether it's running on launchd, + # as it requires for `sudo launchctl list` to get real result. + elsif f.plist_startup + s << "To restart #{f.full_name} after an upgrade:" + s << " sudo brew services restart #{f.full_name}" + elsif Kernel.system "/bin/launchctl list #{plist_domain} &>/dev/null" + s << "To restart #{f.full_name} after an upgrade:" + s << " brew services restart #{f.full_name}" + else + s << "To start #{f.full_name}:" + s << " brew services start #{f.full_name}" + end + + if f.plist_manual + s << "Or, if you don't want/need a background service you can just run:" + s << " #{f.plist_manual}" + end + + # pbpaste is the system clipboard tool on macOS and fails with `tmux` by default + # check if this is being run under `tmux` to avoid failing + if ENV["TMUX"] && !quiet_system("/usr/bin/pbpaste") + s << "" << "WARNING: brew services will fail when run under tmux." + end + end + s.join("\n") + "\n" unless s.empty? + end + +end From dd9415c8d3c07b4fa2ac066e867297ff06c64568 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Mon, 16 Oct 2017 12:23:27 -0500 Subject: [PATCH 3/3] remove sneaky empty line --- Library/Homebrew/extend/os/mac/caveats.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index 2398b1a81a..d912a83075 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -42,5 +42,4 @@ class Caveats end s.join("\n") + "\n" unless s.empty? end - end