cardano-up 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 630dda3bb909a92e0fa63562f5aff0f90afa817c8f5170f7567bcf059a962f2e
4
- data.tar.gz: c37378163253bb7945188c3a8794d6e01d638a0a4a053e887347b9aef5046a48
3
+ metadata.gz: 7dc6e5153ea10a283c8076a763034d89334e0ec285265ce8fa47cb7d41dddbaa
4
+ data.tar.gz: fc58a1646113ff3c52faaadb6807f1147029a4716d06b750f07783041eac4149
5
5
  SHA512:
6
- metadata.gz: 7e84594cee7e1fe4716f78c58f1deb39676f0d3ff3d7a721af055d13b6e627e96085dbceabda516665036f0137393121a29176df07bef07c9120872d680013b5
7
- data.tar.gz: 602b2379f4fd6a2dad86f2f4234ca4c3e7492cb194f73a95e60675f40d502e9dcaef2e3dc37532ae5ccd8b19a48eeddc96d1bd93f1197cceeda64451dd49f10d
6
+ metadata.gz: e098510d7c479a9d1570c1f9ba803875908b509365b556045c8530f1548e13356593592c3985c30d6711c84c2afd077b54cd417bf5eba0505590bb9b1b6fb30d
7
+ data.tar.gz: 54d8a545a3f1ebdea7cca06829672c337de7eac3403469d6ed33033869e7e08431b86dd495be49def0359063d004c0a363fdba397a8cd69ef4852d852582aa92
data/README.md CHANGED
@@ -2,9 +2,6 @@
2
2
  <a href="https://badge.fury.io/rb/cardano-up">
3
3
  <img src="https://badge.fury.io/rb/cardano-up.svg" alt="Gem Version">
4
4
  </a>
5
- <a href="https://github.com/piotr-iohk/cardano-up/releases">
6
- <img src="https://img.shields.io/github/release/piotr-iohk/cardano-up.svg" />
7
- </a>
8
5
  <a href="https://github.com/piotr-iohk/cardano-up/actions?query=workflow%3ATests">
9
6
  <img src="https://github.com/piotr-iohk/cardano-up/workflows/Tests/badge.svg" />
10
7
  </a>
@@ -32,21 +29,26 @@ This Ruby gem provides easy way for:
32
29
 
33
30
  It only takes a single command to start node and wallet on your system. Say, on `mainnet`?
34
31
 
35
- $ cardano-up mainnet node-wallet up
32
+ $ cardano-up mainnet up
36
33
 
37
34
  That's it! 🎉
38
35
 
39
36
  If any configs are missing cardano-up will download them. If any binaries are missing cardano-up will get ones from latest release.
40
37
 
41
- Call `$ cardano-up --help` to explore more options.
38
+ To explore more options call:
39
+
40
+ $ cardano-up --help
41
+ $ cardano-up --examples
42
42
 
43
43
  ## Documentation
44
44
 
45
45
  | Link | Description |
46
46
  |--|--|
47
+ | [Usage examples](https://github.com/piotr-iohk/cardano-up/wiki/Usage-Examples) | Also available in `$ cardano-up --examples` |
47
48
  | [Ruby API (edge)](https://piotr-iohk.github.io/cardano-up/master/) | cardano-up API doc |
48
49
 
49
50
  ## How it works
51
+ By default cardano-up keeps all files at `$HOME/.cardano-up/` however this can be configured by editing `$HOME/.cardano-up/.cardano-up.json` directly or via `config` sub-command. One can check the contents of this internal config file by calling `$ cardano-up config`.
50
52
 
51
53
  **Configurations** for the networks are downloaded from [Cardano Book](https://book.world.dev.cardano.org/environments.html).
52
54
 
@@ -68,8 +70,8 @@ In case of Windows it will attempt to install cardano-node and cardano-wallet as
68
70
 
69
71
  > :warning: nssm requires administrator permissions to register Windows services, therefore you need to start your cmd as an administrator.
70
72
 
71
- By default cardano-up keeps all files at `$HOME/.cardano-up/` however this can be configured by editing `$HOME/.cardano-up/.cardano-up.json` directly or via `config` sub-command. One can check the contents of this internal config file by calling `$ cardano-up config`.
73
+ There is also basic **session management** in cardano-up. In a single session you can have at most 1 node and 1 wallet for particular network. Because of the sessions you can quickly check details of your running components (like where are the log or database files or what ports are used) and you have some basic tools to monitor them (via `tail` and `ping` subcommands).
72
74
 
73
75
  ## License
74
76
 
75
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
77
+ The gem is available as open source under the terms of the [MIT License](https://github.com/piotr-iohk/cardano-up/blob/master/LICENSE.txt).
data/bin/cardano-up CHANGED
@@ -11,16 +11,17 @@ doc = <<~DOCOPT
11
11
  Usage:
12
12
  #{File.basename(__FILE__)} install [<release>]
13
13
  #{File.basename(__FILE__)} get-configs <env>
14
- #{File.basename(__FILE__)} <env> (node|wallet|node-wallet) up [--port <port>]
15
- #{File.basename(__FILE__)} <env> (node|wallet|node-wallet) down
16
- #{File.basename(__FILE__)} <env> (node|wallet) tail
14
+ #{File.basename(__FILE__)} ls
17
15
  #{File.basename(__FILE__)} config [--set-default] [--bindir <path>] [--configdir <path>] [--logdir <path>] [--statedir <path>]
16
+ #{File.basename(__FILE__)} <env> [(node|wallet)] [(up|down|ping)] [--port <port>] [--session <name>]
17
+ #{File.basename(__FILE__)} <env> (node|wallet) tail [--session <name>]
18
18
  #{File.basename(__FILE__)} -v | --version
19
+ #{File.basename(__FILE__)} -e | --examples
19
20
  #{File.basename(__FILE__)} -h | --help
20
21
 
21
22
  Options:
22
23
  install Install cardano-node, cardano-cli, cardano-wallet, cardano-addresses and bech32.
23
- <release> latest | release tag | master | pr num [default: latest]
24
+ <release> latest | release tag | master | pr num. [default: latest]
24
25
  get-configs Get configs for particular Cardano environment.
25
26
  <env> mainnet | preview | preprod etc.
26
27
  up Start particular service. If any configs are missing #{File.basename(__FILE__)}
@@ -28,7 +29,11 @@ doc = <<~DOCOPT
28
29
  ones from latest release.
29
30
  down Stop particular service.
30
31
  tail Follow logs for particular service.
31
- --port <port> Specify wallet port. [default: 8090]
32
+ ping Ping service to check its status.
33
+ ls List sessions.
34
+ -p --port <port> Specify wallet port. [default: 8090]
35
+ -s --session <name> Set session name. In single session you can have
36
+ at most 1 node and 1 wallet for particular <env>. [default: 0]
32
37
 
33
38
  config Internal config for #{File.basename(__FILE__)}
34
39
  --set-default Overwrite config with default values.
@@ -39,33 +44,106 @@ doc = <<~DOCOPT
39
44
 
40
45
  -v --version Check #{File.basename(__FILE__)} version and versions of
41
46
  installed binaries if available.
47
+ -e --examples Show some usage examples.
42
48
  -h --help This help.
43
49
  DOCOPT
44
50
 
45
51
  def pretty_json(c)
46
- puts JSON.pretty_generate(c)
52
+ if c.is_a?(Hash)
53
+ puts JSON.pretty_generate(c)
54
+ else
55
+ warn c
56
+ end
47
57
  end
48
58
 
49
59
  def ok
50
60
  warn 'Ok.'
51
61
  end
52
62
 
63
+ def not_ok
64
+ warn '⚠️ Not ok.'
65
+ end
66
+
53
67
  begin
54
68
  CardanoUp.configure_default unless CardanoUp.configured?
55
69
  o = Docopt.docopt(doc)
70
+ # pretty_json o
71
+
72
+ # EXAMPLES
73
+ if o['--examples'] == true
74
+ warn %(INTERNAL CONFIG:
75
+ ------------------------------
76
+ Check internal config file contents:
77
+
78
+ $ #{File.basename(__FILE__)} config
79
+
80
+ BINARIES AND NETWORK CONFIGS:
81
+ ------------------------------
82
+ Get latest release binaries and verify versions:
83
+
84
+ $ #{File.basename(__FILE__)} install latest
85
+ $ #{File.basename(__FILE__)} -v
86
+
87
+ Get configuration for 'preview' network:
88
+
89
+ $ #{File.basename(__FILE__)} get-configs preview
90
+
91
+ SERVICE MANAGEMENT:
92
+ ------------------------------
93
+ > Note: If you have no configs for particular env 'up'
94
+ subcommand will download them on the fly. If no binaries,
95
+ latest release will be installed, otherwise it will use
96
+ what is in the 'bin_dir'.
97
+
98
+ Start node and wallet on mainnet:
99
+
100
+ $ #{File.basename(__FILE__)} mainnet up
101
+
102
+ Start node on preprod:
103
+
104
+ $ #{File.basename(__FILE__)} preprod node up
105
+
106
+ Check active sessions:
107
+
108
+ $ #{File.basename(__FILE__)} ls
109
+
110
+ Check details of what is running on mainnet and preprod or details of given component:
111
+
112
+ $ #{File.basename(__FILE__)} mainnet
113
+ $ #{File.basename(__FILE__)} preprod
114
+ $ #{File.basename(__FILE__)} mainnet wallet
115
+ $ #{File.basename(__FILE__)} preprod node
116
+
117
+ Check health of node and wallet on mainnet:
118
+
119
+ $ #{File.basename(__FILE__)} mainnet node ping
120
+ $ #{File.basename(__FILE__)} mainnet wallet ping
56
121
 
122
+ Monitor mainnet wallet and node logs (Ctrl + c to stop):
123
+
124
+ $ #{File.basename(__FILE__)} mainnet node tail
125
+ $ #{File.basename(__FILE__)} mainnet wallet tail
126
+
127
+ Stop preprod node:
128
+
129
+ $ #{File.basename(__FILE__)} preprod node down
130
+
131
+ Stop mainnet node and wallet:
132
+
133
+ $ #{File.basename(__FILE__)} mainnet down
134
+ )
135
+ end
57
136
  # VERSION
58
137
  if o['--version'] == true
59
138
  warn "#{File.basename(__FILE__)}: #{CardanoUp::VERSION}"
60
139
  $stderr.puts
61
140
  begin
62
- pretty_json CardanoUp::Install.return_versions
141
+ pretty_json CardanoUp::Bins.return_versions
63
142
  rescue StandardError => e
64
143
  warn 'Nothing installed? To fix run:'
65
144
  warn " $ #{File.basename(__FILE__)} install"
66
- warn e
145
+ warn "⚠️ #{e}"
67
146
  end
68
- exit 1
69
147
  end
70
148
 
71
149
  # CONFIG
@@ -96,7 +174,7 @@ begin
96
174
  warn 'Configdir updated!'
97
175
  end
98
176
 
99
- warn "Your config file is #{CardanoUp.adrestia_bundler_config}:"
177
+ warn "Your config file is #{CardanoUp.cardano_up_config}:"
100
178
  $stderr.puts
101
179
  pretty_json(c)
102
180
  exit
@@ -104,16 +182,20 @@ begin
104
182
 
105
183
  # INSTALL
106
184
  if o['install'] == true
107
- release = o['<release>']
185
+ release = o['<release>'] || 'latest'
108
186
  begin
109
187
  $stderr.print "Installing '#{release}'... "
110
- versions = CardanoUp::Install.install_bins(release)
188
+ versions = CardanoUp::Bins.install(release)
111
189
  ok
112
190
  rescue CardanoUp::VersionNotSupportedError => e
113
191
  warn(e.message)
114
192
  exit 1
193
+ rescue Errno::ETXTBSY => e
194
+ warn("Couldn't unpack binaries, perhaps some file is in use?")
195
+ warn(e.message)
196
+ exit 1
115
197
  end
116
- warn "Install dir: #{CardanoUp.config['bin_dir']}"
198
+ warn "Install dir: #{CardanoUp.config[:bin_dir]}"
117
199
  $stderr.puts
118
200
  pretty_json(versions)
119
201
  exit
@@ -123,13 +205,13 @@ begin
123
205
  if o['get-configs'] == true
124
206
  env = o['<env>']
125
207
  begin
126
- configs = CardanoUp::Install.install_configs(env)
208
+ configs = CardanoUp::Configs.get(env)
127
209
  rescue CardanoUp::EnvNotSupportedError => e
128
210
  warn(e.message)
129
211
  exit 1
130
212
  end
131
213
  warn "Downloaded configs for '#{env}' environment."
132
- warn "Config dir: #{File.join(CardanoUp.config['config_dir'], env)}"
214
+ warn "Config dir: #{File.join(CardanoUp.config[:config_dir], env)}"
133
215
  $stderr.puts
134
216
  pretty_json(configs)
135
217
  exit
@@ -139,80 +221,103 @@ begin
139
221
  if o['up'] == true
140
222
  env = o['<env>']
141
223
  port = o['--port']
224
+ session_name = o['--session']
142
225
 
143
226
  begin
144
227
  $stderr.print 'Configs: '
145
- unless CardanoUp::Install.configs_exist?(env)
228
+ unless CardanoUp::Configs.exist?(env)
146
229
  $stderr.print "installing configs for #{env}... "
147
- CardanoUp::Install.install_configs(env)
230
+ CardanoUp::Configs.get(env)
148
231
  end
149
232
  ok
150
233
 
151
234
  $stderr.print 'Binaries: '
152
235
  begin
153
- CardanoUp::Install.return_versions
236
+ CardanoUp::Bins.return_versions
154
237
  ok
155
238
  rescue StandardError
156
239
  $stderr.print 'installing latest release binaries... '
157
- CardanoUp::Install.install_bins('latest')
240
+ CardanoUp::Bins.install('latest')
158
241
  ok
159
242
  end
160
243
 
161
244
  $stderr.puts
162
245
  warn 'Starting...'
163
246
  $stderr.puts
164
- c = CardanoUp::Start.prepare_configuration({ env: env, wallet_port: port })
165
- rescue CardanoUp::EnvNotSupportedError => e
166
- warn(e.message)
167
- exit 1
168
- end
169
- begin
247
+ c = CardanoUp::Launcher.setup({ env: env, wallet_port: port, session_name: session_name })
248
+
170
249
  if o['node']
171
- pretty_json CardanoUp::Start.start_node(c)
250
+ pretty_json CardanoUp::Launcher.node_up(c)
172
251
  $stderr.puts
173
252
  warn "Congratulations! You've just started cardano-node!"
174
253
  elsif o['wallet']
175
- pretty_json CardanoUp::Start.start_wallet(c)
254
+ pretty_json CardanoUp::Launcher.wallet_up(c)
176
255
  $stderr.puts
177
256
  warn "Congratulations! You've just started cardano-wallet!"
178
- elsif o['node-wallet']
179
- pretty_json CardanoUp::Start.start_node_and_wallet(c)
257
+ else
258
+ n = CardanoUp::Launcher.node_up(c)
259
+ w = CardanoUp::Launcher.wallet_up(c)
260
+ pretty_json(n.merge(w))
180
261
  $stderr.puts
181
262
  warn "Congratulations! You've just started cardano-node and cardano-wallet!"
182
263
  end
264
+ rescue CardanoUp::EnvNotSupportedError => e
265
+ warn "⚠️ #{e}"
266
+ exit 1
267
+ rescue CardanoUp::SessionHasNodeError => e
268
+ warn "⚠️ #{e}"
269
+ $stderr.puts
270
+ warn "If you'd like to start another node instance after all:"
271
+ warn " $ #{File.basename(__FILE__)} #{env} node up -s <some_name>"
272
+ exit 1
273
+ rescue CardanoUp::SessionHasWalletError, CardanoUp::WalletPortUsedError => e
274
+ warn "⚠️ #{e}"
275
+ $stderr.puts
276
+ warn "If you'd like to start another wallet instance after all:"
277
+ warn " $ #{File.basename(__FILE__)} #{env} wallet up -s <some_name> --port <different_port>"
278
+ exit 1
183
279
  rescue StandardError => e
184
280
  warn 'Either you miss configs or binaries... To fix that try running:'
185
281
  warn " $ #{File.basename(__FILE__)} get-configs #{env}"
186
282
  warn " $ #{File.basename(__FILE__)} install"
187
- warn e
283
+ warn "⚠️ #{e}"
188
284
  exit 1
189
285
  end
190
- end
191
286
 
192
- # STOP
193
- if o['down'] == true
287
+ # DOWN
288
+ elsif o['down'] == true
194
289
  env = o['<env>']
195
-
290
+ session_name = o['--session']
291
+ warn "Stopping service on '#{env}' in session '#{session_name}'..."
196
292
  begin
197
293
  if o['node']
198
- CardanoUp::Start.stop_node(env)
294
+ CardanoUp::Launcher.node_down(env, session_name)
295
+ warn 'Node stopped.'
199
296
  elsif o['wallet']
200
- CardanoUp::Start.stop_wallet(env)
201
- elsif o['node-wallet']
202
- CardanoUp::Start.stop_node_and_wallet(env)
297
+ CardanoUp::Launcher.wallet_down(env, session_name)
298
+ warn 'Wallet stopped.'
299
+ else
300
+ CardanoUp::Launcher.node_down(env, session_name)
301
+ warn 'Node stopped.'
302
+ begin
303
+ CardanoUp::Launcher.wallet_down(env, session_name)
304
+ rescue CardanoUp::SessionNotExistsError
305
+ # in case node_down kills session (i.e. it was the last service killed)
306
+ exit
307
+ end
308
+ warn 'Wallet stopped.'
203
309
  end
204
- warn 'Stopped.'
205
- rescue CardanoUp::EnvNotSupportedError => e
206
- warn(e.message)
310
+ rescue CardanoUp::EnvNotSupportedError, CardanoUp::SessionNotExistsError => e
311
+ warn "⚠️ #{e}"
207
312
  exit 1
208
313
  end
209
- end
210
314
 
211
315
  # TAIL
212
- if o['tail'] == true
316
+ elsif o['tail'] == true
213
317
  env = o['<env>']
318
+ session_name = o['--session']
214
319
  begin
215
- log_dir = File.join(CardanoUp.config['log_dir'], env)
320
+ log_dir = File.join(CardanoUp.config[:log_dir], session_name, env)
216
321
  if o['node']
217
322
  log_file = File.join(log_dir, 'node.log')
218
323
  CardanoUp::Tail.tail(log_file)
@@ -228,8 +333,123 @@ begin
228
333
  warn(e.message)
229
334
  exit 1
230
335
  rescue Interrupt
336
+ # on ctrl + c don't show stack trace
337
+ $stderr.puts
338
+ end
339
+
340
+ # PING
341
+ elsif o['ping']
342
+ begin
343
+ session_name = o['--session']
344
+ env = o['<env>']
345
+ CardanoUp::Configs.exist?(env)
346
+ sessions = CardanoUp::Session.get(session_name)
347
+ CardanoUp::Session.network_or_raise?(session_name, env.to_sym)
348
+ warn "Ping {env: #{env}, session: #{session_name}}:"
349
+
350
+ if o['node']
351
+ CardanoUp::Session.node_or_raise?(session_name, env.to_sym)
352
+ $stderr.print 'Node ping... '
353
+ r, c = CardanoUp::Ping.node(session_name, env)
354
+ c == 200 ? ok : not_ok
355
+ pretty_json r
356
+ elsif o['wallet']
357
+ CardanoUp::Session.wallet_or_raise?(session_name, env.to_sym)
358
+ url = sessions[env.to_sym][:wallet][:url]
359
+ $stderr.print "Wallet ping (url: #{url})... "
360
+ r, c = CardanoUp::Ping.wallet(session_name, env)
361
+ c == 200 ? ok : not_ok
362
+ pretty_json r
363
+ else
364
+ warn 'Use: '
365
+ warn " $ #{File.basename(__FILE__)} #{env} node ping -s #{session_name}"
366
+ warn " $ #{File.basename(__FILE__)} #{env} wallet ping -s #{session_name}"
367
+ end
368
+ rescue Errno::ECONNREFUSED,
369
+ CardanoUp::EnvNotSupportedError => e
370
+ warn "⚠️ #{e}"
371
+ exit 1
372
+ rescue CardanoUp::SessionNotExistsError,
373
+ CardanoUp::SessionEnvNotUpError,
374
+ CardanoUp::SessionServiceNotUpError => e
375
+ warn "⚠️ #{e}"
376
+ warn 'To list active sessions call: '
377
+ warn " $ #{File.basename(__FILE__)} ls"
378
+ exit 1
379
+ rescue Interrupt
380
+ # on ctrl + c don't show stack trace
381
+ $stderr.puts
231
382
  exit
232
383
  end
384
+
385
+ # Session STATUS
386
+ elsif o['<env>']
387
+ session_name = o['--session']
388
+ env = o['<env>']
389
+ begin
390
+ CardanoUp::Configs.exist?(env)
391
+ sessions = CardanoUp::Session.get(session_name)
392
+ CardanoUp::Session.network_or_raise?(session_name, env.to_sym)
393
+
394
+ if o['node']
395
+ CardanoUp::Session.node_or_raise?(session_name, env.to_sym)
396
+ warn "Node details {env: #{env}, session: #{session_name}}:"
397
+ warn "For health-check: $ #{File.basename(__FILE__)} #{env} node ping -s #{session_name}"
398
+ $stderr.puts
399
+ node = sessions[env.to_sym][:node]
400
+ pretty_json node
401
+ elsif o['wallet']
402
+ CardanoUp::Session.wallet_or_raise?(session_name, env.to_sym)
403
+ warn "Wallet details {env: #{env}, session: #{session_name}}:"
404
+ warn "For health-check: $ #{File.basename(__FILE__)} #{env} wallet ping -s #{session_name}"
405
+ $stderr.puts
406
+ wallet = sessions[env.to_sym][:wallet]
407
+ pretty_json wallet
408
+ else
409
+ warn "Details {env: #{env}, session: #{session_name}}:"
410
+ $stderr.puts
411
+ pretty_json sessions[env.to_sym]
412
+ end
413
+ rescue CardanoUp::EnvNotSupportedError => e
414
+ warn "⚠️ #{e}"
415
+ exit 1
416
+ rescue CardanoUp::SessionNotExistsError,
417
+ CardanoUp::SessionEnvNotUpError,
418
+ CardanoUp::SessionServiceNotUpError => e
419
+ warn "⚠️ #{e}"
420
+ warn 'To list active sessions call: '
421
+ warn " $ #{File.basename(__FILE__)} ls"
422
+ exit 1
423
+ end
424
+ end
425
+
426
+ # LS
427
+ if o['ls']
428
+ sessions = CardanoUp::Session.list_all
429
+
430
+ def list_extended(sessions)
431
+ sessions.map do |s|
432
+ session_name = File.basename(s)[/.session-(.+).json/, 1]
433
+ s_det = CardanoUp::Session.get(session_name)
434
+ warn " #{session_name}:"
435
+ s_det.each_key do |env|
436
+ warn " #{env}:"
437
+ s_det[env].each_key do |service|
438
+ warn " #{service} (#{s_det[env][service][:service]})" if service == :node
439
+ if service == :wallet
440
+ warn " #{service} (#{s_det[env][service][:service]}, port: #{s_det[env][service][:port]})"
441
+ end
442
+ end
443
+ end
444
+ end
445
+ end
446
+
447
+ if sessions.empty?
448
+ warn 'No active sessions.'
449
+ else
450
+ warn 'Sessions:'
451
+ list_extended(sessions)
452
+ end
233
453
  end
234
454
  rescue Docopt::Exit => e
235
455
  puts e.message
@@ -1,49 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CardanoUp
4
- # Installing configs for Cardano environments and binaries
5
- module Install
6
- # Check all necessary config files for particular environment exist.
7
- # @param env [String] - one of {ENVS}
8
- # @raise CardanoUp::EnvNotSupportedError
9
- def self.configs_exist?(env)
10
- CardanoUp.configure_default unless CardanoUp.configured?
11
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
12
-
13
- configs = CardanoUp.config
14
- config_dir_env = FileUtils.mkdir_p(File.join(configs['config_dir'], env))
15
- config_files = CardanoUp::CONFIG_FILES
16
- not_existing = []
17
- config_files.each do |file|
18
- conf_file_path = File.join(config_dir_env, file)
19
- not_existing << conf_file_path unless File.exist?(conf_file_path)
20
- end
21
- not_existing.empty?
22
- end
23
-
24
- # Get all necessary config files for particular environment.
25
- # @param env [String] - one of {ENVS}
26
- # @raise CardanoUp::EnvNotSupportedError
27
- def self.install_configs(env)
28
- CardanoUp.configure_default unless CardanoUp.configured?
29
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
30
-
31
- configs = CardanoUp.config
32
- config_urls = CardanoUp::Utils.config_urls(env)
33
- config_dir_env = FileUtils.mkdir_p(File.join(configs['config_dir'], env))
34
- config_urls.each do |url|
35
- CardanoUp::Utils.wget(url, File.join(config_dir_env, File.basename(url)))
36
- end
37
- end
38
-
4
+ # Installing binaries for Cardano
5
+ module Bins
39
6
  # Get cardano-wallet bundle binaries to your computer.
40
7
  # @param release [String] - 'latest' | /^v20.{2}-.{2}-.{2}/ | 'master' | '3341'
41
8
  # @raise CardanoUp::VersionNotSupportedError
42
- def self.install_bins(release)
9
+ def self.install(release)
43
10
  CardanoUp.configure_default unless CardanoUp.configured?
44
11
  configs = CardanoUp.config
45
12
  url = CardanoUp::Utils.get_binary_url(release)
46
- bin_dir_env = FileUtils.mkdir_p(configs['bin_dir']).first
13
+ bin_dir_env = FileUtils.mkdir_p(configs[:bin_dir]).first
47
14
  file_to_unpack = File.join(bin_dir_env, 'binary-dist')
48
15
  CardanoUp::Utils.wget(url, file_to_unpack)
49
16
 
@@ -51,6 +18,23 @@ module CardanoUp
51
18
  return_versions(bin_dir_env)
52
19
  end
53
20
 
21
+ # Return versions of installed components
22
+ # @raise CardanoUp::ConfigNotSetError
23
+ def self.return_versions(bin_dir = nil)
24
+ bindir = bin_dir.nil? ? CardanoUp.config[:bin_dir] : bin_dir
25
+ exe = CardanoUp::Utils.win? ? '.exe' : ''
26
+ cn = CardanoUp::Utils.cmd "#{bindir}/cardano-node#{exe} version"
27
+ cli = CardanoUp::Utils.cmd "#{bindir}/cardano-cli#{exe} version"
28
+ cw = CardanoUp::Utils.cmd "#{bindir}/cardano-wallet#{exe} version"
29
+ ca = CardanoUp::Utils.cmd "#{bindir}/cardano-address#{exe} version"
30
+ b32 = CardanoUp::Utils.cmd "#{bindir}/bech32#{exe} --version"
31
+ { 'cardano-node' => cn,
32
+ 'cardano-cli' => cli,
33
+ 'cardano-wallet' => cw,
34
+ 'cardano-address' => ca,
35
+ 'bech32' => b32 }
36
+ end
37
+
54
38
  def unpack_binary(file_path, destination)
55
39
  if CardanoUp::Utils.win?
56
40
  CardanoUp::Tar.unzip(file_path, destination)
@@ -68,22 +52,5 @@ module CardanoUp
68
52
  end
69
53
  module_function :unpack_binary
70
54
  private_class_method :unpack_binary
71
-
72
- # Return versions of installed components
73
- # @raise CardanoUp::ConfigNotSetError
74
- def self.return_versions(bin_dir = nil)
75
- bindir = bin_dir.nil? ? CardanoUp.config['bin_dir'] : bin_dir
76
- exe = CardanoUp::Utils.win? ? '.exe' : ''
77
- cn = CardanoUp::Utils.cmd "#{bindir}/cardano-node#{exe} version"
78
- cli = CardanoUp::Utils.cmd "#{bindir}/cardano-cli#{exe} version"
79
- cw = CardanoUp::Utils.cmd "#{bindir}/cardano-wallet#{exe} version"
80
- ca = CardanoUp::Utils.cmd "#{bindir}/cardano-address#{exe} version"
81
- b32 = CardanoUp::Utils.cmd "#{bindir}/bech32#{exe} --version"
82
- { 'cardano-node' => cn,
83
- 'cardano-cli' => cli,
84
- 'cardano-wallet' => cw,
85
- 'cardano-address' => ca,
86
- 'bech32' => b32 }
87
- end
88
55
  end
89
56
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CardanoUp
4
+ # Installing configs Cardano environments
5
+ module Configs
6
+ # Check all necessary config files for particular environment exist.
7
+ # @param env [String] - one of {ENVS}
8
+ # @raise CardanoUp::EnvNotSupportedError
9
+ def self.exist?(env)
10
+ CardanoUp.configure_default unless CardanoUp.configured?
11
+ raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
12
+
13
+ configs = CardanoUp.config
14
+ config_dir_env = FileUtils.mkdir_p(File.join(configs[:config_dir], env))
15
+ config_files = CardanoUp::CONFIG_FILES
16
+ not_existing = []
17
+ config_files.each do |file|
18
+ conf_file_path = File.join(config_dir_env, file)
19
+ not_existing << conf_file_path unless File.exist?(conf_file_path)
20
+ end
21
+ not_existing.empty?
22
+ end
23
+
24
+ # Get all necessary config files for particular environment.
25
+ # @param env [String] - one of {ENVS}
26
+ # @raise CardanoUp::EnvNotSupportedError
27
+ def self.get(env)
28
+ CardanoUp.configure_default unless CardanoUp.configured?
29
+ raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
30
+
31
+ configs = CardanoUp.config
32
+ config_urls = CardanoUp::Utils.config_urls(env)
33
+ config_dir_env = FileUtils.mkdir_p(File.join(configs[:config_dir], env))
34
+ config_urls.each do |url|
35
+ CardanoUp::Utils.wget(url, File.join(config_dir_env, File.basename(url)))
36
+ end
37
+ end
38
+ end
39
+ end