cmt 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/cmt +1 -1
- data/lib/cmt.rb +22 -17
- data/lib/config/config.rb +11 -13
- data/lib/config/git_config.rb +50 -50
- data/lib/dotfiles/dotfiles.rb +84 -89
- data/lib/dotfiles/dotfiles_cli.rb +22 -22
- data/lib/pkg/pkg.rb +78 -79
- data/lib/pkg/pkg_config.rb +30 -34
- data/lib/pkg/pkgm/dnf.rb +17 -0
- data/lib/pkg/pkgm/pacman.rb +13 -14
- data/lib/pkg/pkgm/pip.rb +14 -15
- data/lib/pkg/pkgm/snap.rb +14 -15
- data/lib/pkg/pkgm/winget.rb +14 -16
- data/lib/pkg/pkgm/yay.rb +13 -14
- data/lib/util/file_util.rb +19 -19
- data/lib/version.rb +3 -0
- metadata +20 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8a9562284819480fc462bedeca790f97c9583f8a100560b4cfcb64cfb5f7fbf
|
4
|
+
data.tar.gz: fca40eb657310a8f824da003cb2126ee9798fbaf628d8fe11d2f28adc8b59043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8329b3f7b97400c08fc4f18effba5d7caa9ae5f38492b731712c2d8a9564bca66a6e6773e6d8827e1c2caa0a9b01992b712b660d221af0df1a6c59c3b9d5f2
|
7
|
+
data.tar.gz: 6bd12d08de30bf9f0577bbef609627068a92350969a456ad56923436c7bcc29cf15831699a63805af70fcbeee80a7325af8a2de3b80108668e870ecefa499ed6
|
data/bin/cmt
CHANGED
data/lib/cmt.rb
CHANGED
@@ -1,29 +1,34 @@
|
|
1
1
|
require "thor"
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require "pathname"
|
3
|
+
require "fileutils"
|
4
|
+
require "json"
|
5
5
|
require "logger"
|
6
6
|
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
7
|
+
require_relative "config/git_config"
|
8
|
+
require_relative "dotfiles/dotfiles_cli"
|
9
|
+
require_relative "pkg/pkg"
|
10
|
+
require_relative "version"
|
10
11
|
|
11
|
-
$logger = Logger.new(
|
12
|
-
$logger.formatter = proc do |severity, datetime,
|
13
|
-
|
14
|
-
|
12
|
+
$logger = Logger.new($stdout)
|
13
|
+
$logger.formatter = proc do |severity, datetime, _progname, msg|
|
14
|
+
date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
|
15
|
+
JSON.dump(date: date_format, severity: severity.ljust(5), pid: "##{Process.pid}", message: msg) + "\n" # rubocop:disable Style/StringConcatenation
|
15
16
|
end
|
16
17
|
|
17
18
|
class Cmt < Thor
|
18
|
-
|
19
|
-
|
19
|
+
desc "config SUBCOMMAND ...ARGS", "manage set of tracked repositories"
|
20
|
+
subcommand "config", GitConfig
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
desc "dotfiles SUBCOMMAND ...ARGS", "manage set of tracked repositories"
|
23
|
+
subcommand "dotfiles", DotfilesCli
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
desc "pkg SUBCOMMAND ...ARGS", "manage set of tracked repositories"
|
26
|
+
subcommand "pkg", Pkg
|
27
|
+
|
28
|
+
desc "version", "Print version"
|
29
|
+
def version
|
30
|
+
puts(VERSION)
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
Cmt.start(ARGV)
|
29
|
-
|
data/lib/config/config.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
require "thor"
|
2
|
-
require
|
2
|
+
require "fileutils"
|
3
3
|
|
4
|
-
$CONFIG_DIR = File.join(Dir.home,
|
4
|
+
$CONFIG_DIR = File.join(Dir.home, ".config", "cmt")
|
5
5
|
|
6
6
|
class Config
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
File.open(file, 'w') {|f| JSON.dump(default_config, f)}
|
11
|
-
end
|
7
|
+
def self.get_config_json(file, default_config)
|
8
|
+
FileUtils.mkdir_p File.dirname(file)
|
9
|
+
File.write(file, JSON.pretty_generate(default_config, { indent: " " })) unless File.exist?(file)
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
config = JSON.load_file(file)
|
12
|
+
default_config.merge(config)
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def self.write_config_file(file, config)
|
16
|
+
File.write(file, JSON.pretty_generate(config, { indent: " " }))
|
17
|
+
end
|
20
18
|
end
|
data/lib/config/git_config.rb
CHANGED
@@ -1,63 +1,63 @@
|
|
1
1
|
require "thor"
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "config"
|
4
4
|
|
5
5
|
class GitConfig < Thor
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
`git clone #{repo} #{$CONFIG_DIR}`
|
6
|
+
desc "init", "Init"
|
7
|
+
option :force, type: :boolean, default: false
|
8
|
+
def init(repo)
|
9
|
+
force = options["force"]
|
10
|
+
|
11
|
+
if File.exist? $CONFIG_DIR
|
12
|
+
if force
|
13
|
+
FileUtils.rm_rf($CONFIG_DIR)
|
14
|
+
else
|
15
|
+
$logger.error("Config already exists at '#{$CONFIG_DIR}'")
|
16
|
+
abort("Config already exists at '#{$CONFIG_DIR}'")
|
17
|
+
end
|
21
18
|
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
20
|
+
`git clone #{repo} #{$CONFIG_DIR}`
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "update", "update"
|
24
|
+
option :message, default: "Update config"
|
25
|
+
def update
|
26
|
+
message = options['message']
|
27
|
+
Dir.chdir($CONFIG_DIR) do
|
28
|
+
changes = `git status --porcelain=v1`
|
29
|
+
num_changes = changes.split.length
|
30
|
+
|
31
|
+
if num_changes.zero?
|
32
|
+
$logger.error("No changes to commit in '#{$CONFIG_DIR}'")
|
33
|
+
abort("No changes to commit in '#{$CONFIG_DIR}'")
|
34
|
+
else
|
35
|
+
$logger.info("Commit changes")
|
36
|
+
system 'git', 'add', '.'
|
37
|
+
system 'git', 'commit', '-m', "'#{message}'"
|
38
|
+
system 'git', 'push'
|
39
|
+
end
|
41
40
|
end
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
43
|
+
desc "status", "Show git status in '#{$CONFIG_DIR}'"
|
44
|
+
def status(*args)
|
45
|
+
Dir.chdir($CONFIG_DIR) do
|
46
|
+
system 'git', 'status', *args
|
48
47
|
end
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
50
|
+
desc "pull", "Pull newest changes in '#{$CONFIG_DIR}'"
|
51
|
+
def pull(*args)
|
52
|
+
Dir.chdir($CONFIG_DIR) do
|
53
|
+
system 'git', 'pull', *args
|
55
54
|
end
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
57
|
+
desc "exec", "Execute any git command in '#{$CONFIG_DIR}'"
|
58
|
+
def exec(*args)
|
59
|
+
Dir.chdir($CONFIG_DIR) do
|
60
|
+
system 'git', *args
|
62
61
|
end
|
63
|
-
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/dotfiles/dotfiles.rb
CHANGED
@@ -8,135 +8,130 @@ require_relative '../config/config'
|
|
8
8
|
require_relative '../util/file_util'
|
9
9
|
|
10
10
|
class Dotfiles
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
CONFIG_SUB_DIR = 'dotfiles'.freeze
|
12
|
+
ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
|
13
|
+
CONFIG_FILE = File.join(ROOT_PATH, 'dotfiles.json').freeze
|
14
|
+
FILES_PATH = File.join(ROOT_PATH, 'files').freeze
|
15
|
+
FOLDERS_PATH = File.join(ROOT_PATH, 'folders').freeze
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
DEFAULT_CONFIG = {
|
18
|
+
"files" => [],
|
19
|
+
"folders" => []
|
20
|
+
}.freeze
|
21
21
|
|
22
|
-
|
22
|
+
def add(file)
|
23
|
+
abs_file = File.absolute_path(file.dup)
|
23
24
|
|
24
|
-
|
25
|
+
config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
|
26
|
+
list = get_sync_list(config, abs_file)
|
25
27
|
|
26
|
-
|
27
|
-
list = get_sync_list(config, abs_file)
|
28
|
-
|
29
|
-
parsed_file = FileUtil.to_local_file(abs_file)
|
28
|
+
parsed_file = FileUtil.to_local_file(abs_file)
|
30
29
|
|
31
|
-
|
30
|
+
local_path = get_local_path(file)
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
unless list.include? parsed_file
|
33
|
+
dir = File.dirname(parsed_file)
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
FileUtils.mkdir_p File.join(local_path, dir)
|
35
|
+
puts File.join(local_path, dir)
|
39
36
|
|
40
|
-
|
41
|
-
FileUtils.cp(abs_file, File.join(local_path, parsed_file))
|
42
|
-
else
|
43
|
-
FileUtils.cp_r(abs_file, File.join(local_path, parsed_file))
|
44
|
-
end
|
45
|
-
|
46
|
-
if File.exists? File.join(local_path, parsed_file)
|
47
|
-
list.append(parsed_file)
|
48
|
-
end
|
49
|
-
end
|
37
|
+
FileUtils.mkdir_p File.join(local_path, dir)
|
50
38
|
|
51
|
-
|
39
|
+
if File.file?(abs_file)
|
40
|
+
FileUtils.cp(abs_file, File.join(local_path, parsed_file))
|
41
|
+
else
|
42
|
+
FileUtils.cp_r(abs_file, File.join(local_path, parsed_file))
|
43
|
+
end
|
52
44
|
|
53
|
-
|
45
|
+
list.append(parsed_file) if File.exist? File.join(local_path, parsed_file)
|
54
46
|
end
|
55
47
|
|
56
|
-
|
57
|
-
local_file = FileUtil.to_local_file(file)
|
58
|
-
local_file_abs = File.join(get_local_path(file), local_file)
|
48
|
+
Config.write_config_file(CONFIG_FILE, config)
|
59
49
|
|
60
|
-
|
61
|
-
|
50
|
+
$logger.info("Added '#{parsed_file}'")
|
51
|
+
end
|
62
52
|
|
53
|
+
def remove(file)
|
54
|
+
local_file = FileUtil.to_local_file(file)
|
55
|
+
local_file_abs = File.join(get_local_path(file), local_file)
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
FileUtils.rm_rf(local_file_abs)
|
67
|
-
|
68
|
-
list.delete(local_file)
|
69
|
-
end
|
70
|
-
|
71
|
-
Config.write_config_file(CONFIG_FILE, config)
|
57
|
+
config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
|
58
|
+
list = get_sync_list(config, local_file_abs)
|
72
59
|
|
60
|
+
if list.include? local_file
|
61
|
+
puts(local_file_abs)
|
62
|
+
FileUtils.rm_rf(local_file_abs)
|
73
63
|
|
74
|
-
|
64
|
+
list.delete(local_file)
|
75
65
|
end
|
76
66
|
|
77
|
-
|
78
|
-
$logger.info('Start apply')
|
67
|
+
Config.write_config_file(CONFIG_FILE, config)
|
79
68
|
|
80
|
-
|
81
|
-
|
69
|
+
$logger.info("Removed '#{local_file}'")
|
70
|
+
end
|
82
71
|
|
83
|
-
|
84
|
-
|
72
|
+
def apply
|
73
|
+
$logger.info('Start apply')
|
85
74
|
|
86
|
-
|
87
|
-
|
75
|
+
config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
|
76
|
+
files = config['files']
|
88
77
|
|
89
|
-
|
90
|
-
|
78
|
+
files.each do |file|
|
79
|
+
dest_file = FileUtil.to_system_file(file)
|
91
80
|
|
92
|
-
|
81
|
+
abs_file = File.join(FILES_PATH, file)
|
82
|
+
$logger.debug("Copy #{abs_file} to #{dest_file}")
|
93
83
|
|
94
|
-
|
95
|
-
|
84
|
+
FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
|
85
|
+
end
|
86
|
+
|
87
|
+
folders = config['folders']
|
96
88
|
|
97
|
-
|
98
|
-
|
89
|
+
folders.each do |folder|
|
90
|
+
dest_file = File.dirname(FileUtil.to_system_file(folder))
|
99
91
|
|
100
|
-
|
101
|
-
|
92
|
+
abs_file = File.join(FOLDERS_PATH, folder)
|
93
|
+
$logger.debug("Copy #{abs_file} to #{dest_file}")
|
102
94
|
|
103
|
-
|
95
|
+
FileUtils.cp_r(abs_file, dest_file, remove_destination: true)
|
104
96
|
end
|
105
97
|
|
106
|
-
|
107
|
-
|
98
|
+
$logger.info('Finished apply')
|
99
|
+
end
|
108
100
|
|
109
|
-
|
110
|
-
|
101
|
+
def sync
|
102
|
+
$logger.info('Start sync')
|
111
103
|
|
112
|
-
|
113
|
-
|
104
|
+
config = Config.get_config_json(CONFIG_FILE, DEFAULT_CONFIG)
|
105
|
+
files = config['files']
|
114
106
|
|
115
|
-
|
116
|
-
|
107
|
+
files.each do |file|
|
108
|
+
dest_file = FileUtil.to_system_file(file)
|
117
109
|
|
118
|
-
|
119
|
-
|
110
|
+
abs_file = File.join(FILES_PATH, file)
|
111
|
+
$logger.debug("Copy #{dest_file} to #{abs_file}")
|
120
112
|
|
121
|
-
|
113
|
+
FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
|
114
|
+
end
|
122
115
|
|
123
|
-
|
124
|
-
dest_file = FileUtil.to_system_file(folder)
|
116
|
+
folders = config['folders']
|
125
117
|
|
126
|
-
|
127
|
-
|
118
|
+
folders.each do |folder|
|
119
|
+
dest_file = FileUtil.to_system_file(folder)
|
128
120
|
|
129
|
-
|
130
|
-
|
121
|
+
abs_file = File.dirname(File.join(FOLDERS_PATH, folder))
|
122
|
+
$logger.debug("Copy #{dest_file} to #{abs_file}")
|
131
123
|
|
132
|
-
|
124
|
+
FileUtils.cp_r(dest_file, abs_file, remove_destination: true)
|
133
125
|
end
|
134
126
|
|
135
|
-
|
136
|
-
|
137
|
-
end
|
127
|
+
$logger.info('Finished sync')
|
128
|
+
end
|
138
129
|
|
139
|
-
|
140
|
-
|
141
|
-
|
130
|
+
def get_local_path(file)
|
131
|
+
return File.file?(file) ? FILES_PATH : FOLDERS_PATH
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_sync_list(config, file)
|
135
|
+
return File.file?(file) ? config['files'] : config['folders']
|
136
|
+
end
|
142
137
|
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "dotfiles"
|
2
2
|
|
3
3
|
class DotfilesCli < Thor
|
4
|
-
|
4
|
+
DOTFILES = Dotfiles.new
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
desc "init", "Download objects and refs from another repository"
|
7
|
+
def init
|
8
|
+
DOTFILES.init
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
desc "add <file>", "Download objects and refs from another repository"
|
12
|
+
def add(file)
|
13
|
+
DOTFILES.add(file)
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
desc "remove <file>", "Download objects and refs from another repository"
|
17
|
+
def remove(file)
|
18
|
+
DOTFILES.remove(file)
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
desc "apply", "Copies all dotfiles defined in the user config to the system"
|
22
|
+
def apply
|
23
|
+
DOTFILES.apply
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
desc "sync", "Updates all files defined in the user config from the system to the config dir"
|
27
|
+
def sync
|
28
|
+
DOTFILES.sync
|
29
|
+
end
|
30
30
|
end
|
data/lib/pkg/pkg.rb
CHANGED
@@ -1,105 +1,104 @@
|
|
1
|
-
require
|
1
|
+
require "thor"
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
3
|
+
require_relative "pkgm/dnf"
|
4
|
+
require_relative "pkgm/pacman"
|
5
|
+
require_relative "pkgm/yay"
|
6
|
+
require_relative "pkgm/pip"
|
7
|
+
require_relative "pkgm/snap"
|
8
|
+
require_relative "pkgm/winget"
|
9
|
+
require_relative "pkg_config"
|
9
10
|
|
10
11
|
class Pkg < Thor
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
SYSTEM_PACKAGE_MANGER = {
|
13
|
+
"manjaro" => Pacman,
|
14
|
+
"fedora" => Dnf,
|
15
|
+
"windows" => Winget
|
16
|
+
}.freeze
|
17
|
+
OTHER_PACKAGE_MANGER = {
|
18
|
+
"pip" => Pip,
|
19
|
+
"snap" => Snap,
|
20
|
+
"yay" => Yay
|
21
|
+
}.freeze
|
22
|
+
RELEASE_FILE = "/etc/os-release".freeze
|
21
23
|
|
24
|
+
desc "install_all", "Install"
|
25
|
+
option "pkgm", default: "system"
|
26
|
+
def install_all(*args)
|
27
|
+
manager = get_package_manager(options["pkgm"])
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
def install_all(*args)
|
26
|
-
manager = get_package_manager(options['pkgm'])
|
29
|
+
config_file = PkgConfig.get_config_file(manager)
|
30
|
+
config = Config.get_config_json(config_file, PkgConfig.default_config)
|
27
31
|
|
28
|
-
|
29
|
-
config = Config.get_config_json(config_file, PkgConfig.get_default_config())
|
32
|
+
packages = config["packages"]
|
30
33
|
|
31
|
-
|
34
|
+
manager.install_all(packages, *args)
|
35
|
+
end
|
32
36
|
|
33
|
-
|
34
|
-
|
37
|
+
desc "install", "Install"
|
38
|
+
option "pkgm", default: "system"
|
39
|
+
def install(package, *args)
|
40
|
+
manager = get_package_manager(options["pkgm"])
|
35
41
|
|
36
|
-
|
37
|
-
option 'pkgm', default: 'system'
|
38
|
-
def install(package, *args)
|
39
|
-
manager = get_package_manager(options['pkgm'])
|
42
|
+
installed = manager.install(package, *args)
|
40
43
|
|
41
|
-
|
44
|
+
return unless installed
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
46
|
+
PkgConfig.add(manager, package)
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
desc "update", "update"
|
50
|
+
option "pkgm", default: "system"
|
51
|
+
def update(*args)
|
52
|
+
manager = get_package_manager(options["pkgm"])
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
manager.update(*args)
|
55
|
+
end
|
55
56
|
|
57
|
+
desc "uninstall", "uninstall"
|
58
|
+
option "pkgm", default: "system"
|
59
|
+
def uninstall(package, *args)
|
60
|
+
manager = get_package_manager(options["pkgm"])
|
56
61
|
|
57
|
-
|
58
|
-
option 'pkgm', default: 'system'
|
59
|
-
def uninstall(package, *args)
|
60
|
-
manager = get_package_manager(options['pkgm'])
|
62
|
+
uninstalled = manager.uninstall(package, *args)
|
61
63
|
|
62
|
-
|
64
|
+
return unless uninstalled
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
end
|
66
|
+
PkgConfig.remove(manager, package)
|
67
|
+
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
69
|
+
no_commands do
|
70
|
+
def get_package_manager(pkgm)
|
71
|
+
manager = nil
|
72
72
|
|
73
|
-
|
73
|
+
if pkgm == "system"
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
75
|
+
if Gem.win_platform?
|
76
|
+
manager = SYSTEM_PACKAGE_MANGER["windows"]
|
77
|
+
else
|
78
|
+
r = { "distro" => nil }
|
79
|
+
unless File.exist?(RELEASE_FILE)
|
80
|
+
$logger.error("'#{RELEASE_FILE}' does not exist")
|
81
|
+
abort("'#{RELEASE_FILE}' does not exist")
|
82
|
+
end
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
File.foreach(RELEASE_FILE) do |line|
|
85
|
+
r = { "distro" => ::Regexp.last_match(1) } if line =~ /^ID=(.*)/
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
88
|
+
manager = SYSTEM_PACKAGE_MANGER[r["distro"]]
|
89
|
+
end
|
90
|
+
else
|
91
|
+
manager = OTHER_PACKAGE_MANGER[pkgm]
|
92
|
+
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
if manager.nil?
|
95
|
+
$logger.error("'#{pkgm}' is not supported")
|
96
|
+
abort("'#{pkgm}' is not supported")
|
97
|
+
end
|
98
98
|
|
99
|
-
|
99
|
+
$logger.info("Using package manager '#{manager}'")
|
100
100
|
|
101
|
-
|
102
|
-
end
|
101
|
+
manager
|
103
102
|
end
|
104
|
-
|
105
|
-
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/pkg/pkg_config.rb
CHANGED
@@ -1,49 +1,45 @@
|
|
1
|
-
require
|
1
|
+
require "json"
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../config/config"
|
4
4
|
|
5
5
|
class PkgConfig
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
CONFIG_SUB_DIR = "pkg".freeze
|
7
|
+
ROOT_PATH = File.join($CONFIG_DIR, CONFIG_SUB_DIR).freeze
|
8
|
+
DEFAULT_CONFIG = {
|
9
|
+
"repos" => [],
|
10
|
+
"packages" => []
|
11
|
+
}.freeze
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
def self.add(pkgm, package)
|
14
|
+
config_file = PkgConfig.get_config_file(pkgm)
|
15
15
|
|
16
|
-
|
16
|
+
config = Config.get_config_json(config_file, DEFAULT_CONFIG)
|
17
17
|
|
18
|
-
|
18
|
+
packages = config["packages"]
|
19
19
|
|
20
|
-
|
21
|
-
packages.append package
|
22
|
-
end
|
20
|
+
packages.append package unless packages.include? package
|
23
21
|
|
24
|
-
|
25
|
-
|
22
|
+
Config.write_config_file(config_file, config)
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
25
|
+
def self.remove(pkgm, package)
|
26
|
+
config_file = PkgConfig.get_config_file(pkgm)
|
29
27
|
|
30
|
-
|
28
|
+
config = Config.get_config_json(config_file, DEFAULT_CONFIG)
|
31
29
|
|
32
|
-
|
30
|
+
packages = config["packages"]
|
33
31
|
|
34
|
-
|
35
|
-
packages.delete package
|
36
|
-
end
|
32
|
+
packages.delete package if packages.include? package
|
37
33
|
|
38
|
-
|
39
|
-
|
34
|
+
Config.write_config_file(config_file, config)
|
35
|
+
end
|
40
36
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
def self.get_config_file(pkgm)
|
38
|
+
pkgm = pkgm.downcase
|
39
|
+
File.join(ROOT_PATH, "#{pkgm}.json")
|
40
|
+
end
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
42
|
+
def self.default_config
|
43
|
+
DEFAULT_CONFIG
|
44
|
+
end
|
45
|
+
end
|
data/lib/pkg/pkgm/dnf.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Dnf
|
2
|
+
def self.install_all(packages, *args)
|
3
|
+
system "sudo", "dnf", "install", *args, *packages
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.install(package, *args)
|
7
|
+
system "sudo", "dnf", "install", *args, package
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.update(*args)
|
11
|
+
system "sudo", "dnf", "update", *args
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.uninstall(package, *args)
|
15
|
+
system "sudo", "dnf", "remove", *args, package
|
16
|
+
end
|
17
|
+
end
|
data/lib/pkg/pkgm/pacman.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
|
2
1
|
class Pacman
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def self.install_all(packages, *args)
|
3
|
+
system "sudo", "pacman", "-Sy", *args, *packages
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.install(package, *args)
|
7
|
+
system "sudo", "pacman", "-Sy", *args, package
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def self.update(*args)
|
11
|
+
system "sudo", "pacman", "-Syu", *args
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
def self.uninstall(package, *args)
|
15
|
+
system "sudo", "pacman", "-R", *args, package
|
16
|
+
end
|
17
|
+
end
|
data/lib/pkg/pkgm/pip.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
|
2
1
|
class Pip
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def self.install_all(packages, *args)
|
3
|
+
system "python3", "-m", "pip", "install", *args, *packages
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.install(package, *args)
|
7
|
+
system "python3", "-m", "pip", "install", *args, package
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def self.update(*_args)
|
11
|
+
$logger.error("Update is not supported for pip")
|
12
|
+
abort("Update is not supported for pip")
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
def self.uninstall(package, *args)
|
16
|
+
system "python3", "-m", "pip", "uninstall", *args, package
|
17
|
+
end
|
18
|
+
end
|
data/lib/pkg/pkgm/snap.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
|
2
1
|
class Snap
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def self.install_all(packages, *args)
|
3
|
+
system "snap", "install", *args, *packages
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.install(package, *args)
|
7
|
+
system "snap", "install", *args, package
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def self.update(*_args)
|
11
|
+
$logger.error("Update is not supported for snap")
|
12
|
+
abort("Update is not supported for snap")
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
def self.uninstall(package, *args)
|
16
|
+
system "snap", "remove", *args, package
|
17
|
+
end
|
18
|
+
end
|
data/lib/pkg/pkgm/winget.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
|
-
|
2
1
|
class Winget
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
}
|
2
|
+
def self.install_all(packages, *args)
|
3
|
+
packages.each do |package|
|
4
|
+
Winget.install(package, *args)
|
7
5
|
end
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
def self.install(package, *args)
|
9
|
+
system "winget", "install", *args, "--id=#{package}", "-e"
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def self.update(*_args)
|
13
|
+
system "winget", "upgrade"
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
16
|
+
def self.uninstall(package, *args)
|
17
|
+
system "winget", "uninstall", *args, "--id=#{package}", "-e"
|
18
|
+
end
|
19
|
+
end
|
data/lib/pkg/pkgm/yay.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
|
2
1
|
class Yay
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
def self.install_all(packages, *args)
|
3
|
+
system "yay", "-Sy", *args, *packages
|
4
|
+
end
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.install(package, *args)
|
7
|
+
system "yay", "-Sy", *args, package
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def self.update(*args)
|
11
|
+
system "yay", "-Syu", *args
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
14
|
+
def self.uninstall(package, *args)
|
15
|
+
system "yay", "-R", *args, package
|
16
|
+
end
|
17
|
+
end
|
data/lib/util/file_util.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
class FileUtil
|
2
|
-
|
2
|
+
USER_HOME = "user-home".freeze
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
def self.to_local_file(file)
|
5
|
+
local_file = File.absolute_path(file.dup)
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
return local_file
|
7
|
+
if local_file.include? Dir.home
|
8
|
+
local_file[Dir.home] = USER_HOME
|
9
|
+
elsif local_file.start_with?("/")
|
10
|
+
local_file = local_file[1..]
|
14
11
|
end
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
local_file
|
14
|
+
end
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
else
|
22
|
-
system_file = "/#{system_file}"
|
23
|
-
end
|
16
|
+
def self.to_system_file(file)
|
17
|
+
system_file = file.dup
|
24
18
|
|
25
|
-
|
19
|
+
if system_file.start_with? USER_HOME
|
20
|
+
system_file[USER_HOME] = Dir.home
|
21
|
+
else
|
22
|
+
system_file = "/#{system_file}"
|
26
23
|
end
|
27
|
-
|
24
|
+
|
25
|
+
system_file
|
26
|
+
end
|
27
|
+
end
|
data/lib/version.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cmt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- simon.schuster
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -25,7 +25,8 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.2'
|
27
27
|
description: "[C]onfiguration [M]anagment [T]ool"
|
28
|
-
email:
|
28
|
+
email:
|
29
|
+
- simon.schuster@dynatrace.com
|
29
30
|
executables:
|
30
31
|
- cmt
|
31
32
|
extensions: []
|
@@ -39,17 +40,24 @@ files:
|
|
39
40
|
- lib/dotfiles/dotfiles_cli.rb
|
40
41
|
- lib/pkg/pkg.rb
|
41
42
|
- lib/pkg/pkg_config.rb
|
43
|
+
- lib/pkg/pkgm/dnf.rb
|
42
44
|
- lib/pkg/pkgm/pacman.rb
|
43
45
|
- lib/pkg/pkgm/pip.rb
|
44
46
|
- lib/pkg/pkgm/snap.rb
|
45
47
|
- lib/pkg/pkgm/winget.rb
|
46
48
|
- lib/pkg/pkgm/yay.rb
|
47
49
|
- lib/util/file_util.rb
|
48
|
-
|
50
|
+
- lib/version.rb
|
51
|
+
homepage: https://github.com/Setre14/cmt
|
49
52
|
licenses:
|
50
|
-
-
|
51
|
-
metadata:
|
52
|
-
|
53
|
+
- MIT
|
54
|
+
metadata:
|
55
|
+
allowed_push_host: https://rubygems.org/
|
56
|
+
homepage_uri: https://github.com/Setre14/cmt
|
57
|
+
source_code_uri: https://github.com/Setre14/cmt
|
58
|
+
changelog_uri: https://github.com/Setre14/cmt/blob/main/CHANGELOG.md
|
59
|
+
rubygems_mfa_required: 'true'
|
60
|
+
post_install_message:
|
53
61
|
rdoc_options: []
|
54
62
|
require_paths:
|
55
63
|
- lib
|
@@ -57,15 +65,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
65
|
requirements:
|
58
66
|
- - ">="
|
59
67
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
68
|
+
version: 2.7.0
|
61
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
70
|
requirements:
|
63
71
|
- - ">="
|
64
72
|
- !ruby/object:Gem::Version
|
65
73
|
version: '0'
|
66
74
|
requirements: []
|
67
|
-
rubygems_version: 3.3.
|
68
|
-
signing_key:
|
75
|
+
rubygems_version: 3.3.5
|
76
|
+
signing_key:
|
69
77
|
specification_version: 4
|
70
78
|
summary: configuration managment tool
|
71
79
|
test_files: []
|