Class: Coffer::Installer
- Inherits:
-
Object
- Object
- Coffer::Installer
- Defined in:
- lib/coffer/installer.rb
Constant Summary collapse
- CACHE_DIR =
'/opt/coffer/cache'- BIN_DIR =
'/opt/coffer/bin'
Instance Attribute Summary collapse
-
#coin ⇒ Object
readonly
Returns the value of attribute coin.
Instance Method Summary collapse
- #built_executable_path ⇒ Object
- #built_executable_valid? ⇒ Boolean
- #check_results ⇒ Object
-
#clone ⇒ Object
clone a repo to the correct directory if the directory already exists and is a git repo then do nothing.
- #config_path ⇒ Object
- #copy_built_executable ⇒ Object
- #create_config ⇒ Object
- #create_directories ⇒ Object
-
#initialize(coin) ⇒ Installer
constructor
A new instance of Installer.
- #install ⇒ Object
- #installed_executable_path ⇒ Object
- #make ⇒ Object
- #makefile_name ⇒ Object
- #mkdir(path, mode = 0700) ⇒ Object
-
#pull ⇒ Object
pull the latest changes and ensure we have the correct ref checked out.
- #repo_path ⇒ Object
- #start ⇒ Object
-
#update_repo ⇒ Object
ensure that this git repo is running the latest version and is cloned and all that.
- #wallet_home_directory ⇒ Object
Constructor Details
#initialize(coin) ⇒ Installer
Returns a new instance of Installer.
11 12 13 |
# File 'lib/coffer/installer.rb', line 11 def initialize( coin ) @coin = coin end |
Instance Attribute Details
#coin ⇒ Object (readonly)
Returns the value of attribute coin.
9 10 11 |
# File 'lib/coffer/installer.rb', line 9 def coin @coin end |
Instance Method Details
#built_executable_path ⇒ Object
175 176 177 |
# File 'lib/coffer/installer.rb', line 175 def built_executable_path File.join repo_path, 'src', @coin.wallet_executable end |
#built_executable_valid? ⇒ Boolean
179 180 181 182 |
# File 'lib/coffer/installer.rb', line 179 def built_executable_valid? File.exists?( built_executable_path ) \ && File.executable?( built_executable_path ) end |
#check_results ⇒ Object
118 119 120 |
# File 'lib/coffer/installer.rb', line 118 def check_results raise "Build failed. No executable!" unless built_executable_valid? end |
#clone ⇒ Object
clone a repo to the correct directory if the directory already exists and is a git repo then do nothing.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/coffer/installer.rb', line 43 def clone return false if File.directory?( repo_path ) warn "Cloning repo... #{repo_path}" g = Git.clone( coin.git_repo, File.basename(repo_path), :path => File.dirname(repo_path) ) g.checkout @coin.git_branch true end |
#config_path ⇒ Object
110 111 112 |
# File 'lib/coffer/installer.rb', line 110 def config_path File.join( wallet_home_directory, @coin.config_file ) end |
#copy_built_executable ⇒ Object
85 86 87 |
# File 'lib/coffer/installer.rb', line 85 def copy_built_executable FileUtils.cp built_executable_path, installed_executable_path end |
#create_config ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/coffer/installer.rb', line 97 def create_config if File.exists?( config_path ) puts "Not creating config. (#{ config_path })" return end File.open( config_path , 'w' ) do |f| f.write @coin.build_config.to_config end FileUtils.chmod 0600, config_path end |
#create_directories ⇒ Object
89 90 91 |
# File 'lib/coffer/installer.rb', line 89 def create_directories mkdir wallet_home_directory, 0700 end |
#install ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/coffer/installer.rb', line 15 def install mkdir CACHE_DIR, 0755 mkdir BIN_DIR, 0755 update_repo # preconfigure Dir.chdir( File.join( repo_path, @coin.build_dir) ) do mkdir 'obj', 0755 make check_results end copy_built_executable create_directories create_config end |
#installed_executable_path ⇒ Object
171 172 173 |
# File 'lib/coffer/installer.rb', line 171 def installed_executable_path File.join BIN_DIR, @coin.wallet_executable end |
#make ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/coffer/installer.rb', line 122 def make if @coin.build.nil? cmd = "make -f '#{ makefile_name }'" puts `#{cmd}` retval = $? if retval != 0 warn "ERROR from command: (#{ cmd }): #{ retval }" end else @coin.build.split("\n").each do |cmd| cmd = cmd.strip puts "EXEC> #{ cmd }" puts `#{cmd}` retval = $? if retval != 0 warn "ERROR from command (#{cmd}): #{ retval }" return false end end end true end |
#makefile_name ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/coffer/installer.rb', line 149 def makefile_name sys = `uname`.chomp.downcase if sys == 'darwin' 'makefile.osx' elsif sys == 'linux' 'makefile.unix' end end |
#mkdir(path, mode = 0700) ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/coffer/installer.rb', line 159 def mkdir( path, mode=0700 ) begin FileUtils.mkdir_p path, :mode => mode rescue Errno::EEXIST #pass end end |
#pull ⇒ Object
pull the latest changes and ensure we have the correct ref checked out.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/coffer/installer.rb', line 57 def pull raise "Not a git repository! (#{ repo_path })" unless File.directory?( repo_path ) warn "Updating repo... #{repo_path}" g = Git.open( repo_path, :logger => Logger.new(STDOUT) ) # store the current SHA1 old_sha = g.object('HEAD').sha # ensure the remote is configured as expected if g.remote.url != coin.git_repo g.remove_remote 'origin' g.add_remote 'origin', coin.git_repo, :fetch => true end # make sure the tree is clean g.reset_hard g.clean :force => true, :d => true # fetch data from remote, checkout the right branch and merge into local branch g.checkout @coin.git_branch g.pull('origin', @coin.git_branch) # check if there are any changes. old_sha != g.object('HEAD').sha end |
#repo_path ⇒ Object
167 168 169 |
# File 'lib/coffer/installer.rb', line 167 def repo_path File.join CACHE_DIR, @coin.name end |
#start ⇒ Object
114 115 116 |
# File 'lib/coffer/installer.rb', line 114 def start `#{ installed_executable_path } -daemon` end |
#update_repo ⇒ Object
ensure that this git repo is running the latest version and is cloned and all that
36 37 38 |
# File 'lib/coffer/installer.rb', line 36 def update_repo [ clone, pull ].count { |i| i } > 0 end |
#wallet_home_directory ⇒ Object
93 94 95 |
# File 'lib/coffer/installer.rb', line 93 def wallet_home_directory File.("~/.#{ @coin.directory }") end |