From 9d05ec959059743f8bb7913821754dad49e28a09 Mon Sep 17 00:00:00 2001 From: Joshua Knarr Date: Thu, 14 Jan 2021 15:29:22 -0500 Subject: [PATCH] fixes for colors, shell safety --- Gemfile | 2 +- bin/install-buddy | 3 ++- lib/sysinfo.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index fc33954..46bd723 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,9 @@ source 'https://rubygems.org' gem 'net-ssh' gem 'ed25519' gem 'bcrypt_pbkdf' +gem 'tty-color' group :development do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'minitest' end - diff --git a/bin/install-buddy b/bin/install-buddy index a07ee31..2eeea23 100755 --- a/bin/install-buddy +++ b/bin/install-buddy @@ -1,6 +1,7 @@ #!/usr/bin/env ruby require 'optparse' require 'yaml' +require 'tty-color' require_relative '../lib/install_buddy' require_relative '../lib/sysinfo' require_relative '../lib/distro_support' @@ -15,7 +16,7 @@ packagelist_file = InstallBuddy.get_option(:packagelist) abort(Utils::colorize("#{InstallBuddy.get_usage}. Type `install-buddy -h` for more details", :yellow)) if packagelist_file.nil? # Check if running as root -abort(Utils::colorize('install-buddy must be run as root!', :red)) unless InstallBuddy.get_option(:remote) || `id -u`.chomp == '0' +abort(Utils::colorize('install-buddy must be run as root!', :red)) unless InstallBuddy.get_option(:remote) || Process.uid == '0' abort(Utils::colorize("File not found or is unreadable!", :red)) if !File.readable?(packagelist_file) diff --git a/lib/sysinfo.rb b/lib/sysinfo.rb index 692ff6e..b9cc295 100644 --- a/lib/sysinfo.rb +++ b/lib/sysinfo.rb @@ -8,7 +8,7 @@ def initialize end def self.term_supports_color? - @colors ||= `env tput colors 2>/dev/null`.chomp + @colors ||= TTY::Color.mode @colors.to_i > 8 end