Class: C0Setup
- Inherits:
-
Object
- Object
- C0Setup
- Defined in:
- lib/c0_setup.rb
Instance Method Summary collapse
-
#check_precedence ⇒ Object
check for things that don’t exist yet.
-
#create_runpath ⇒ Object
create folder for binaries and set executable path.
- #install_cc0 ⇒ Object
- #install_coin ⇒ Object
-
#setup ⇒ Object
do the setup yo.
- #which(cmd) ⇒ Object
Instance Method Details
#check_precedence ⇒ Object
check for things that don’t exist yet
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/c0_setup.rb', line 45 def check_precedence Dir.chdir(File.("~")) do not_yet = [] if which("cc0").nil? not_yet.push("cc0") end if which("coin").nil? not_yet.push("coin") end if !Dir.exist?(".c0") not_yet.push("runpath") end return not_yet end end |
#create_runpath ⇒ Object
create folder for binaries and set executable path
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/c0_setup.rb', line 62 def create_runpath Dir.chdir(File.("~")) do Dir.mkdir ".c0" File.new ".bashrc" unless File.exist? ".bashrc" File.open(".bashrc", "a") do |file| file.puts "export PATH=$PATH:~/.c0" end in_path = File.open(".bashrc", "r").read.include? "export PATH=$PATH:~/.c0" return (in_path and Dir.exist? ".c0") end end |
#install_cc0 ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/c0_setup.rb', line 74 def install_cc0 # copy the cc0 binary to "~/.c0" user = File.("~") Dir.chdir(File.dirname __dir__) do FileUtils.cp("./cc0", "#{user}/.c0") end return File.exist?("#{user}/.c0/cc0") end |
#install_coin ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/c0_setup.rb', line 83 def install_coin # copy the coin binary to "~/.c0" user = File.("~") Dir.chdir(File.dirname __dir__) do FileUtils.cp("./coin", "#{user}/.c0") end return File.exist?("#{user}/.c0/coin") end |
#setup ⇒ Object
do the setup yo
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/c0_setup.rb', line 9 def setup to_do = check_precedence() result = [] if to_do.include? "runpath" if create_runpath result.push "successfully created runpath" else result.push "failed to create runpath" return result end else result.push ".c0 folder already exists, remove it and retry if broken" return result end if to_do.include? "cc0" if install_cc0 result.push "successfully installed cc0" else result.push "failed to install cc0" end else result.push "cc0 is already installed somewhere, remove it and retry if broken" end if to_do.include? "coin" if install_coin result.push "successfully installed coin" else result.push "failed to install coin" end else result.push "cc0 is already installed somewhere, remove it and retry if broken" end return result end |
#which(cmd) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/c0_setup.rb', line 92 def which(cmd) # check for the presence of a binary in $PATH exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end return nil end |