kanrisuru 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/kanrisuru/core/apt/commands/autoclean.rb +13 -0
- data/lib/kanrisuru/core/apt/commands/autoremove.rb +15 -0
- data/lib/kanrisuru/core/apt/commands/clean.rb +13 -0
- data/lib/kanrisuru/core/apt/commands/full_upgrade.rb +14 -0
- data/lib/kanrisuru/core/apt/commands/install.rb +22 -0
- data/lib/kanrisuru/core/apt/commands/list.rb +21 -0
- data/lib/kanrisuru/core/apt/commands/purge.rb +18 -0
- data/lib/kanrisuru/core/apt/commands/remove.rb +18 -0
- data/lib/kanrisuru/core/apt/commands/search.rb +18 -0
- data/lib/kanrisuru/core/apt/commands/show.rb +21 -0
- data/lib/kanrisuru/core/apt/commands/update.rb +14 -0
- data/lib/kanrisuru/core/apt/commands/upgrade.rb +14 -0
- data/lib/kanrisuru/core/apt/commands.rb +14 -0
- data/lib/kanrisuru/core/apt/parser.rb +6 -0
- data/lib/kanrisuru/core/apt/parsers/base.rb +51 -0
- data/lib/kanrisuru/core/apt/parsers/list.rb +28 -0
- data/lib/kanrisuru/core/apt/parsers/search.rb +32 -0
- data/lib/kanrisuru/core/apt/parsers/show.rb +90 -0
- data/lib/kanrisuru/core/apt/types.rb +36 -0
- data/lib/kanrisuru/core/apt.rb +4 -284
- data/lib/kanrisuru/core/archive/commands/tar.rb +126 -0
- data/lib/kanrisuru/core/archive/commands.rb +3 -0
- data/lib/kanrisuru/core/archive/types.rb +9 -0
- data/lib/kanrisuru/core/archive.rb +3 -121
- data/lib/kanrisuru/core/disk/commands/blkid.rb +35 -0
- data/lib/kanrisuru/core/disk/commands/df.rb +26 -0
- data/lib/kanrisuru/core/disk/commands/du.rb +24 -0
- data/lib/kanrisuru/core/disk/commands/lsblk.rb +54 -0
- data/lib/kanrisuru/core/disk/commands.rb +6 -0
- data/lib/kanrisuru/core/disk/parser.rb +6 -0
- data/lib/kanrisuru/core/disk/parsers/blkid.rb +72 -0
- data/lib/kanrisuru/core/disk/parsers/df.rb +33 -0
- data/lib/kanrisuru/core/disk/parsers/du.rb +25 -0
- data/lib/kanrisuru/core/disk/parsers/lsblk.rb +96 -0
- data/lib/kanrisuru/core/disk/types.rb +21 -0
- data/lib/kanrisuru/core/disk.rb +5 -290
- data/lib/kanrisuru/core/dmi/commands/dmi.rb +42 -0
- data/lib/kanrisuru/core/dmi/commands.rb +3 -0
- data/lib/kanrisuru/core/dmi/parser.rb +3 -0
- data/lib/kanrisuru/core/dmi/parsers/dmi.rb +149 -0
- data/lib/kanrisuru/core/dmi/types.rb +361 -0
- data/lib/kanrisuru/core/dmi.rb +4 -522
- data/lib/kanrisuru/core/file/commands/chmod.rb +29 -0
- data/lib/kanrisuru/core/file/commands/chown.rb +35 -0
- data/lib/kanrisuru/core/file/commands/copy.rb +56 -0
- data/lib/kanrisuru/core/file/commands/link.rb +25 -0
- data/lib/kanrisuru/core/file/commands/mkdir.rb +37 -0
- data/lib/kanrisuru/core/file/commands/move.rb +48 -0
- data/lib/kanrisuru/core/file/commands/rm.rb +38 -0
- data/lib/kanrisuru/core/file/commands/symlink.rb +46 -0
- data/lib/kanrisuru/core/file/commands/touch.rb +33 -0
- data/lib/kanrisuru/core/file/commands/unlink.rb +13 -0
- data/lib/kanrisuru/core/file/commands/wc.rb +16 -0
- data/lib/kanrisuru/core/file/commands.rb +29 -0
- data/lib/kanrisuru/core/file/parser.rb +3 -0
- data/lib/kanrisuru/core/file/parsers/wc.rb +16 -0
- data/lib/kanrisuru/core/file/types.rb +9 -0
- data/lib/kanrisuru/core/file.rb +4 -312
- data/lib/kanrisuru/core/find/commands/find.rb +97 -0
- data/lib/kanrisuru/core/find/commands.rb +3 -0
- data/lib/kanrisuru/core/find/constants.rb +9 -0
- data/lib/kanrisuru/core/find/parser.rb +3 -0
- data/lib/kanrisuru/core/find/parsers/find.rb +18 -0
- data/lib/kanrisuru/core/find/types.rb +9 -0
- data/lib/kanrisuru/core/find.rb +5 -97
- data/lib/kanrisuru/core/group/commands/create_group.rb +21 -0
- data/lib/kanrisuru/core/group/commands/delete_group.rb +16 -0
- data/lib/kanrisuru/core/group/commands/get_gid.rb +17 -0
- data/lib/kanrisuru/core/group/commands/get_group.rb +29 -0
- data/lib/kanrisuru/core/group/commands/is_group.rb +14 -0
- data/lib/kanrisuru/core/group/commands/update_group.rb +23 -0
- data/lib/kanrisuru/core/group/commands.rb +8 -0
- data/lib/kanrisuru/core/group/parser.rb +4 -0
- data/lib/kanrisuru/core/group/parsers/gid.rb +15 -0
- data/lib/kanrisuru/core/group/parsers/group.rb +15 -0
- data/lib/kanrisuru/core/group/types.rb +10 -0
- data/lib/kanrisuru/core/group.rb +4 -81
- data/lib/kanrisuru/core/ip/commands/address.rb +69 -0
- data/lib/kanrisuru/core/ip/commands/address_label.rb +38 -0
- data/lib/kanrisuru/core/ip/commands/link.rb +74 -0
- data/lib/kanrisuru/core/ip/commands/maddress.rb +33 -0
- data/lib/kanrisuru/core/ip/commands/neighbour.rb +55 -0
- data/lib/kanrisuru/core/ip/commands/route.rb +115 -0
- data/lib/kanrisuru/core/ip/commands/rule.rb +42 -0
- data/lib/kanrisuru/core/ip/commands.rb +24 -0
- data/lib/kanrisuru/core/ip/constants.rb +13 -0
- data/lib/kanrisuru/core/ip/parser.rb +10 -0
- data/lib/kanrisuru/core/ip/parsers/address.rb +104 -0
- data/lib/kanrisuru/core/ip/parsers/address_label.rb +27 -0
- data/lib/kanrisuru/core/ip/parsers/base.rb +166 -0
- data/lib/kanrisuru/core/ip/parsers/link.rb +86 -0
- data/lib/kanrisuru/core/ip/parsers/maddress.rb +85 -0
- data/lib/kanrisuru/core/ip/parsers/neighbour.rb +89 -0
- data/lib/kanrisuru/core/ip/parsers/route.rb +76 -0
- data/lib/kanrisuru/core/ip/parsers/rule.rb +60 -0
- data/lib/kanrisuru/core/ip/types.rb +46 -0
- data/lib/kanrisuru/core/ip.rb +5 -995
- data/lib/kanrisuru/core/mount/commands/mount.rb +65 -0
- data/lib/kanrisuru/core/mount/commands/umount.rb +35 -0
- data/lib/kanrisuru/core/mount/commands.rb +49 -0
- data/lib/kanrisuru/core/mount.rb +2 -125
- data/lib/kanrisuru/core/path/commands/ls.rb +26 -0
- data/lib/kanrisuru/core/path/commands/pwd.rb +16 -0
- data/lib/kanrisuru/core/path/commands/readlink.rb +22 -0
- data/lib/kanrisuru/core/path/commands/realpath.rb +18 -0
- data/lib/kanrisuru/core/path/commands/which.rb +19 -0
- data/lib/kanrisuru/core/path/commands/whoami.rb +16 -0
- data/lib/kanrisuru/core/path/commands.rb +8 -0
- data/lib/kanrisuru/core/path/parser.rb +4 -0
- data/lib/kanrisuru/core/path/parsers/ls.rb +53 -0
- data/lib/kanrisuru/core/path/parsers/which.rb +18 -0
- data/lib/kanrisuru/core/path/types.rb +12 -0
- data/lib/kanrisuru/core/path.rb +4 -121
- data/lib/kanrisuru/core/socket/commands/ss.rb +44 -0
- data/lib/kanrisuru/core/socket/commands.rb +3 -0
- data/lib/kanrisuru/core/socket/constants.rb +29 -0
- data/lib/kanrisuru/core/socket/parser.rb +3 -0
- data/lib/kanrisuru/core/socket/parsers/ss.rb +109 -0
- data/lib/kanrisuru/core/socket/types.rb +18 -0
- data/lib/kanrisuru/core/socket.rb +5 -164
- data/lib/kanrisuru/core/stat/commands/stat.rb +62 -0
- data/lib/kanrisuru/core/stat/commands.rb +3 -0
- data/lib/kanrisuru/core/stat/parser.rb +3 -0
- data/lib/kanrisuru/core/stat/parsers/stat.rb +34 -0
- data/lib/kanrisuru/core/stat/types.rb +14 -0
- data/lib/kanrisuru/core/stat.rb +4 -81
- data/lib/kanrisuru/core/stream/commands/cat.rb +25 -0
- data/lib/kanrisuru/core/stream/commands/echo.rb +20 -0
- data/lib/kanrisuru/core/stream/commands/head.rb +18 -0
- data/lib/kanrisuru/core/stream/commands/read_file_chunk.rb +21 -0
- data/lib/kanrisuru/core/stream/commands/sed.rb +23 -0
- data/lib/kanrisuru/core/stream/commands/tail.rb +18 -0
- data/lib/kanrisuru/core/stream/commands.rb +27 -0
- data/lib/kanrisuru/core/stream/parser.rb +4 -0
- data/lib/kanrisuru/core/stream/parsers/echo.rb +17 -0
- data/lib/kanrisuru/core/stream/parsers/sed.rb +17 -0
- data/lib/kanrisuru/core/stream.rb +3 -104
- data/lib/kanrisuru/core/system/commands/cpu_info.rb +32 -0
- data/lib/kanrisuru/core/system/commands/free.rb +25 -0
- data/lib/kanrisuru/core/system/commands/kernel_statistics.rb +21 -0
- data/lib/kanrisuru/core/system/commands/kill.rb +22 -0
- data/lib/kanrisuru/core/system/commands/last.rb +31 -0
- data/lib/kanrisuru/core/system/commands/load_average.rb +16 -0
- data/lib/kanrisuru/core/system/commands/load_env.rb +16 -0
- data/lib/kanrisuru/core/system/commands/lscpu.rb +17 -0
- data/lib/kanrisuru/core/system/commands/lsof.rb +16 -0
- data/lib/kanrisuru/core/system/commands/poweroff.rb +42 -0
- data/lib/kanrisuru/core/system/commands/ps.rb +35 -0
- data/lib/kanrisuru/core/system/commands/reboot.rb +42 -0
- data/lib/kanrisuru/core/system/commands/uptime.rb +18 -0
- data/lib/kanrisuru/core/system/commands/w.rb +24 -0
- data/lib/kanrisuru/core/system/commands.rb +34 -0
- data/lib/kanrisuru/core/system/parser.rb +11 -0
- data/lib/kanrisuru/core/system/parsers/kernel_statistics.rb +56 -0
- data/lib/kanrisuru/core/system/parsers/last.rb +64 -0
- data/lib/kanrisuru/core/system/parsers/load_average.rb +15 -0
- data/lib/kanrisuru/core/system/parsers/load_env.rb +24 -0
- data/lib/kanrisuru/core/system/parsers/lscpu.rb +90 -0
- data/lib/kanrisuru/core/system/parsers/lsof.rb +62 -0
- data/lib/kanrisuru/core/system/parsers/ps.rb +71 -0
- data/lib/kanrisuru/core/system/parsers/uptime.rb +38 -0
- data/lib/kanrisuru/core/system/parsers/w.rb +30 -0
- data/lib/kanrisuru/core/system/types.rb +108 -0
- data/lib/kanrisuru/core/system.rb +4 -687
- data/lib/kanrisuru/core/transfer/commands/download.rb +26 -0
- data/lib/kanrisuru/core/transfer/commands/upload.rb +23 -0
- data/lib/kanrisuru/core/transfer/commands/wget.rb +168 -0
- data/lib/kanrisuru/core/transfer/commands.rb +5 -0
- data/lib/kanrisuru/core/transfer/constants.rb +10 -0
- data/lib/kanrisuru/core/transfer.rb +3 -199
- data/lib/kanrisuru/core/user/commands/create_user.rb +57 -0
- data/lib/kanrisuru/core/user/commands/delete_user.rb +20 -0
- data/lib/kanrisuru/core/user/commands/get_uid.rb +15 -0
- data/lib/kanrisuru/core/user/commands/get_user.rb +48 -0
- data/lib/kanrisuru/core/user/commands/is_user.rb +14 -0
- data/lib/kanrisuru/core/user/commands/update_user.rb +63 -0
- data/lib/kanrisuru/core/user/commands.rb +8 -0
- data/lib/kanrisuru/core/user/parser.rb +4 -0
- data/lib/kanrisuru/core/user/parsers/getent.rb +17 -0
- data/lib/kanrisuru/core/user/parsers/groups.rb +17 -0
- data/lib/kanrisuru/core/user/types.rb +11 -0
- data/lib/kanrisuru/core/user.rb +4 -182
- data/lib/kanrisuru/core/yum/commands/autoremove.rb +14 -0
- data/lib/kanrisuru/core/yum/commands/clean.rb +23 -0
- data/lib/kanrisuru/core/yum/commands/erase.rb +20 -0
- data/lib/kanrisuru/core/yum/commands/info.rb +21 -0
- data/lib/kanrisuru/core/yum/commands/install.rb +18 -0
- data/lib/kanrisuru/core/yum/commands/list.rb +30 -0
- data/lib/kanrisuru/core/yum/commands/localinstall.rb +22 -0
- data/lib/kanrisuru/core/yum/commands/remove.rb +20 -0
- data/lib/kanrisuru/core/yum/commands/repolist.rb +20 -0
- data/lib/kanrisuru/core/yum/commands/search.rb +21 -0
- data/lib/kanrisuru/core/yum/commands/update.rb +14 -0
- data/lib/kanrisuru/core/yum/commands/upgrade.rb +14 -0
- data/lib/kanrisuru/core/yum/commands.rb +39 -0
- data/lib/kanrisuru/core/yum/parser.rb +7 -0
- data/lib/kanrisuru/core/yum/parsers/base.rb +31 -0
- data/lib/kanrisuru/core/yum/parsers/info.rb +69 -0
- data/lib/kanrisuru/core/yum/parsers/list.rb +24 -0
- data/lib/kanrisuru/core/yum/parsers/repolist.rb +60 -0
- data/lib/kanrisuru/core/yum/parsers/search.rb +30 -0
- data/lib/kanrisuru/core/yum/types.rb +41 -0
- data/lib/kanrisuru/core/yum.rb +4 -347
- data/lib/kanrisuru/core/zypper/commands/add_lock.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/add_repo.rb +38 -0
- data/lib/kanrisuru/core/zypper/commands/add_service.rb +26 -0
- data/lib/kanrisuru/core/zypper/commands/clean_cache.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/clean_locks.rb +17 -0
- data/lib/kanrisuru/core/zypper/commands/dist_upgrade.rb +25 -0
- data/lib/kanrisuru/core/zypper/commands/info.rb +25 -0
- data/lib/kanrisuru/core/zypper/commands/install.rb +39 -0
- data/lib/kanrisuru/core/zypper/commands/install_new_recommends.rb +23 -0
- data/lib/kanrisuru/core/zypper/commands/list_locks.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/list_patches.rb +34 -0
- data/lib/kanrisuru/core/zypper/commands/list_repos.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/list_services.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/list_updates.rb +30 -0
- data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +48 -0
- data/lib/kanrisuru/core/zypper/commands/modify_service.rb +40 -0
- data/lib/kanrisuru/core/zypper/commands/patch.rb +40 -0
- data/lib/kanrisuru/core/zypper/commands/patch_check.rb +29 -0
- data/lib/kanrisuru/core/zypper/commands/purge_kernels.rb +18 -0
- data/lib/kanrisuru/core/zypper/commands/refresh_repos.rb +24 -0
- data/lib/kanrisuru/core/zypper/commands/refresh_services.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/remove.rb +26 -0
- data/lib/kanrisuru/core/zypper/commands/remove_lock.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +32 -0
- data/lib/kanrisuru/core/zypper/commands/remove_service.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/rename_repo.rb +20 -0
- data/lib/kanrisuru/core/zypper/commands/search.rb +52 -0
- data/lib/kanrisuru/core/zypper/commands/source_install.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/update.rb +27 -0
- data/lib/kanrisuru/core/zypper/commands/verify.rb +23 -0
- data/lib/kanrisuru/core/zypper/commands.rb +109 -0
- data/lib/kanrisuru/core/zypper/constants.rb +19 -0
- data/lib/kanrisuru/core/zypper/parser.rb +11 -0
- data/lib/kanrisuru/core/zypper/parsers/base.rb +18 -0
- data/lib/kanrisuru/core/zypper/parsers/info.rb +77 -0
- data/lib/kanrisuru/core/zypper/parsers/list_locks.rb +36 -0
- data/lib/kanrisuru/core/zypper/parsers/list_patches.rb +40 -0
- data/lib/kanrisuru/core/zypper/parsers/list_repos.rb +37 -0
- data/lib/kanrisuru/core/zypper/parsers/list_services.rb +36 -0
- data/lib/kanrisuru/core/zypper/parsers/list_updates.rb +32 -0
- data/lib/kanrisuru/core/zypper/parsers/patch_check.rb +34 -0
- data/lib/kanrisuru/core/zypper/parsers/search.rb +37 -0
- data/lib/kanrisuru/core/zypper/types.rb +88 -0
- data/lib/kanrisuru/core/zypper.rb +5 -998
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/unit/util_spec.rb +16 -0
- metadata +231 -2
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module Transfer
|
6
|
+
def download(remote_path, local_path = nil, opts = {})
|
7
|
+
if local_path.instance_of?(Hash)
|
8
|
+
opts = local_path
|
9
|
+
local_path = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
tmp_path = "/tmp/kanrisuru-tmp-#{Time.now.to_i}-#{object_id}"
|
13
|
+
|
14
|
+
begin
|
15
|
+
result = cp(remote_path, tmp_path, force: true)
|
16
|
+
raise 'Unable to copy remote file to temp path' unless result.success?
|
17
|
+
|
18
|
+
result = ssh.scp.download!(tmp_path, local_path, opts)
|
19
|
+
Kanrisuru::Util.blank?(local_path) ? result : local_path
|
20
|
+
ensure
|
21
|
+
rm(tmp_path, force: true) if inode?(tmp_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module Transfer
|
6
|
+
def upload(local_path, remote_path, opts = {})
|
7
|
+
tmp_path = "/tmp/kanrisuru-tmp-#{Time.now.to_i}-#{object_id}"
|
8
|
+
|
9
|
+
begin
|
10
|
+
result = ssh.scp.upload!(local_path, tmp_path, opts)
|
11
|
+
raise 'Unable to upload file' unless result
|
12
|
+
|
13
|
+
result = mv(tmp_path, remote_path)
|
14
|
+
raise 'Unable to move file to remote path' unless result.success?
|
15
|
+
|
16
|
+
stat(remote_path)
|
17
|
+
ensure
|
18
|
+
rm(tmp_path, force: true) if inode?(tmp_path)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module Transfer
|
6
|
+
def wget(url, opts = {})
|
7
|
+
command = Kanrisuru::Command.new('wget')
|
8
|
+
|
9
|
+
## Logging and input
|
10
|
+
command.append_flag('--quiet', opts[:quiet])
|
11
|
+
|
12
|
+
case opts[:verbose]
|
13
|
+
when true
|
14
|
+
command.append_flag('--verbose')
|
15
|
+
when false
|
16
|
+
command.append_flag('--no-verbose')
|
17
|
+
end
|
18
|
+
|
19
|
+
command.append_arg('--output-file', opts[:log_file])
|
20
|
+
command.append_arg('--append-output', opts[:append_log_file])
|
21
|
+
|
22
|
+
## Download
|
23
|
+
command.append_arg('--bind-address', opts[:bind_address])
|
24
|
+
command.append_arg('--tries', opts[:retries])
|
25
|
+
command.append_arg('--output-document', opts[:output_document])
|
26
|
+
command.append_flag('--no-clobber', opts[:no_clobber])
|
27
|
+
command.append_flag('--continue', opts[:continue])
|
28
|
+
command.append_flag('--server-response', opts[:server_response])
|
29
|
+
command.append_flag('--spider', opts[:spider])
|
30
|
+
command.append_arg('--timeout', opts[:timeout])
|
31
|
+
command.append_arg('--dns-timeout', opts[:dns_timeout])
|
32
|
+
command.append_arg('--connect-timeout', opts[:connect_timeout])
|
33
|
+
command.append_arg('--read-timeout', opts[:read_timeout])
|
34
|
+
command.append_arg('--limit-rate', opts[:limit_rate])
|
35
|
+
command.append_arg('--wait', opts[:wait])
|
36
|
+
command.append_arg('--waitretry', opts[:waitretry])
|
37
|
+
command.append_flag('--random-wait', opts[:random_wait])
|
38
|
+
command.append_flag('--no-proxy', opts[:no_proxy])
|
39
|
+
command.append_flag('--no-dns-cache', opts[:no_dns_cache])
|
40
|
+
|
41
|
+
command.append_arg('--quota', opts[:quota])
|
42
|
+
|
43
|
+
if Kanrisuru::Util.present?(opts[:restrict_file_names])
|
44
|
+
command.append_arg('--restrict-file-names', Kanrisuru::Util.array_join_string(opts[:restrict_file_names]))
|
45
|
+
end
|
46
|
+
|
47
|
+
case opts[:family]
|
48
|
+
when 'inet'
|
49
|
+
command.append_flag('--inet4-only')
|
50
|
+
when 'inet6'
|
51
|
+
command.append_flag('--inet6-only')
|
52
|
+
end
|
53
|
+
|
54
|
+
command.append_flag('--retry-connrefused', opts[:retry_connrefused])
|
55
|
+
command.append_arg('--user', opts[:user])
|
56
|
+
command.append_arg('--password', opts[:password])
|
57
|
+
command.append_flag('--no-iri', opts[:no_iri])
|
58
|
+
command.append_arg('--local-encoding', opts[:local_encoding])
|
59
|
+
command.append_arg('--remote-encoding', opts[:remote_encoding])
|
60
|
+
|
61
|
+
## Directories
|
62
|
+
command.append_flag('--no-directories', opts[:no_directories])
|
63
|
+
command.append_flag('--force-directories', opts[:force_directories])
|
64
|
+
command.append_flag('--no-host-directories', opts[:no_host_directories])
|
65
|
+
command.append_flag('--protocol-directories', opts[:protocol_directories])
|
66
|
+
command.append_arg('--cut-dirs', opts[:cut_dirs])
|
67
|
+
command.append_arg('--directory-prefix', opts[:directory_prefix])
|
68
|
+
|
69
|
+
## HTTP
|
70
|
+
command.append_arg('--default-page', opts[:default_page])
|
71
|
+
command.append_flag('--adjust-extension', opts[:adjust_extension])
|
72
|
+
command.append_arg('--http-user', opts[:http_user])
|
73
|
+
command.append_arg('--http-password', opts[:http_password])
|
74
|
+
command.append_arg('--load-cookies', opts[:load_cookies])
|
75
|
+
command.append_arg('--save-cookies', opts[:save_cookies])
|
76
|
+
command.append_flag('--no-http-keep-alive', opts[:no_http_keep_alive])
|
77
|
+
command.append_flag('--no-cache', opts[:no_cache])
|
78
|
+
command.append_flag('--no-cookies', opts[:no_cookies])
|
79
|
+
command.append_flag('--keep-session-cookies', opts[:keep_session_cookies])
|
80
|
+
command.append_flag('--ignore-length', opts[:ignore_length])
|
81
|
+
command.append_arg('--max-redirect', opts[:max_redirect])
|
82
|
+
command.append_arg('--proxy-user', opts[:proxy_user])
|
83
|
+
command.append_arg('--proxy-password', opts[:proxy_password])
|
84
|
+
command.append_arg('--referer', opts[:referer])
|
85
|
+
command.append_flag('--save-headers', opts[:save_headers])
|
86
|
+
command.append_arg('--user-agent', opts[:user_agent])
|
87
|
+
|
88
|
+
headers = opts[:headers]
|
89
|
+
if Kanrisuru::Util.present?(headers)
|
90
|
+
if headers.instance_of?(Hash)
|
91
|
+
headers.each do |key, value|
|
92
|
+
header = "'#{key}: #{value}'"
|
93
|
+
command.append_arg('--header', header)
|
94
|
+
end
|
95
|
+
elsif headers.instance_of?(String)
|
96
|
+
command.append_arg('--header', headers)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
post_data = opts[:post_data]
|
101
|
+
|
102
|
+
if Kanrisuru::Util.present?(post_data)
|
103
|
+
post_data = post_data.instance_of?(Hash) ? URI.encode_www_form(post_data) : post_data
|
104
|
+
command.append_arg('--post-data', post_data)
|
105
|
+
end
|
106
|
+
|
107
|
+
command.append_arg('--post-file', opts[:post_file])
|
108
|
+
command.append_flag('--content-disposition', opts[:content_disposition])
|
109
|
+
|
110
|
+
## SSL / TLS
|
111
|
+
if Kanrisuru::Util.present?(opts[:secure_protocol])
|
112
|
+
raise ArgumentError, 'invalid ssl protocol' unless WGET_SSL_PROTO.include?(opts[:secure_protocol])
|
113
|
+
|
114
|
+
command.append_arg('--secure-protocol', opts[:secure_protocol])
|
115
|
+
end
|
116
|
+
|
117
|
+
command.append_flag('--no-check-certificate', opts[:no_check_certificate])
|
118
|
+
command.append_arg('--certificate', opts[:certificate])
|
119
|
+
command.append_arg('--certificate-type', opts[:certificate_type])
|
120
|
+
command.append_arg('--private-key', opts[:private_key])
|
121
|
+
command.append_arg('--private-key-type', opts[:private_key_type])
|
122
|
+
command.append_arg('--ca-certificate', opts[:ca_certificate])
|
123
|
+
command.append_arg('--ca-directory', opts[:ca_directory])
|
124
|
+
command.append_arg('--random-file', opts[:random_file])
|
125
|
+
command.append_arg('--egd-file', opts[:egd_file])
|
126
|
+
|
127
|
+
## FTP
|
128
|
+
command.append_arg('--ftp-user', opts[:ftp_user])
|
129
|
+
command.append_arg('--ftp-password', opts[:ftp_password])
|
130
|
+
command.append_flag('--no-remove-listing', opts[:no_remove_listing])
|
131
|
+
command.append_flag('--no-glob', opts[:no_glob])
|
132
|
+
command.append_flag('--no-passive-ftp', opts[:no_passive_ftp])
|
133
|
+
command.append_flag('--retr-symlinks', opts[:retr_symlinks])
|
134
|
+
|
135
|
+
## Recursive Retrieval
|
136
|
+
command.append_flag('--recursive', opts[:recursive])
|
137
|
+
command.append_arg('--level', opts[:depth])
|
138
|
+
command.append_flag('--delete-after', opts[:delete_after])
|
139
|
+
command.append_flag('--convert-links', opts[:convert_links])
|
140
|
+
command.append_flag('--backup-converted', opts[:backup_converted])
|
141
|
+
command.append_flag('--mirror', opts[:mirror])
|
142
|
+
command.append_flag('--page-requisites', opts[:page_requisites])
|
143
|
+
command.append_flag('--strict-comments', opts[:strict_comments])
|
144
|
+
|
145
|
+
## Recursive Accept/Reject
|
146
|
+
command.append_arg('--accept', Kanrisuru::Util.array_join_string(opts[:accept_list]))
|
147
|
+
command.append_arg('--reject', Kanrisuru::Util.array_join_string(opts[:reject_list]))
|
148
|
+
command.append_arg('--domains', Kanrisuru::Util.array_join_string(opts[:domain_list]))
|
149
|
+
command.append_arg('--exclude-domains', Kanrisuru::Util.array_join_string(opts[:exclude_domain_list]))
|
150
|
+
command.append_arg('--follow-tags', Kanrisuru::Util.array_join_string(opts[:follow_tags]))
|
151
|
+
command.append_arg('--ignore-tags', Kanrisuru::Util.array_join_string(opts[:ignore_tags]))
|
152
|
+
command.append_arg('--include-directories', Kanrisuru::Util.array_join_string(opts[:include_directories]))
|
153
|
+
command.append_arg('--exclude-directories', Kanrisuru::Util.array_join_string(opts[:exclude_directories]))
|
154
|
+
command.append_flag('--follow-ftp', opts[:follow_ftp])
|
155
|
+
command.append_flag('--ignore-case', opts[:ignore_case])
|
156
|
+
command.append_flag('--span-hosts', opts[:span_hosts])
|
157
|
+
command.append_flag('--relative', opts[:relative])
|
158
|
+
command.append_flag('--no-parent', opts[:no_parent])
|
159
|
+
|
160
|
+
command << url
|
161
|
+
|
162
|
+
execute_shell(command)
|
163
|
+
|
164
|
+
Kanrisuru::Result.new(command)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
|
+
require_relative 'transfer/constants'
|
6
|
+
require_relative 'transfer/commands'
|
7
|
+
|
5
8
|
module Kanrisuru
|
6
9
|
module Core
|
7
10
|
module Transfer
|
@@ -10,205 +13,6 @@ module Kanrisuru
|
|
10
13
|
os_define :linux, :download
|
11
14
|
os_define :linux, :upload
|
12
15
|
os_define :linux, :wget
|
13
|
-
|
14
|
-
WGET_FILENAME_MODES = %w[unix windows nocontrol ascii lowercase uppercase].freeze
|
15
|
-
WGET_SSL_PROTO = %w[auto SSLv2 SSLv3 TLSv1].freeze
|
16
|
-
|
17
|
-
def download(remote_path, local_path = nil, opts = {})
|
18
|
-
if local_path.instance_of?(Hash)
|
19
|
-
opts = local_path
|
20
|
-
local_path = nil
|
21
|
-
end
|
22
|
-
|
23
|
-
tmp_path = "/tmp/kanrisuru-tmp-#{Time.now.to_i}-#{object_id}"
|
24
|
-
|
25
|
-
begin
|
26
|
-
result = cp(remote_path, tmp_path, force: true)
|
27
|
-
raise 'Unable to copy remote file to temp path' unless result.success?
|
28
|
-
|
29
|
-
result = ssh.scp.download!(tmp_path, local_path, opts)
|
30
|
-
Kanrisuru::Util.blank?(local_path) ? result : local_path
|
31
|
-
ensure
|
32
|
-
rm(tmp_path, force: true) if inode?(tmp_path)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def upload(local_path, remote_path, opts = {})
|
37
|
-
tmp_path = "/tmp/kanrisuru-tmp-#{Time.now.to_i}-#{object_id}"
|
38
|
-
|
39
|
-
begin
|
40
|
-
result = ssh.scp.upload!(local_path, tmp_path, opts)
|
41
|
-
raise 'Unable to upload file' unless result
|
42
|
-
|
43
|
-
result = mv(tmp_path, remote_path)
|
44
|
-
raise 'Unable to move file to remote path' unless result.success?
|
45
|
-
|
46
|
-
stat(remote_path)
|
47
|
-
ensure
|
48
|
-
rm(tmp_path, force: true) if inode?(tmp_path)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def wget(url, opts = {})
|
53
|
-
command = Kanrisuru::Command.new('wget')
|
54
|
-
|
55
|
-
## Logging and input
|
56
|
-
command.append_flag('--quiet', opts[:quiet])
|
57
|
-
|
58
|
-
case opts[:verbose]
|
59
|
-
when true
|
60
|
-
command.append_flag('--verbose')
|
61
|
-
when false
|
62
|
-
command.append_flag('--no-verbose')
|
63
|
-
end
|
64
|
-
|
65
|
-
command.append_arg('--output-file', opts[:log_file])
|
66
|
-
command.append_arg('--append-output', opts[:append_log_file])
|
67
|
-
|
68
|
-
## Download
|
69
|
-
command.append_arg('--bind-address', opts[:bind_address])
|
70
|
-
command.append_arg('--tries', opts[:retries])
|
71
|
-
command.append_arg('--output-document', opts[:output_document])
|
72
|
-
command.append_flag('--no-clobber', opts[:no_clobber])
|
73
|
-
command.append_flag('--continue', opts[:continue])
|
74
|
-
command.append_flag('--server-response', opts[:server_response])
|
75
|
-
command.append_flag('--spider', opts[:spider])
|
76
|
-
command.append_arg('--timeout', opts[:timeout])
|
77
|
-
command.append_arg('--dns-timeout', opts[:dns_timeout])
|
78
|
-
command.append_arg('--connect-timeout', opts[:connect_timeout])
|
79
|
-
command.append_arg('--read-timeout', opts[:read_timeout])
|
80
|
-
command.append_arg('--limit-rate', opts[:limit_rate])
|
81
|
-
command.append_arg('--wait', opts[:wait])
|
82
|
-
command.append_arg('--waitretry', opts[:waitretry])
|
83
|
-
command.append_flag('--random-wait', opts[:random_wait])
|
84
|
-
command.append_flag('--no-proxy', opts[:no_proxy])
|
85
|
-
command.append_flag('--no-dns-cache', opts[:no_dns_cache])
|
86
|
-
|
87
|
-
command.append_arg('--quota', opts[:quota])
|
88
|
-
|
89
|
-
if Kanrisuru::Util.present?(opts[:restrict_file_names])
|
90
|
-
command.append_arg('--restrict-file-names', Kanrisuru::Util.array_join_string(opts[:restrict_file_names]))
|
91
|
-
end
|
92
|
-
|
93
|
-
case opts[:family]
|
94
|
-
when 'inet'
|
95
|
-
command.append_flag('--inet4-only')
|
96
|
-
when 'inet6'
|
97
|
-
command.append_flag('--inet6-only')
|
98
|
-
end
|
99
|
-
|
100
|
-
command.append_flag('--retry-connrefused', opts[:retry_connrefused])
|
101
|
-
command.append_arg('--user', opts[:user])
|
102
|
-
command.append_arg('--password', opts[:password])
|
103
|
-
command.append_flag('--no-iri', opts[:no_iri])
|
104
|
-
command.append_arg('--local-encoding', opts[:local_encoding])
|
105
|
-
command.append_arg('--remote-encoding', opts[:remote_encoding])
|
106
|
-
|
107
|
-
## Directories
|
108
|
-
command.append_flag('--no-directories', opts[:no_directories])
|
109
|
-
command.append_flag('--force-directories', opts[:force_directories])
|
110
|
-
command.append_flag('--no-host-directories', opts[:no_host_directories])
|
111
|
-
command.append_flag('--protocol-directories', opts[:protocol_directories])
|
112
|
-
command.append_arg('--cut-dirs', opts[:cut_dirs])
|
113
|
-
command.append_arg('--directory-prefix', opts[:directory_prefix])
|
114
|
-
|
115
|
-
## HTTP
|
116
|
-
command.append_arg('--default-page', opts[:default_page])
|
117
|
-
command.append_flag('--adjust-extension', opts[:adjust_extension])
|
118
|
-
command.append_arg('--http-user', opts[:http_user])
|
119
|
-
command.append_arg('--http-password', opts[:http_password])
|
120
|
-
command.append_arg('--load-cookies', opts[:load_cookies])
|
121
|
-
command.append_arg('--save-cookies', opts[:save_cookies])
|
122
|
-
command.append_flag('--no-http-keep-alive', opts[:no_http_keep_alive])
|
123
|
-
command.append_flag('--no-cache', opts[:no_cache])
|
124
|
-
command.append_flag('--no-cookies', opts[:no_cookies])
|
125
|
-
command.append_flag('--keep-session-cookies', opts[:keep_session_cookies])
|
126
|
-
command.append_flag('--ignore-length', opts[:ignore_length])
|
127
|
-
command.append_arg('--max-redirect', opts[:max_redirect])
|
128
|
-
command.append_arg('--proxy-user', opts[:proxy_user])
|
129
|
-
command.append_arg('--proxy-password', opts[:proxy_password])
|
130
|
-
command.append_arg('--referer', opts[:referer])
|
131
|
-
command.append_flag('--save-headers', opts[:save_headers])
|
132
|
-
command.append_arg('--user-agent', opts[:user_agent])
|
133
|
-
|
134
|
-
headers = opts[:headers]
|
135
|
-
if Kanrisuru::Util.present?(headers)
|
136
|
-
if headers.instance_of?(Hash)
|
137
|
-
headers.each do |key, value|
|
138
|
-
header = "'#{key}: #{value}'"
|
139
|
-
command.append_arg('--header', header)
|
140
|
-
end
|
141
|
-
elsif headers.instance_of?(String)
|
142
|
-
command.append_arg('--header', headers)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
post_data = opts[:post_data]
|
147
|
-
|
148
|
-
if Kanrisuru::Util.present?(post_data)
|
149
|
-
post_data = post_data.instance_of?(Hash) ? URI.encode_www_form(post_data) : post_data
|
150
|
-
command.append_arg('--post-data', post_data)
|
151
|
-
end
|
152
|
-
|
153
|
-
command.append_arg('--post-file', opts[:post_file])
|
154
|
-
command.append_flag('--content-disposition', opts[:content_disposition])
|
155
|
-
|
156
|
-
## SSL / TLS
|
157
|
-
if Kanrisuru::Util.present?(opts[:secure_protocol])
|
158
|
-
raise ArgumentError, 'invalid ssl protocol' unless WGET_SSL_PROTO.include?(opts[:secure_protocol])
|
159
|
-
|
160
|
-
command.append_arg('--secure-protocol', opts[:secure_protocol])
|
161
|
-
end
|
162
|
-
|
163
|
-
command.append_flag('--no-check-certificate', opts[:no_check_certificate])
|
164
|
-
command.append_arg('--certificate', opts[:certificate])
|
165
|
-
command.append_arg('--certificate-type', opts[:certificate_type])
|
166
|
-
command.append_arg('--private-key', opts[:private_key])
|
167
|
-
command.append_arg('--private-key-type', opts[:private_key_type])
|
168
|
-
command.append_arg('--ca-certificate', opts[:ca_certificate])
|
169
|
-
command.append_arg('--ca-directory', opts[:ca_directory])
|
170
|
-
command.append_arg('--random-file', opts[:random_file])
|
171
|
-
command.append_arg('--egd-file', opts[:egd_file])
|
172
|
-
|
173
|
-
## FTP
|
174
|
-
command.append_arg('--ftp-user', opts[:ftp_user])
|
175
|
-
command.append_arg('--ftp-password', opts[:ftp_password])
|
176
|
-
command.append_flag('--no-remove-listing', opts[:no_remove_listing])
|
177
|
-
command.append_flag('--no-glob', opts[:no_glob])
|
178
|
-
command.append_flag('--no-passive-ftp', opts[:no_passive_ftp])
|
179
|
-
command.append_flag('--retr-symlinks', opts[:retr_symlinks])
|
180
|
-
|
181
|
-
## Recursive Retrieval
|
182
|
-
command.append_flag('--recursive', opts[:recursive])
|
183
|
-
command.append_arg('--level', opts[:depth])
|
184
|
-
command.append_flag('--delete-after', opts[:delete_after])
|
185
|
-
command.append_flag('--convert-links', opts[:convert_links])
|
186
|
-
command.append_flag('--backup-converted', opts[:backup_converted])
|
187
|
-
command.append_flag('--mirror', opts[:mirror])
|
188
|
-
command.append_flag('--page-requisites', opts[:page_requisites])
|
189
|
-
command.append_flag('--strict-comments', opts[:strict_comments])
|
190
|
-
|
191
|
-
## Recursive Accept/Reject
|
192
|
-
command.append_arg('--accept', Kanrisuru::Util.array_join_string(opts[:accept_list]))
|
193
|
-
command.append_arg('--reject', Kanrisuru::Util.array_join_string(opts[:reject_list]))
|
194
|
-
command.append_arg('--domains', Kanrisuru::Util.array_join_string(opts[:domain_list]))
|
195
|
-
command.append_arg('--exclude-domains', Kanrisuru::Util.array_join_string(opts[:exclude_domain_list]))
|
196
|
-
command.append_arg('--follow-tags', Kanrisuru::Util.array_join_string(opts[:follow_tags]))
|
197
|
-
command.append_arg('--ignore-tags', Kanrisuru::Util.array_join_string(opts[:ignore_tags]))
|
198
|
-
command.append_arg('--include-directories', Kanrisuru::Util.array_join_string(opts[:include_directories]))
|
199
|
-
command.append_arg('--exclude-directories', Kanrisuru::Util.array_join_string(opts[:exclude_directories]))
|
200
|
-
command.append_flag('--follow-ftp', opts[:follow_ftp])
|
201
|
-
command.append_flag('--ignore-case', opts[:ignore_case])
|
202
|
-
command.append_flag('--span-hosts', opts[:span_hosts])
|
203
|
-
command.append_flag('--relative', opts[:relative])
|
204
|
-
command.append_flag('--no-parent', opts[:no_parent])
|
205
|
-
|
206
|
-
command << url
|
207
|
-
|
208
|
-
execute_shell(command)
|
209
|
-
|
210
|
-
Kanrisuru::Result.new(command)
|
211
|
-
end
|
212
16
|
end
|
213
17
|
end
|
214
18
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module User
|
6
|
+
def create_user(user, opts = {})
|
7
|
+
uid = opts[:uid]
|
8
|
+
group = opts[:group]
|
9
|
+
groups = opts[:groups]
|
10
|
+
home = opts[:home]
|
11
|
+
shell = opts[:shell] || '/bin/false'
|
12
|
+
createhome = opts[:createhome]
|
13
|
+
system_opt = opts[:system]
|
14
|
+
skeleton = opts[:skeleton]
|
15
|
+
non_unique = opts[:non_unique]
|
16
|
+
password = opts[:password]
|
17
|
+
expires = opts[:expires] ## YYYY-MM-DD
|
18
|
+
|
19
|
+
command = Kanrisuru::Command.new("useradd #{user}")
|
20
|
+
|
21
|
+
if Kanrisuru::Util.present?(uid)
|
22
|
+
command.append_arg('-u', uid)
|
23
|
+
command.append_flag('-o', non_unique)
|
24
|
+
end
|
25
|
+
|
26
|
+
command.append_flag('-r', system_opt)
|
27
|
+
command.append_arg('-s', shell)
|
28
|
+
command.append_arg('-d', home)
|
29
|
+
|
30
|
+
case createhome
|
31
|
+
when true
|
32
|
+
command.append_flag('-m')
|
33
|
+
command.append_arg('-k', skeleton)
|
34
|
+
when false
|
35
|
+
command.append_flag('-M')
|
36
|
+
end
|
37
|
+
|
38
|
+
if Kanrisuru::Util.present?(group) && group?(group)
|
39
|
+
command.append_arg('-g', group)
|
40
|
+
elsif group?(user)
|
41
|
+
command.append_flag('-N')
|
42
|
+
end
|
43
|
+
|
44
|
+
command.append_arg('-G', groups.join(',')) if Kanrisuru::Util.present?(groups)
|
45
|
+
|
46
|
+
command.append_arg('-p', password)
|
47
|
+
command.append_arg('-e', expires)
|
48
|
+
|
49
|
+
execute_shell(command)
|
50
|
+
|
51
|
+
Kanrisuru::Result.new(command) do
|
52
|
+
get_user(user).data
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module User
|
6
|
+
def delete_user(user, opts = {})
|
7
|
+
force = opts[:force]
|
8
|
+
|
9
|
+
return false unless get_uid(user)
|
10
|
+
|
11
|
+
command = Kanrisuru::Command.new("userdel #{user}")
|
12
|
+
command.append_flag('-f', force)
|
13
|
+
|
14
|
+
execute_shell(command)
|
15
|
+
|
16
|
+
Kanrisuru::Result.new(command)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module User
|
6
|
+
def get_user(user)
|
7
|
+
command = Kanrisuru::Command.new("id #{user}")
|
8
|
+
execute_shell(command)
|
9
|
+
|
10
|
+
Kanrisuru::Result.new(command) do |cmd|
|
11
|
+
## Get user id
|
12
|
+
result = get_uid(user)
|
13
|
+
break if result.failure?
|
14
|
+
|
15
|
+
uid = result.to_i
|
16
|
+
|
17
|
+
## Get all groups for the user, with gid and group name
|
18
|
+
array = Parser::Groups.parse(cmd)
|
19
|
+
|
20
|
+
groups = array.map do |str|
|
21
|
+
gid = str.delete('^0-9').to_i
|
22
|
+
name = str.delete('0-9')
|
23
|
+
UserGroup.new(gid, name)
|
24
|
+
end
|
25
|
+
|
26
|
+
## Get home / shell path information
|
27
|
+
cmd = Kanrisuru::Command.new("getent passwd #{user}")
|
28
|
+
cmd | "awk -F: '{print $6, $7}'"
|
29
|
+
|
30
|
+
execute(cmd)
|
31
|
+
|
32
|
+
result = Kanrisuru::Result.new(cmd) do |cmd2|
|
33
|
+
Parser::Getent.parse(cmd2)
|
34
|
+
end
|
35
|
+
|
36
|
+
## TODO: Raise custom error to change parent result to use nested error and mark
|
37
|
+
## as failure.
|
38
|
+
break if result.failure?
|
39
|
+
|
40
|
+
home = result[0]
|
41
|
+
shell = result[1]
|
42
|
+
|
43
|
+
User.new(uid, user, home, shell, groups)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module User
|
6
|
+
def user?(user)
|
7
|
+
result = get_uid(user)
|
8
|
+
return false if result.failure?
|
9
|
+
|
10
|
+
Kanrisuru::Util.present?(result.data) && result.data.instance_of?(Integer)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Core
|
5
|
+
module User
|
6
|
+
def update_user(user, opts = {})
|
7
|
+
uid = opts[:uid]
|
8
|
+
group = opts[:group]
|
9
|
+
groups = opts[:groups]
|
10
|
+
append = opts[:append]
|
11
|
+
home = opts[:home]
|
12
|
+
move_home = opts[:move_home]
|
13
|
+
shell = opts[:shell] || '/bin/false'
|
14
|
+
non_unique = opts[:non_unique]
|
15
|
+
password = opts[:password]
|
16
|
+
expires = opts[:expires] ## YYYY-MM-DD
|
17
|
+
locked = opts[:locked]
|
18
|
+
|
19
|
+
command = Kanrisuru::Command.new("usermod #{user}")
|
20
|
+
|
21
|
+
if Kanrisuru::Util.present?(home)
|
22
|
+
command.append_arg('-d', home)
|
23
|
+
command.append_flag('-m', move_home)
|
24
|
+
end
|
25
|
+
|
26
|
+
command.append_arg('-s', shell)
|
27
|
+
|
28
|
+
if Kanrisuru::Util.present?(uid)
|
29
|
+
command.append_arg('-u', uid)
|
30
|
+
command.append_flag('-o', non_unique)
|
31
|
+
end
|
32
|
+
|
33
|
+
command.append_arg('-g', group) if Kanrisuru::Util.present?(group) && group_exists?(group)
|
34
|
+
|
35
|
+
if Kanrisuru::Util.present?(groups)
|
36
|
+
command.append_arg('-G', groups.join(','))
|
37
|
+
command.append_flag('-a', append)
|
38
|
+
end
|
39
|
+
|
40
|
+
case locked
|
41
|
+
when true
|
42
|
+
command.append_flag('-L')
|
43
|
+
command.append_arg('-e', 1)
|
44
|
+
when false
|
45
|
+
command.append_arg('-U')
|
46
|
+
command.append_arg('-e', 99_999)
|
47
|
+
else
|
48
|
+
## Ensure expires isn't added twice.
|
49
|
+
command.append_arg('-e', expires)
|
50
|
+
|
51
|
+
## Can't use password with lock / unlock flag.
|
52
|
+
command.append_arg('-p', password)
|
53
|
+
end
|
54
|
+
|
55
|
+
execute_shell(command)
|
56
|
+
|
57
|
+
Kanrisuru::Result.new(command) do |_command|
|
58
|
+
get_user(user).data
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|