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.
-
#get_os ⇒ Object
figure out the os.
-
#install_lib ⇒ Object
copy the c0 lib to “~/.c0” (OS specific).
-
#setup ⇒ Object
do the setup yo.
-
#which(cmd) ⇒ Object
check for the presence of a binary in $PATH.
Instance Method Details
#check_precedence ⇒ Object
check for things that don’t exist yet
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/c0_setup.rb', line 37 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
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/c0_setup.rb', line 54 def create_runpath Dir.chdir(File.("~")) do Dir.mkdir ".c0" File.new("#{File.expand_path("~")}/.bashrc", "w+") unless File.exist? ".bashrc" File.open(".bashrc", "a") do |file| file.puts "export PATH=$PATH:~/.c0/bin" end in_path = File.open(".bashrc", "r").read.include? "export PATH=$PATH:~/.c0/bin" return (in_path and Dir.exist? ".c0") end end |
#get_os ⇒ Object
figure out the os
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/c0_setup.rb', line 90 def get_os result = "" os = RbConfig::CONFIG['host_os'] if os.downcase.include?('linux') result = 'linux' elsif os.downcase.include?('darwin') result = 'darwin' end return result end |
#install_lib ⇒ Object
copy the c0 lib to “~/.c0” (OS specific)
66 67 68 69 70 71 72 73 74 |
# File 'lib/c0_setup.rb', line 66 def install_lib user = File.("~") if get_os == "darwin" `tar -xvzf #{File.expand_path(File.dirname __dir__)}/c0_mac.tar.gz -C #{user}/.c0` elsif get_os == "linux" `tar -xvzf #{File.expand_path(File.dirname __dir__)}/c0_linux.tar.gz -C #{user}/.c0` end return (File.exist?("#{user}/.c0/bin/cc0") and File.exist?("#{user}/.c0/bin/coin")) end |
#setup ⇒ Object
do the setup yo
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 |
# File 'lib/c0_setup.rb', line 10 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" and to_do.include? "coin" if install_lib result.push "successfully installed cc0 and coin" else result.push "failed to install cc0 and coin" end else result.push "coin or cc0 is already installed somewhere, remove it and retry if broken" end end |
#which(cmd) ⇒ Object
check for the presence of a binary in $PATH
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/c0_setup.rb', line 78 def which(cmd) 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 |