Top Level Namespace
Instance Method Summary collapse
- #add_line_to_file(file, line, regex = nil) ⇒ Object
- #get_datadir ⇒ Object
- #install_brew(app, opts = '') ⇒ Object
- #install_cask(app) ⇒ Object
- #install_file(file, destination) ⇒ Object
- #mkdir(dir) ⇒ Object
- #run_cmd(cmd, msg) ⇒ Object
- #uninstall_brew(app) ⇒ Object
Instance Method Details
#add_line_to_file(file, line, regex = nil) ⇒ Object
71 72 73 74 |
# File 'lib/ahalogy/install-helper.rb', line 71 def add_line_to_file(file, line, regex = nil) regex = Regexp.escape(line) if regex == nil run_cmd "grep '#{regex}' #{file} --quiet || echo '#{line}' >> #{file}", "Updating #{file}..." end |
#get_datadir ⇒ Object
5 6 7 8 9 |
# File 'lib/ahalogy/install-helper.rb', line 5 def get_datadir datadir = Gem.datadir('ahalogy-automation') datadir = File.join(File.dirname(__FILE__), '../../data/ahalogy-automation') if datadir== nil return datadir end |
#install_brew(app, opts = '') ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ahalogy/install-helper.rb', line 18 def install_brew(app, opts = '') %x[brew list #{app}] if $? == 0 puts "(brew) #{app} already installed...skipped.".colorize(:green) else puts "(brew) install #{app} #{opts}".colorize(:blue) system 'brew', 'install', app, opts abort 'FAILED.' if $? != 0 end end |
#install_cask(app) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ahalogy/install-helper.rb', line 40 def install_cask(app) %x[brew cask list #{app}] if $? == 0 puts "(cask) #{app} already installed...skipped.".colorize(:green) else puts "(cask) install #{app}".colorize(:blue) system 'brew', 'cask', 'install', app abort 'FAILED.' if $? != 0 end end |
#install_file(file, destination) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ahalogy/install-helper.rb', line 51 def install_file(file, destination) file = File.join(get_datadir, file) if not File.readable? file puts "(file) Attempted to install #{file} but the file was not found.".colorize(:red) return false end destination = File.(destination) filemd5 = Digest::MD5.file(file).hexdigest destmd5 = '' if File.readable? destination destmd5 = Digest::MD5.file(destination).hexdigest end if filemd5 == destmd5 puts "(file) #{file} and #{destination} are the same file...skipped.".colorize(:green) else puts "(file) Copying #{file} to #{destination}...".colorize(:blue) FileUtils.cp file, destination end end |
#mkdir(dir) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ahalogy/install-helper.rb', line 76 def mkdir(dir) dir = File. dir if File.exists? dir if File.directory? dir puts "(mkdir) The directory #{dir} already exists...skipped.".colorize(:green) else fail "(mkdir) ERROR: Trying to create directory but file already exists at #{dir}".colorize(:red) end else puts "(mkdir) Creating directory #{dir}...".colorize(:blue) FileUtils.mkdir dir end end |
#run_cmd(cmd, msg) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/ahalogy/install-helper.rb', line 11 def run_cmd(cmd, msg) puts msg puts "(cmd) '#{cmd}'".colorize(:blue) system cmd abort 'FAILED.' if $? != 0 end |
#uninstall_brew(app) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ahalogy/install-helper.rb', line 29 def uninstall_brew(app) %x[brew list #{app}] if $? != 0 puts "(brew) #{app} is not installed...skipped.".colorize(:green) else puts "(brew-uninstall) uninstall #{app}".colorize(:blue) system 'brew', 'uninstall', '--force', app abort 'FAILED.' if $? != 0 end end |