diskman 1.0.8 → 1.1.0

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: 6b601bff2adbe81099f2b8c279a9757a99d0afc8b62fbec38a8cff8140fb7b1f
4
- data.tar.gz: 12579cdae49bf6a812e0a415ab7bc273f0106dee52880e2a2850c4f1ea9ad680
3
+ metadata.gz: 7fc1b38621654bc6c54e2c341508f7a34bad56edea11e3d6a1430fb386aa7998
4
+ data.tar.gz: ef7d21e5d8fd39f346e755fd8cc961c38d0b0f90fbd1a8a8326faacd5021ce39
5
5
  SHA512:
6
- metadata.gz: 99c8eeb4df39180d09418c9b8707df8bb1413aaa4c6ec55a2f058a66ce017e1a2a51b12254a7461dbfc2215aa0138995fdcd7b179f7987116eed8826bd938ab5
7
- data.tar.gz: 05051535ce5c6007a5e6372e7c779b73b48e6ea920a16e7876533063b0d9ed754a21f2a1e1f5ace6b015eb01654230f78ec18e8e2684c4d13237f3790aa7947b
6
+ metadata.gz: 1633d95b48a889716644ec065f124add986f10eaa11ed8386b4c64cf354bcf0a909231e00d727637ff6f2821fe1282cf7f2e37a7ce648c3bfe58224c86ac298d
7
+ data.tar.gz: 6e3d1a87a326e762cef359c67ba782f87a63f8f8f658b6dadbb21f3bf6ad2c13e1db6aaf550759384f6ba699f7deb5f0422ff1982ac68aff04709fc05c26301f
data/bin/diskman CHANGED
@@ -2,7 +2,18 @@
2
2
  require_relative '../lib/diskman'
3
3
  require 'docopt'
4
4
 
5
- include Diskman # rubocop:disable Style/MixinUsage
5
+ include Diskman
6
+
7
+ Params = Struct.new(
8
+ :version,
9
+ :list,
10
+ :write,
11
+ :clone,
12
+ :fdisk,
13
+ :mkfs,
14
+ :file,
15
+ keyword_init: true,
16
+ )
6
17
 
7
18
  class Main
8
19
  def initialize(opts)
@@ -14,14 +25,15 @@ class Main
14
25
  end
15
26
 
16
27
  def params
17
- @params ||= OpenStruct.new({
28
+ @params ||= Params.new(
18
29
  version: @opts['--version'],
19
30
  list: @opts['--list'],
20
31
  write: @opts['write'],
32
+ clone: @opts['clone'],
21
33
  fdisk: @opts['fdisk'],
22
34
  mkfs: @opts['mkfs'],
23
35
  file: @opts['<file>'],
24
- })
36
+ )
25
37
  end
26
38
 
27
39
  def run
@@ -34,6 +46,8 @@ class Main
34
46
  Command::Mkfs.new.run(list: params.list)
35
47
  elsif params.write
36
48
  Command::Write.new.run(file: params.file)
49
+ elsif params.clone
50
+ Command::Clone.new.run(file: params.file)
37
51
  elsif params.fdisk
38
52
  Command::Fdisk.new.run
39
53
  end
@@ -41,16 +55,19 @@ class Main
41
55
  end
42
56
  end
43
57
 
58
+ PROGRAM_NAME = File.basename($PROGRAM_NAME)
59
+
44
60
  usage = <<~EOF
45
61
  Usage:
46
- #{File.basename($0)} write <file>
47
- #{File.basename($0)} fdisk
48
- #{File.basename($0)} mkfs [--list]
49
- #{File.basename($0)} ( --version | --help )
62
+ #{PROGRAM_NAME} write <file>
63
+ #{PROGRAM_NAME} clone <file>
64
+ #{PROGRAM_NAME} fdisk
65
+ #{PROGRAM_NAME} mkfs [--list]
66
+ #{PROGRAM_NAME} ( --version | --help )
50
67
 
51
68
  Options:
52
69
  -v, --version Show version
53
- -h, --help Show this help
70
+ -h, --help Show help
54
71
  EOF
55
72
 
56
73
  begin
@@ -0,0 +1,19 @@
1
+ module Command
2
+ class Clone
3
+ def run(file:)
4
+ if File.exist?(file)
5
+ puts ('File exists: ' + file).red
6
+ raise Interrupt
7
+ end
8
+
9
+ device = RootDevice.choose
10
+ cmd = device.get_clone_command(file)
11
+
12
+ puts "File: #{file.yellow}"
13
+ puts "Device: #{device.to_s.yellow}"
14
+ puts "Command: #{cmd.yellow}"
15
+
16
+ System.exec!(cmd)
17
+ end
18
+ end
19
+ end
@@ -17,8 +17,13 @@ module Diskman
17
17
  end
18
18
 
19
19
  def get_write_command(path)
20
- dd = 'sudo dd if="%s" of="%s" bs=%dK status=progress'
21
- dd % [path, @path, 4096]
20
+ dd = 'sudo dd if="%s" of="%s" bs=%dM status=progress conv=fsync'
21
+ dd % [path, @path, 4]
22
+ end
23
+
24
+ def get_clone_command(path)
25
+ dd = 'sudo dd if="%s" of="%s" bs=%dM status=progress conv=fsync'
26
+ dd % [@path, path, 4]
22
27
  end
23
28
 
24
29
  def to_s
@@ -1,19 +1,10 @@
1
1
  module Diskman
2
2
  module System
3
- # If sudo prompts for the password when a pipeline with pv has already
4
- # started then we're unable to enter the password. Run sudo --validate
5
- # first to ensure that we are preauthenticated.
6
- def self.prepare_sudo_session!
7
- system('sudo --validate')
8
- end
9
-
10
3
  # Execute a command.
11
- # If sudo is true, ensures sudo is ready before running the command.
12
- # If safe is true, ensures the user definitely wants to run the command
13
- # before running it.
14
- def self.exec!(cmd, safe: true, sudo: true)
4
+ #
5
+ # If safe is true, ensures the user definitely wants to run the command before running it.
6
+ def self.exec!(cmd, safe: true)
15
7
  Confirmer.check! if safe
16
- prepare_sudo_session! if sudo
17
8
  puts
18
9
  exec(cmd)
19
10
  end
@@ -22,8 +13,7 @@ module Diskman
22
13
  def self.bytes2human(b)
23
14
  return '0B' if b <= 0
24
15
 
25
- # Use 1000 to match the misleading way disk capacities are
26
- # advertised.
16
+ # Use 1000 to match the misleading way disk capacities are advertised.
27
17
  k = 1000
28
18
 
29
19
  suffixes = %w[T G M K B]
@@ -1,3 +1,3 @@
1
1
  module Diskman
2
- VERSION = '1.0.8'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diskman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-12 00:00:00.000000000 Z
11
+ date: 2023-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -104,6 +104,7 @@ files:
104
104
  - bin/diskman
105
105
  - lib/diskman.rb
106
106
  - lib/diskman/chooser.rb
107
+ - lib/diskman/commands/clone.rb
107
108
  - lib/diskman/commands/fdisk.rb
108
109
  - lib/diskman/commands/mkfs.rb
109
110
  - lib/diskman/commands/write.rb
@@ -115,8 +116,9 @@ files:
115
116
  - lib/diskman/version.rb
116
117
  homepage: https://github.com/crdx/diskman
117
118
  licenses:
118
- - MIT
119
- metadata: {}
119
+ - GPLv3
120
+ metadata:
121
+ rubygems_mfa_required: 'true'
120
122
  post_install_message:
121
123
  rdoc_options: []
122
124
  require_paths:
@@ -132,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
134
  - !ruby/object:Gem::Version
133
135
  version: '0'
134
136
  requirements: []
135
- rubygems_version: 3.2.21
137
+ rubygems_version: 3.3.25
136
138
  signing_key:
137
139
  specification_version: 4
138
140
  summary: Interactive command line interface for safely managing disks