From a87dcb305d6de9dd8857b22223f6fd0635b9db67 Mon Sep 17 00:00:00 2001 From: "Satadru Pramanik, DO, MPH, MEng" Date: Mon, 30 Oct 2023 13:19:19 -0400 Subject: [PATCH] Add exitmessages (#8851) * Add exitmessages * bump version * Use ExitMessage.new in fixup.rb * Use ExitMessage.new in sommelier.rb * use color for message * style adjustment * change to @supechicken suggested code * bump version back --- bin/crew | 19 +++++++++++++++++++ lib/const.rb | 2 +- lib/fixup.rb | 3 +-- packages/sommelier.rb | 15 +++++---------- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/bin/crew b/bin/crew index 8b18b9391..68c30b575 100755 --- a/bin/crew +++ b/bin/crew @@ -124,6 +124,21 @@ String.use_color = args['--color'] || !args['--no-color'] @verbose = @opt_verbose ? 'v' : '' @short_verbose = @opt_verbose ? '-v' : '' +class ExitMessage + @messages = [] + + def self.add(msg, print_last: false) + # add an option to allow important messages (like sommelier) to print at the bottom + @messages << [msg.lightcyan, print_last] + end + + def self.print # print all messages + # &:last represent to print_last + puts @messages.reject(&:last).map(&:first) + puts @messages.select(&:last).map(&:first) + end +end + def load_json # load_json(): (re)load device.json json_path = File.join(CREW_CONFIG_PATH, 'device.json') @@ -2000,3 +2015,7 @@ end load_json command_name = args.select { |k, v| v && is_command(k) }.keys[0] send("#{command_name}_command", args) + +# Print exit messages. +ExitMessage.add 'Crew is exiting.' if @opt_verbose +ExitMessage.print diff --git a/lib/const.rb b/lib/const.rb index e8904afbd..e0531c16b 100644 --- a/lib/const.rb +++ b/lib/const.rb @@ -1,6 +1,6 @@ # lib/const.rb # Defines common constants used in different parts of crew -CREW_VERSION = '1.37.3' +CREW_VERSION = '1.37.4' # kernel architecture KERN_ARCH = `uname -m`.chomp diff --git a/lib/fixup.rb b/lib/fixup.rb index d15fabbd9..9285f33f3 100644 --- a/lib/fixup.rb +++ b/lib/fixup.rb @@ -6,12 +6,11 @@ FileUtils.rm_rf "#{HOME}/.cache/crewcache/manifest" # Fix missing $PATH not added in install.sh if !system("grep -q '$PATH' #{CREW_PREFIX}/etc/env.d/path") || Gem::Version.new(CREW_VERSION.to_s) < Gem::Version.new('1.36.4') - puts 'Fixing path env.d file...'.orange - puts "Please run 'source ~/.bashrc'".lightblue File.write "#{CREW_PREFIX}/etc/env.d/path", <<~ENVD_PATH_EOF ## Inserted by Chromebrew version #{CREW_VERSION} PATH=#{CREW_PREFIX}/bin:#{CREW_PREFIX}/sbin:#{CREW_PREFIX}/share/musl/bin:$PATH ENVD_PATH_EOF + ExitMessage.add "Fixed path env.d file...\nPlease run 'source ~/.bashrc'".orange end # Check for renamed and deprecated packages, and handle them. diff --git a/packages/sommelier.rb b/packages/sommelier.rb index a4a19a7c4..0534de1b7 100644 --- a/packages/sommelier.rb +++ b/packages/sommelier.rb @@ -460,7 +460,7 @@ class Sommelier < Package if FileUtils.identical?("#{HOME}/.bashrc", "#{HOME}/.bashrc.#{@now}") FileUtils.rm "#{HOME}/.bashrc.#{@now}" else - puts <<~EOT0.lightblue + ExitMessage.add <<~EOT0.lightblue Removed old sommelier environment variables in ~/.bashrc. A backup of the original is stored in ~/.bashrc.#{@now} @@ -470,15 +470,10 @@ class Sommelier < Package end FileUtils.touch "#{HOME}/.sommelier.env" unless File.exist? "#{HOME}/.sommelier.env" - puts <<~EOT1.lightblue + ExitMessage.add <<~EOT1.lightblue The default environment is stored in #{CREW_PREFIX}/etc/env.d/sommelier. - EOT1 - - puts <<~EOT2.orange DO NOT EDIT THIS FILE SINCE UPDATES WILL OVERWRITE YOUR CHANGES. - EOT2 - puts <<~EOT1.lightblue To override environment variables set above, edit ~/.sommelier.env instead. Information about those environment variables may be found on the Chromebrew wiki: https://github.com/chromebrew/chromebrew/wiki @@ -487,7 +482,7 @@ class Sommelier < Package To stop the sommelier daemon, run 'stopsommelier' To restart the sommelier daemon, run 'restartsommelier' EOT1 - puts <<~EOT2.orange + ExitMessage.add <<~EOT2.orange Please be aware that gui applications may not work without the sommelier daemon running. @@ -500,9 +495,9 @@ class Sommelier < Package Please open a github issue at https://github.com/chromebrew/chromebrew/issues/new/choose with the output of both - readlink -f "/sys/class/drm/renderD129/device/driver" + readlink -f '/sys/class/drm/renderD129/device/driver' and - readlink -f "/sys/class/drm/renderD128/device/driver" + readlink -f '/sys/class/drm/renderD128/device/driver' if sommelier does not start properly on your arm ChromeOS device. EOT2 end