5
6
7
8
9
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/arver/cli.rb', line 5
def self.execute(output,arguments=[])
Arver::Log.logger= IOLogger.new( output )
options = {
:user => '',
:config_dir => '',
:dry_run => false,
:test_mode => false,
:ask_password => false,
:force => false,
:violence => false,
:action => nil,
:argument => {},
}
parser = OptionParser.new do |opts|
opts.banner = " arver.\n\n Usage: \#{File.basename($0)} [options] ACTION\n\n Options:\n BANNER\n opts.on(\"-c\", \"--config-dir PATH\", String,\n \"Path to arverdata dir.\") { |arg| options[:config_dir] = arg }\n opts.on(\"-u\", \"--user NAME\", String,\n \"Your username.\" ) { |arg| options[:user] = arg }\n opts.on(\"-h\", \"--help\",\n \"Show this help message.\") { Arver::Log.write opts; return }\n opts.on(\"--ask-password\",\n \"Ask for an existing LUKS password when adding a new user.\") { options[:ask_password] = true }\n opts.on(\"--set-key KEYNAME\", String,\n \"Manuall choose a key to use. The KEYNAME is in the format /LOCATION/MACHINE/DISK.\") { |arg| options[:global_key_path] = arg }\n opts.on(\"-t\", \"--trust-all\",\n \"Use untrusted GPG Keys.\") { options[:trust_all] = true }\n opts.on(\"--force\",\n \"Apply force (allow duplicate keys)\") { options[:force] = true }\n opts.on(\"--violence\",\n \"Apply violence (allow destruction of disk)\") { options[:violence] = true }\n opts.on(\"-v\",\n \"Verbose\") { Arver::Log.level( Arver::LogLevels::Debug ) }\n opts.on(\"--vv\",\n \"Max Verbose\") { Arver::Log.level( Arver::LogLevels::Trace ) }\n opts.on(\"--dry-run\",\n \"Test your command.\") { options[:dry_run] = true }\n opts.on(\"--test-mode\",\n \"Test mode (internal use)\") { options[:test_mode] = true }\n opts.separator \"Targets:\"\n opts.on(\n \" Possible targets are: '<Group>', '<Host>', '<Disk>', '<Host>/<Device>',\\n\"+\n \" '<Group>/<Host>/<Disk>' or 'ALL'.\\n\"+\n \" Multiple parameters can be given as comma separated list.\\n\"+\n \" Ambigues targets yield an error.\" )\n opts.separator \"Actions:\"\n opts.on_tail( \"-o TARGET\", \"--open TARGET\", String,\n \"Open target.\" ) { |arg| options[:argument][:target] = arg; options[:action] = :open; }\n opts.on_tail( \"--systemd-open TARGET\", String,\n \"Open target during boot via systemd-asskpasswd.\" ) { |arg| options[:argument][:target] = arg; options[:action] = :systemd_open; }\n opts.on_tail( \"-c TARGET\", \"--close TARGET\", String,\n \"Close target.\" ) { |arg| options[:argument][:target] = arg; options[:action] = :close; }\n opts.on_tail( \"--create TARGET\", String,\n \"Create new arver partition on the target.\" ) { |arg| options[:argument][:target] = arg; options[:action] = :create; }\n opts.on_tail( \"-a USER TARGET\", \"--add-user USER TARGET\", String,\n \"Add a user to target.\") { |user| options[:action] = :adduser; options[:argument][:user] = user; }\n opts.on_tail( \"-d USER TARGET\", \"--del-user USER TARGET\", String,\n \"Remove a user from target.\") { |user| options[:action] = :deluser; options[:argument][:user] = user; }\n opts.on_tail( \"-r TARGET\", \"--refresh TARGET\", String,\n \"Refresh the key on target.\" ) { |arg| options[:argument][:target] = arg; options[:action] = :refresh; }\n opts.on_tail( \"-g\", \"--garbage-collect\",\n \"Expunge old keys.\" ) { options[:action] = :gc; }\n opts.on_tail( \"-k TARGET\", \"--keys TARGET\", String,\n \"List local keys for this target.\") { |arg| options[:argument][:target] = arg; options[:action] = :key_info; }\n opts.on_tail( \"-i TARGET\", \"--info TARGET\", String,\n \"LUKS info about a target.\") { |arg| options[:argument][:target] = arg; options[:action] = :info; }\n opts.on_tail( \"-l\", \"--list-targets\",\n \"List targets.\" ) { options[:action] = :list; }\n opts.on_tail( \"--dump-key TARGET\", String,\n \"Dump raw luks passphrase.\" ) { |arg| options[:argument][:target] = arg; options[:action] = :dump; }\n opts.on_tail( \"--init\",\n \"Setup a sample configuration.\" ) { options[:action] = :init; }\n \n begin\n opts.parse!(arguments)\n rescue\n Arver::Log.write opts; return\n end\n \n if options[:action] == :deluser || options[:action] == :adduser\n options[:argument][:target] = arguments.last\n end\n \n if options[:action].nil? || \n ( options[:action] != :list && options[:action] != :gc && options[:action] != :init && ! options[:argument][:target] ) ||\n ( ( options[:action] == :adduser || options[:action] == :deluser ) && ! options[:argument][:target] )\n Arver::Log.write opts; return\n end\n end\n\n unless( Arver::Bootstrap.run( options ) )\n return\n end\n \n target_list = TargetList.get_list( options[:argument][:target] )\n if target_list.empty? && ( options[:action] != :list && options[:action] != :gc && options[:action] != :init )\n Arver::Log.write( \"No targets found\" )\n return false\n end\n \n run_action( options[:action], target_list, options[:argument][:user] )\nend\n".gsub(/^ /,'')
|