cardano-up 0.1.1 → 0.1.3

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: ffd6230a971acea78415e9789e6b605ad493dee667afe4acd5f123759df90867
4
- data.tar.gz: 20af817f4b0918d29b5b75dc6bea54d59fc3e5e6ee61d974888a69ffd8dce357
3
+ metadata.gz: c55536463a8a275a7a370bac31474072c837a1411e08455934aa23a9b9d18932
4
+ data.tar.gz: b884c70ea66053c81bb91c3eefdef6447bd855e5a91595f0d7cf6ea0d5216b23
5
5
  SHA512:
6
- metadata.gz: 46d6f2e0f2398aa1416ab61e1f49684aa5b07389efce583f00ab973b46f5c91246aea9a71f27bb03717ed0101ef27cff9547adf366469650d9b03d25ff7dd8b9
7
- data.tar.gz: bcc306a1b9ac5a7debee61df90fe659bfc3df4f4cc309317ba334193c6cf421c9810a88c5100639994bc9e5494c678fc171cf9fd308cd7c3937e4e658b516270
6
+ metadata.gz: 84a039aeab642b1e9eb5adcc30ebf1eccc8af53edbf6aebb28025ade0a69a858c9f8f8f7cb66ea4c84f1ff547065c19682347e7e4e5eef1039f47dfec70d14c4
7
+ data.tar.gz: 948ba5bad9619f2aaacad6c0cc6a9c1e5f114b8aa3eb1ea40c47141922b6d373eba19be5e8ff586db6f770296ab6cb868efa09773c82523b9fa61b6823e22b34
data/README.md CHANGED
@@ -23,31 +23,48 @@ This Ruby gem provides easy way for:
23
23
 
24
24
  ## Installation
25
25
 
26
+ #### Rubygem:
27
+
26
28
  $ gem install cardano-up
29
+ $ cardano-up --help
30
+
31
+ #### Nix:
32
+
33
+ $ nix develop github:piotr-iohk/cardano-up?dir=nix
34
+ $ cardano-up --help
35
+
36
+ or run directly
37
+
38
+ $ nix run github:piotr-iohk/cardano-up?dir=nix -- --help
27
39
 
28
40
  ## Usage
29
41
 
30
42
  It only takes a single command to start node and wallet on your system. Say, on `mainnet`?
31
43
 
32
- $ cardano-up mainnet node-wallet up
44
+ $ cardano-up mainnet up
33
45
 
34
46
  That's it! 🎉
35
47
 
36
48
  If any configs are missing cardano-up will download them. If any binaries are missing cardano-up will get ones from latest release.
37
49
 
38
- Call `$ cardano-up --help` to explore more options.
50
+ To explore more options call:
51
+
52
+ $ cardano-up --help
53
+ $ cardano-up --examples
39
54
 
40
55
  ## Documentation
41
56
 
42
57
  | Link | Description |
43
58
  |--|--|
59
+ | [Usage examples](https://github.com/piotr-iohk/cardano-up/wiki/Usage-Examples) | Also available in `$ cardano-up --examples` |
44
60
  | [Ruby API (edge)](https://piotr-iohk.github.io/cardano-up/master/) | cardano-up API doc |
45
61
 
46
62
  ## How it works
63
+ 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`.
47
64
 
48
65
  **Configurations** for the networks are downloaded from [Cardano Book](https://book.world.dev.cardano.org/environments.html).
49
66
 
50
- **Binaries** come from [cardano-wallet](https://github.com/input-output-hk/cardano-wallet) which actually provides `cardano-node`, `cardano-cli`, `cardano-wallet`, `cardano-addresses` and `bech32` tools in each of its release bundles. This ensures that all components are compatible and work smoothly together. You can get any public release of the cardano-wallet bundle as well as `master` version and even any of the PRs that are currently being worked on.
67
+ **Binaries** come from [cardano-wallet](https://github.com/input-output-hk/cardano-wallet) which actually provides `cardano-node`, `cardano-cli`, `cardano-wallet`, `cardano-addresses` and `bech32` tools in each of its release bundles. This ensures that all components are compatible and work smoothly together. You can get any public release of the cardano-wallet bundle.
51
68
 
52
69
  **Starting** `cardano-node` and `cardano-wallet`, cardano-up attempts to launch separate [`screen`](https://www.gnu.org/software/screen/) sessions for wallet and node respectively. If screen is not present on your system you can install it using package manager, e.g.:
53
70
 
@@ -65,8 +82,8 @@ In case of Windows it will attempt to install cardano-node and cardano-wallet as
65
82
 
66
83
  > :warning: nssm requires administrator permissions to register Windows services, therefore you need to start your cmd as an administrator.
67
84
 
68
- 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`.
85
+ 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).
69
86
 
70
87
  ## License
71
88
 
72
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
89
+ 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 [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,31 +44,105 @@ 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
147
  end
69
148
 
@@ -103,16 +182,20 @@ begin
103
182
 
104
183
  # INSTALL
105
184
  if o['install'] == true
106
- release = o['<release>']
185
+ release = o['<release>'] || 'latest'
107
186
  begin
108
187
  $stderr.print "Installing '#{release}'... "
109
- versions = CardanoUp::Install.install_bins(release)
188
+ versions = CardanoUp::Bins.install(release)
110
189
  ok
111
190
  rescue CardanoUp::VersionNotSupportedError => e
112
191
  warn(e.message)
113
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
114
197
  end
115
- warn "Install dir: #{CardanoUp.config['bin_dir']}"
198
+ warn "Install dir: #{CardanoUp.config[:bin_dir]}"
116
199
  $stderr.puts
117
200
  pretty_json(versions)
118
201
  exit
@@ -122,13 +205,13 @@ begin
122
205
  if o['get-configs'] == true
123
206
  env = o['<env>']
124
207
  begin
125
- configs = CardanoUp::Install.install_configs(env)
208
+ configs = CardanoUp::Configs.get(env)
126
209
  rescue CardanoUp::EnvNotSupportedError => e
127
210
  warn(e.message)
128
211
  exit 1
129
212
  end
130
213
  warn "Downloaded configs for '#{env}' environment."
131
- warn "Config dir: #{File.join(CardanoUp.config['config_dir'], env)}"
214
+ warn "Config dir: #{File.join(CardanoUp.config[:config_dir], env)}"
132
215
  $stderr.puts
133
216
  pretty_json(configs)
134
217
  exit
@@ -138,80 +221,103 @@ begin
138
221
  if o['up'] == true
139
222
  env = o['<env>']
140
223
  port = o['--port']
224
+ session_name = o['--session']
141
225
 
142
226
  begin
143
227
  $stderr.print 'Configs: '
144
- unless CardanoUp::Install.configs_exist?(env)
228
+ unless CardanoUp::Configs.exist?(env)
145
229
  $stderr.print "installing configs for #{env}... "
146
- CardanoUp::Install.install_configs(env)
230
+ CardanoUp::Configs.get(env)
147
231
  end
148
232
  ok
149
233
 
150
234
  $stderr.print 'Binaries: '
151
235
  begin
152
- CardanoUp::Install.return_versions
236
+ CardanoUp::Bins.return_versions
153
237
  ok
154
238
  rescue StandardError
155
239
  $stderr.print 'installing latest release binaries... '
156
- CardanoUp::Install.install_bins('latest')
240
+ CardanoUp::Bins.install('latest')
157
241
  ok
158
242
  end
159
243
 
160
244
  $stderr.puts
161
245
  warn 'Starting...'
162
246
  $stderr.puts
163
- c = CardanoUp::Start.prepare_configuration({ env: env, wallet_port: port })
164
- rescue CardanoUp::EnvNotSupportedError => e
165
- warn(e.message)
166
- exit 1
167
- end
168
- begin
247
+ c = CardanoUp::Launcher.setup({ env: env, wallet_port: port, session_name: session_name })
248
+
169
249
  if o['node']
170
- pretty_json CardanoUp::Start.start_node(c)
250
+ pretty_json CardanoUp::Launcher.node_up(c)
171
251
  $stderr.puts
172
252
  warn "Congratulations! You've just started cardano-node!"
173
253
  elsif o['wallet']
174
- pretty_json CardanoUp::Start.start_wallet(c)
254
+ pretty_json CardanoUp::Launcher.wallet_up(c)
175
255
  $stderr.puts
176
256
  warn "Congratulations! You've just started cardano-wallet!"
177
- elsif o['node-wallet']
178
- 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))
179
261
  $stderr.puts
180
262
  warn "Congratulations! You've just started cardano-node and cardano-wallet!"
181
263
  end
264
+ rescue CardanoUp::EnvNotSupportedError, CardanoUp::NoScreenError => 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
182
279
  rescue StandardError => e
183
280
  warn 'Either you miss configs or binaries... To fix that try running:'
184
281
  warn " $ #{File.basename(__FILE__)} get-configs #{env}"
185
282
  warn " $ #{File.basename(__FILE__)} install"
186
- warn e
283
+ warn "⚠️ #{e}"
187
284
  exit 1
188
285
  end
189
- end
190
286
 
191
- # STOP
192
- if o['down'] == true
287
+ # DOWN
288
+ elsif o['down'] == true
193
289
  env = o['<env>']
194
-
290
+ session_name = o['--session']
291
+ warn "Stopping service on '#{env}' in session '#{session_name}'..."
195
292
  begin
196
293
  if o['node']
197
- CardanoUp::Start.stop_node(env)
294
+ CardanoUp::Launcher.node_down(env, session_name)
295
+ warn 'Node stopped.'
198
296
  elsif o['wallet']
199
- CardanoUp::Start.stop_wallet(env)
200
- elsif o['node-wallet']
201
- 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.'
202
309
  end
203
- warn 'Stopped.'
204
- rescue CardanoUp::EnvNotSupportedError => e
205
- warn(e.message)
310
+ rescue CardanoUp::EnvNotSupportedError, CardanoUp::SessionNotExistsError, CardanoUp::NoScreenError => e
311
+ warn "⚠️ #{e}"
206
312
  exit 1
207
313
  end
208
- end
209
314
 
210
315
  # TAIL
211
- if o['tail'] == true
316
+ elsif o['tail'] == true
212
317
  env = o['<env>']
318
+ session_name = o['--session']
213
319
  begin
214
- log_dir = File.join(CardanoUp.config['log_dir'], env)
320
+ log_dir = File.join(CardanoUp.config[:log_dir], session_name, env)
215
321
  if o['node']
216
322
  log_file = File.join(log_dir, 'node.log')
217
323
  CardanoUp::Tail.tail(log_file)
@@ -227,8 +333,123 @@ begin
227
333
  warn(e.message)
228
334
  exit 1
229
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
230
382
  exit
231
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
232
453
  end
233
454
  rescue Docopt::Exit => e
234
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
- # @param release [String] - 'latest' | /^v20.{2}-.{2}-.{2}/ | 'master' | '3341'
7
+ # @param release [String] - 'latest' | /^v20.{2}-.{2}-.{2}/
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