kanrisuru 0.13.0 → 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/README.md +5 -5
  4. data/kanrisuru.gemspec +7 -3
  5. data/lib/kanrisuru/command.rb +15 -1
  6. data/lib/kanrisuru/core/apt/commands/autoclean.rb +13 -0
  7. data/lib/kanrisuru/core/apt/commands/autoremove.rb +15 -0
  8. data/lib/kanrisuru/core/apt/commands/clean.rb +13 -0
  9. data/lib/kanrisuru/core/apt/commands/full_upgrade.rb +14 -0
  10. data/lib/kanrisuru/core/apt/commands/install.rb +22 -0
  11. data/lib/kanrisuru/core/apt/commands/list.rb +21 -0
  12. data/lib/kanrisuru/core/apt/commands/purge.rb +18 -0
  13. data/lib/kanrisuru/core/apt/commands/remove.rb +18 -0
  14. data/lib/kanrisuru/core/apt/commands/search.rb +18 -0
  15. data/lib/kanrisuru/core/apt/commands/show.rb +21 -0
  16. data/lib/kanrisuru/core/apt/commands/update.rb +14 -0
  17. data/lib/kanrisuru/core/apt/commands/upgrade.rb +14 -0
  18. data/lib/kanrisuru/core/apt/commands.rb +14 -0
  19. data/lib/kanrisuru/core/apt/parser.rb +6 -0
  20. data/lib/kanrisuru/core/apt/parsers/base.rb +51 -0
  21. data/lib/kanrisuru/core/apt/parsers/list.rb +28 -0
  22. data/lib/kanrisuru/core/apt/parsers/search.rb +32 -0
  23. data/lib/kanrisuru/core/apt/parsers/show.rb +90 -0
  24. data/lib/kanrisuru/core/apt/types.rb +36 -0
  25. data/lib/kanrisuru/core/apt.rb +4 -284
  26. data/lib/kanrisuru/core/archive/commands/tar.rb +126 -0
  27. data/lib/kanrisuru/core/archive/commands.rb +3 -0
  28. data/lib/kanrisuru/core/archive/types.rb +9 -0
  29. data/lib/kanrisuru/core/archive.rb +3 -121
  30. data/lib/kanrisuru/core/disk/commands/blkid.rb +35 -0
  31. data/lib/kanrisuru/core/disk/commands/df.rb +26 -0
  32. data/lib/kanrisuru/core/disk/commands/du.rb +24 -0
  33. data/lib/kanrisuru/core/disk/commands/lsblk.rb +49 -0
  34. data/lib/kanrisuru/core/disk/commands.rb +6 -0
  35. data/lib/kanrisuru/core/disk/constants.rb +9 -0
  36. data/lib/kanrisuru/core/disk/parser.rb +7 -0
  37. data/lib/kanrisuru/core/disk/parsers/blkid.rb +72 -0
  38. data/lib/kanrisuru/core/disk/parsers/df.rb +33 -0
  39. data/lib/kanrisuru/core/disk/parsers/du.rb +25 -0
  40. data/lib/kanrisuru/core/disk/parsers/lsblk.rb +96 -0
  41. data/lib/kanrisuru/core/disk/parsers/lsblk_version.rb +21 -0
  42. data/lib/kanrisuru/core/disk/types.rb +21 -0
  43. data/lib/kanrisuru/core/disk.rb +6 -290
  44. data/lib/kanrisuru/core/dmi/commands/dmi.rb +42 -0
  45. data/lib/kanrisuru/core/dmi/commands.rb +3 -0
  46. data/lib/kanrisuru/core/dmi/parser.rb +3 -0
  47. data/lib/kanrisuru/core/dmi/parsers/dmi.rb +149 -0
  48. data/lib/kanrisuru/core/dmi/types.rb +361 -0
  49. data/lib/kanrisuru/core/dmi.rb +4 -522
  50. data/lib/kanrisuru/core/file/commands/chmod.rb +29 -0
  51. data/lib/kanrisuru/core/file/commands/chown.rb +35 -0
  52. data/lib/kanrisuru/core/file/commands/copy.rb +54 -0
  53. data/lib/kanrisuru/core/file/commands/link.rb +25 -0
  54. data/lib/kanrisuru/core/file/commands/mkdir.rb +42 -0
  55. data/lib/kanrisuru/core/file/commands/move.rb +48 -0
  56. data/lib/kanrisuru/core/file/commands/rm.rb +41 -0
  57. data/lib/kanrisuru/core/file/commands/symlink.rb +46 -0
  58. data/lib/kanrisuru/core/file/commands/touch.rb +34 -0
  59. data/lib/kanrisuru/core/file/commands/unlink.rb +13 -0
  60. data/lib/kanrisuru/core/file/commands/wc.rb +16 -0
  61. data/lib/kanrisuru/core/file/commands.rb +29 -0
  62. data/lib/kanrisuru/core/file/parser.rb +3 -0
  63. data/lib/kanrisuru/core/file/parsers/wc.rb +16 -0
  64. data/lib/kanrisuru/core/file/types.rb +9 -0
  65. data/lib/kanrisuru/core/file.rb +4 -312
  66. data/lib/kanrisuru/core/find/commands/find.rb +97 -0
  67. data/lib/kanrisuru/core/find/commands.rb +3 -0
  68. data/lib/kanrisuru/core/find/constants.rb +9 -0
  69. data/lib/kanrisuru/core/find/parser.rb +3 -0
  70. data/lib/kanrisuru/core/find/parsers/find.rb +18 -0
  71. data/lib/kanrisuru/core/find/types.rb +9 -0
  72. data/lib/kanrisuru/core/find.rb +5 -97
  73. data/lib/kanrisuru/core/group/commands/create_group.rb +21 -0
  74. data/lib/kanrisuru/core/group/commands/delete_group.rb +16 -0
  75. data/lib/kanrisuru/core/group/commands/get_gid.rb +17 -0
  76. data/lib/kanrisuru/core/group/commands/get_group.rb +29 -0
  77. data/lib/kanrisuru/core/group/commands/is_group.rb +14 -0
  78. data/lib/kanrisuru/core/group/commands/update_group.rb +23 -0
  79. data/lib/kanrisuru/core/group/commands.rb +8 -0
  80. data/lib/kanrisuru/core/group/parser.rb +4 -0
  81. data/lib/kanrisuru/core/group/parsers/gid.rb +15 -0
  82. data/lib/kanrisuru/core/group/parsers/group.rb +15 -0
  83. data/lib/kanrisuru/core/group/types.rb +10 -0
  84. data/lib/kanrisuru/core/group.rb +4 -81
  85. data/lib/kanrisuru/core/ip/commands/address.rb +86 -0
  86. data/lib/kanrisuru/core/ip/commands/address_label.rb +54 -0
  87. data/lib/kanrisuru/core/ip/commands/link.rb +116 -0
  88. data/lib/kanrisuru/core/ip/commands/link_set_opts.rb +61 -0
  89. data/lib/kanrisuru/core/ip/commands/link_type_opts.rb +313 -0
  90. data/lib/kanrisuru/core/ip/commands/maddress.rb +42 -0
  91. data/lib/kanrisuru/core/ip/commands/neighbour.rb +72 -0
  92. data/lib/kanrisuru/core/ip/commands/route.rb +152 -0
  93. data/lib/kanrisuru/core/ip/commands/rule.rb +57 -0
  94. data/lib/kanrisuru/core/ip/commands.rb +26 -0
  95. data/lib/kanrisuru/core/ip/constants.rb +25 -0
  96. data/lib/kanrisuru/core/ip/parser.rb +11 -0
  97. data/lib/kanrisuru/core/ip/parsers/address.rb +104 -0
  98. data/lib/kanrisuru/core/ip/parsers/address_label.rb +27 -0
  99. data/lib/kanrisuru/core/ip/parsers/base.rb +166 -0
  100. data/lib/kanrisuru/core/ip/parsers/link.rb +86 -0
  101. data/lib/kanrisuru/core/ip/parsers/maddress.rb +85 -0
  102. data/lib/kanrisuru/core/ip/parsers/neighbour.rb +89 -0
  103. data/lib/kanrisuru/core/ip/parsers/route.rb +76 -0
  104. data/lib/kanrisuru/core/ip/parsers/rule.rb +60 -0
  105. data/lib/kanrisuru/core/ip/parsers/version.rb +15 -0
  106. data/lib/kanrisuru/core/ip/types.rb +46 -0
  107. data/lib/kanrisuru/core/ip.rb +15 -1002
  108. data/lib/kanrisuru/core/mount/commands/mount.rb +65 -0
  109. data/lib/kanrisuru/core/mount/commands/umount.rb +35 -0
  110. data/lib/kanrisuru/core/mount/commands.rb +49 -0
  111. data/lib/kanrisuru/core/mount.rb +2 -125
  112. data/lib/kanrisuru/core/path/commands/ls.rb +26 -0
  113. data/lib/kanrisuru/core/path/commands/pwd.rb +16 -0
  114. data/lib/kanrisuru/core/path/commands/readlink.rb +22 -0
  115. data/lib/kanrisuru/core/path/commands/realpath.rb +18 -0
  116. data/lib/kanrisuru/core/path/commands/which.rb +19 -0
  117. data/lib/kanrisuru/core/path/commands/whoami.rb +16 -0
  118. data/lib/kanrisuru/core/path/commands.rb +8 -0
  119. data/lib/kanrisuru/core/path/parser.rb +4 -0
  120. data/lib/kanrisuru/core/path/parsers/ls.rb +53 -0
  121. data/lib/kanrisuru/core/path/parsers/which.rb +18 -0
  122. data/lib/kanrisuru/core/path/types.rb +12 -0
  123. data/lib/kanrisuru/core/path.rb +4 -121
  124. data/lib/kanrisuru/core/socket/commands/ss.rb +44 -0
  125. data/lib/kanrisuru/core/socket/commands.rb +3 -0
  126. data/lib/kanrisuru/core/socket/constants.rb +29 -0
  127. data/lib/kanrisuru/core/socket/parser.rb +3 -0
  128. data/lib/kanrisuru/core/socket/parsers/ss.rb +109 -0
  129. data/lib/kanrisuru/core/socket/types.rb +18 -0
  130. data/lib/kanrisuru/core/socket.rb +5 -164
  131. data/lib/kanrisuru/core/stat/commands/stat.rb +62 -0
  132. data/lib/kanrisuru/core/stat/commands.rb +3 -0
  133. data/lib/kanrisuru/core/stat/parser.rb +3 -0
  134. data/lib/kanrisuru/core/stat/parsers/stat.rb +34 -0
  135. data/lib/kanrisuru/core/stat/types.rb +14 -0
  136. data/lib/kanrisuru/core/stat.rb +4 -81
  137. data/lib/kanrisuru/core/stream/commands/cat.rb +25 -0
  138. data/lib/kanrisuru/core/stream/commands/echo.rb +20 -0
  139. data/lib/kanrisuru/core/stream/commands/head.rb +18 -0
  140. data/lib/kanrisuru/core/stream/commands/read_file_chunk.rb +21 -0
  141. data/lib/kanrisuru/core/stream/commands/sed.rb +23 -0
  142. data/lib/kanrisuru/core/stream/commands/tail.rb +18 -0
  143. data/lib/kanrisuru/core/stream/commands.rb +27 -0
  144. data/lib/kanrisuru/core/stream/parser.rb +4 -0
  145. data/lib/kanrisuru/core/stream/parsers/echo.rb +17 -0
  146. data/lib/kanrisuru/core/stream/parsers/sed.rb +17 -0
  147. data/lib/kanrisuru/core/stream.rb +3 -104
  148. data/lib/kanrisuru/core/system/commands/cpu_info.rb +32 -0
  149. data/lib/kanrisuru/core/system/commands/free.rb +25 -0
  150. data/lib/kanrisuru/core/system/commands/kernel_statistics.rb +21 -0
  151. data/lib/kanrisuru/core/system/commands/kill.rb +22 -0
  152. data/lib/kanrisuru/core/system/commands/last.rb +31 -0
  153. data/lib/kanrisuru/core/system/commands/load_average.rb +16 -0
  154. data/lib/kanrisuru/core/system/commands/load_env.rb +16 -0
  155. data/lib/kanrisuru/core/system/commands/lscpu.rb +17 -0
  156. data/lib/kanrisuru/core/system/commands/lsof.rb +16 -0
  157. data/lib/kanrisuru/core/system/commands/poweroff.rb +42 -0
  158. data/lib/kanrisuru/core/system/commands/ps.rb +35 -0
  159. data/lib/kanrisuru/core/system/commands/reboot.rb +42 -0
  160. data/lib/kanrisuru/core/system/commands/uptime.rb +18 -0
  161. data/lib/kanrisuru/core/system/commands/w.rb +24 -0
  162. data/lib/kanrisuru/core/system/commands.rb +34 -0
  163. data/lib/kanrisuru/core/system/parser.rb +11 -0
  164. data/lib/kanrisuru/core/system/parsers/kernel_statistics.rb +56 -0
  165. data/lib/kanrisuru/core/system/parsers/last.rb +64 -0
  166. data/lib/kanrisuru/core/system/parsers/load_average.rb +15 -0
  167. data/lib/kanrisuru/core/system/parsers/load_env.rb +24 -0
  168. data/lib/kanrisuru/core/system/parsers/lscpu.rb +90 -0
  169. data/lib/kanrisuru/core/system/parsers/lsof.rb +62 -0
  170. data/lib/kanrisuru/core/system/parsers/ps.rb +71 -0
  171. data/lib/kanrisuru/core/system/parsers/uptime.rb +38 -0
  172. data/lib/kanrisuru/core/system/parsers/w.rb +30 -0
  173. data/lib/kanrisuru/core/system/types.rb +108 -0
  174. data/lib/kanrisuru/core/system.rb +4 -687
  175. data/lib/kanrisuru/core/transfer/commands/download.rb +26 -0
  176. data/lib/kanrisuru/core/transfer/commands/upload.rb +23 -0
  177. data/lib/kanrisuru/core/transfer/commands/wget.rb +168 -0
  178. data/lib/kanrisuru/core/transfer/commands.rb +5 -0
  179. data/lib/kanrisuru/core/transfer/constants.rb +10 -0
  180. data/lib/kanrisuru/core/transfer.rb +3 -199
  181. data/lib/kanrisuru/core/user/commands/create_user.rb +49 -0
  182. data/lib/kanrisuru/core/user/commands/delete_user.rb +20 -0
  183. data/lib/kanrisuru/core/user/commands/get_uid.rb +15 -0
  184. data/lib/kanrisuru/core/user/commands/get_user.rb +48 -0
  185. data/lib/kanrisuru/core/user/commands/is_user.rb +14 -0
  186. data/lib/kanrisuru/core/user/commands/update_user.rb +54 -0
  187. data/lib/kanrisuru/core/user/commands.rb +8 -0
  188. data/lib/kanrisuru/core/user/parser.rb +4 -0
  189. data/lib/kanrisuru/core/user/parsers/getent.rb +17 -0
  190. data/lib/kanrisuru/core/user/parsers/groups.rb +17 -0
  191. data/lib/kanrisuru/core/user/types.rb +11 -0
  192. data/lib/kanrisuru/core/user.rb +4 -182
  193. data/lib/kanrisuru/core/yum/commands/autoremove.rb +14 -0
  194. data/lib/kanrisuru/core/yum/commands/clean.rb +23 -0
  195. data/lib/kanrisuru/core/yum/commands/erase.rb +20 -0
  196. data/lib/kanrisuru/core/yum/commands/info.rb +21 -0
  197. data/lib/kanrisuru/core/yum/commands/install.rb +18 -0
  198. data/lib/kanrisuru/core/yum/commands/list.rb +30 -0
  199. data/lib/kanrisuru/core/yum/commands/localinstall.rb +22 -0
  200. data/lib/kanrisuru/core/yum/commands/remove.rb +20 -0
  201. data/lib/kanrisuru/core/yum/commands/repolist.rb +20 -0
  202. data/lib/kanrisuru/core/yum/commands/search.rb +21 -0
  203. data/lib/kanrisuru/core/yum/commands/update.rb +14 -0
  204. data/lib/kanrisuru/core/yum/commands/upgrade.rb +14 -0
  205. data/lib/kanrisuru/core/yum/commands.rb +39 -0
  206. data/lib/kanrisuru/core/yum/parser.rb +7 -0
  207. data/lib/kanrisuru/core/yum/parsers/base.rb +31 -0
  208. data/lib/kanrisuru/core/yum/parsers/info.rb +69 -0
  209. data/lib/kanrisuru/core/yum/parsers/list.rb +24 -0
  210. data/lib/kanrisuru/core/yum/parsers/repolist.rb +60 -0
  211. data/lib/kanrisuru/core/yum/parsers/search.rb +30 -0
  212. data/lib/kanrisuru/core/yum/types.rb +41 -0
  213. data/lib/kanrisuru/core/yum.rb +4 -347
  214. data/lib/kanrisuru/core/zypper/commands/add_lock.rb +22 -0
  215. data/lib/kanrisuru/core/zypper/commands/add_repo.rb +38 -0
  216. data/lib/kanrisuru/core/zypper/commands/add_service.rb +26 -0
  217. data/lib/kanrisuru/core/zypper/commands/clean_cache.rb +22 -0
  218. data/lib/kanrisuru/core/zypper/commands/clean_locks.rb +17 -0
  219. data/lib/kanrisuru/core/zypper/commands/dist_upgrade.rb +25 -0
  220. data/lib/kanrisuru/core/zypper/commands/info.rb +25 -0
  221. data/lib/kanrisuru/core/zypper/commands/install.rb +39 -0
  222. data/lib/kanrisuru/core/zypper/commands/install_new_recommends.rb +23 -0
  223. data/lib/kanrisuru/core/zypper/commands/list_locks.rb +22 -0
  224. data/lib/kanrisuru/core/zypper/commands/list_patches.rb +34 -0
  225. data/lib/kanrisuru/core/zypper/commands/list_repos.rb +21 -0
  226. data/lib/kanrisuru/core/zypper/commands/list_services.rb +21 -0
  227. data/lib/kanrisuru/core/zypper/commands/list_updates.rb +30 -0
  228. data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +48 -0
  229. data/lib/kanrisuru/core/zypper/commands/modify_service.rb +40 -0
  230. data/lib/kanrisuru/core/zypper/commands/patch.rb +40 -0
  231. data/lib/kanrisuru/core/zypper/commands/patch_check.rb +29 -0
  232. data/lib/kanrisuru/core/zypper/commands/purge_kernels.rb +18 -0
  233. data/lib/kanrisuru/core/zypper/commands/refresh_repos.rb +24 -0
  234. data/lib/kanrisuru/core/zypper/commands/refresh_services.rb +21 -0
  235. data/lib/kanrisuru/core/zypper/commands/remove.rb +26 -0
  236. data/lib/kanrisuru/core/zypper/commands/remove_lock.rb +22 -0
  237. data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +32 -0
  238. data/lib/kanrisuru/core/zypper/commands/remove_service.rb +21 -0
  239. data/lib/kanrisuru/core/zypper/commands/rename_repo.rb +20 -0
  240. data/lib/kanrisuru/core/zypper/commands/search.rb +52 -0
  241. data/lib/kanrisuru/core/zypper/commands/source_install.rb +22 -0
  242. data/lib/kanrisuru/core/zypper/commands/update.rb +27 -0
  243. data/lib/kanrisuru/core/zypper/commands/verify.rb +23 -0
  244. data/lib/kanrisuru/core/zypper/commands.rb +109 -0
  245. data/lib/kanrisuru/core/zypper/constants.rb +19 -0
  246. data/lib/kanrisuru/core/zypper/parser.rb +11 -0
  247. data/lib/kanrisuru/core/zypper/parsers/base.rb +18 -0
  248. data/lib/kanrisuru/core/zypper/parsers/info.rb +77 -0
  249. data/lib/kanrisuru/core/zypper/parsers/list_locks.rb +36 -0
  250. data/lib/kanrisuru/core/zypper/parsers/list_patches.rb +40 -0
  251. data/lib/kanrisuru/core/zypper/parsers/list_repos.rb +37 -0
  252. data/lib/kanrisuru/core/zypper/parsers/list_services.rb +36 -0
  253. data/lib/kanrisuru/core/zypper/parsers/list_updates.rb +32 -0
  254. data/lib/kanrisuru/core/zypper/parsers/patch_check.rb +34 -0
  255. data/lib/kanrisuru/core/zypper/parsers/search.rb +37 -0
  256. data/lib/kanrisuru/core/zypper/types.rb +88 -0
  257. data/lib/kanrisuru/core/zypper.rb +5 -998
  258. data/lib/kanrisuru/os_package.rb +2 -0
  259. data/lib/kanrisuru/result.rb +15 -0
  260. data/lib/kanrisuru/version.rb +1 -1
  261. data/spec/functional/core/archive_spec.rb +1 -1
  262. data/spec/functional/core/disk_spec.rb +77 -0
  263. data/spec/functional/core/dmi_spec.rb +78 -0
  264. data/spec/functional/core/file_spec.rb +284 -0
  265. data/spec/functional/core/group_spec.rb +62 -0
  266. data/spec/functional/core/ip/ip_address_label_spec.rb +81 -0
  267. data/spec/functional/core/ip/ip_address_spec.rb +95 -0
  268. data/spec/functional/core/ip/ip_link_spec.rb +814 -0
  269. data/spec/functional/core/ip/ip_maddress_spec.rb +78 -0
  270. data/spec/functional/core/ip/ip_neighbour_spec.rb +119 -0
  271. data/spec/functional/core/ip/ip_route_spec.rb +174 -0
  272. data/spec/functional/core/ip/ip_rule_spec.rb +75 -0
  273. data/spec/functional/core/ip/ip_spec.rb +27 -0
  274. data/spec/functional/core/system_spec.rb +135 -0
  275. data/spec/functional/core/user_spec.rb +97 -0
  276. data/spec/functional/result_spec.rb +91 -44
  277. data/spec/helper/stub_network.rb +6 -2
  278. data/spec/support/shared_examples/integration/core/transfer.rb +1 -1
  279. data/spec/unit/command_spec.rb +2 -0
  280. data/spec/unit/core/ip_spec.rb +12 -0
  281. data/spec/unit/util_spec.rb +16 -0
  282. metadata +253 -4
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'commands/download'
4
+ require_relative 'commands/upload'
5
+ require_relative 'commands/wget'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module Transfer
6
+ WGET_FILENAME_MODES = %w[unix windows nocontrol ascii lowercase uppercase].freeze
7
+ WGET_SSL_PROTO = %w[auto SSLv2 SSLv3 TLSv1].freeze
8
+ end
9
+ end
10
+ 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,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module User
6
+ def create_user(user, opts = {})
7
+ group = opts[:group]
8
+ groups = opts[:groups]
9
+ shell = opts[:shell] || '/bin/false'
10
+
11
+ command = Kanrisuru::Command.new("useradd #{user}")
12
+
13
+ if Kanrisuru::Util.present?(opts[:uid])
14
+ command.append_arg('-u', opts[:uid])
15
+ command.append_flag('-o', opts[:non_unique])
16
+ end
17
+
18
+ command.append_flag('-r', opts[:system])
19
+ command.append_arg('-s', shell)
20
+ command.append_arg('-d', opts[:home])
21
+
22
+ case opts[:createhome]
23
+ when true
24
+ command.append_flag('-m')
25
+ command.append_arg('-k', opts[:skeleton])
26
+ when false
27
+ command.append_flag('-M')
28
+ end
29
+
30
+ if Kanrisuru::Util.present?(group) && group?(group)
31
+ command.append_arg('-g', group)
32
+ elsif group?(user)
33
+ command.append_flag('-N')
34
+ end
35
+
36
+ command.append_arg('-G', groups.join(',')) if Kanrisuru::Util.present?(groups)
37
+
38
+ command.append_arg('-p', opts[:password])
39
+ command.append_arg('-e', opts[:expires]) ## YYYY-MM-DD
40
+
41
+ execute_shell(command)
42
+
43
+ Kanrisuru::Result.new(command) do
44
+ get_user(user).data
45
+ end
46
+ end
47
+ end
48
+ end
49
+ 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 if get_uid(user).failure?
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,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module User
6
+ def get_uid(user)
7
+ command = Kanrisuru::Command.new("id -u #{user}")
8
+
9
+ execute(command)
10
+
11
+ Kanrisuru::Result.new(command, &:to_i)
12
+ end
13
+ end
14
+ end
15
+ 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,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kanrisuru
4
+ module Core
5
+ module User
6
+ def update_user(user, opts = {})
7
+ group = opts[:group]
8
+ groups = opts[:groups]
9
+
10
+ command = Kanrisuru::Command.new("usermod #{user}")
11
+
12
+ if Kanrisuru::Util.present?(opts[:home])
13
+ command.append_arg('-d', opts[:home])
14
+ command.append_flag('-m', opts[:move_home])
15
+ end
16
+
17
+ command.append_arg('-s', opts[:shell])
18
+
19
+ if Kanrisuru::Util.present?(opts[:uid])
20
+ command.append_arg('-u', opts[:uid])
21
+ command.append_flag('-o', opts[:non_unique])
22
+ end
23
+
24
+ command.append_arg('-g', group) if Kanrisuru::Util.present?(group) && group?(group)
25
+
26
+ if Kanrisuru::Util.present?(groups)
27
+ command.append_arg('-G', Kanrisuru::Util.array_join_string(groups, ','))
28
+ command.append_flag('-a', opts[:append])
29
+ end
30
+
31
+ case opts[:locked]
32
+ when true
33
+ command.append_flag('-L')
34
+ command.append_arg('-e', 1)
35
+ when false
36
+ command.append_flag('-U')
37
+ command.append_arg('-e', 99_999)
38
+ else
39
+ ## Ensure expires isn't added twice.
40
+ command.append_arg('-e', opts[:expires]) ## YYYY-MM-DD
41
+
42
+ ## Can't use password with lock / unlock flag.
43
+ command.append_arg('-p', opts[:password])
44
+ end
45
+
46
+ execute_shell(command)
47
+
48
+ Kanrisuru::Result.new(command) do |_command|
49
+ get_user(user).data
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'commands/is_user'
4
+ require_relative 'commands/get_uid'
5
+ require_relative 'commands/get_user'
6
+ require_relative 'commands/create_user'
7
+ require_relative 'commands/update_user'
8
+ require_relative 'commands/delete_user'
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'parsers/getent'
4
+ require_relative 'parsers/groups'