homeconf 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/homeconf +5 -0
- data/lib/homeconf/default_homeconfignore +4 -1
- data/lib/homeconf/homeconf.rb +33 -15
- data/lib/homeconf/init.rb +53 -0
- data/lib/homeconf/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dc32e254261a3730608b691c935a0c2f4ba83306d95f4f2b9c43d090f1cdaaa
|
4
|
+
data.tar.gz: 18d439a7298746b242e335e63115931e5e419e5080d411cba8b53e7c19a137e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9907b0452e9968395fa54085e50268ce082847d86c017eb53e93a29cfde70a6c2ec8c603762dae410fa933fbc1c730bb31522afdc906a6a03126d09f93e0cc3
|
7
|
+
data.tar.gz: 3915b9d43cb98a63f4b7196016e92fc3ae7161956c36652243d46b5d3537121440e7ddbdb18c4fa0f5a6d7e872157f72fee2fadb9f59ab31f35bfab2aaf451e8
|
data/bin/homeconf
CHANGED
@@ -44,6 +44,11 @@ def print_config(homeconf)
|
|
44
44
|
print_linked_table(homeconf, homeconf.list_homeconf_dirs)
|
45
45
|
puts 'homeconf files:'
|
46
46
|
print_linked_table(homeconf, homeconf.list_homeconf_files)
|
47
|
+
|
48
|
+
puts 'init.d scripts:'
|
49
|
+
homeconf.list_init_d.each do |init_file|
|
50
|
+
puts " #{File.basename(init_file)}"
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
54
|
def print_linked_table(homeconf, filepaths)
|
data/lib/homeconf/homeconf.rb
CHANGED
@@ -6,6 +6,7 @@ require 'fileutils'
|
|
6
6
|
require 'pathname'
|
7
7
|
require_relative 'errors'
|
8
8
|
require_relative 'file_finder'
|
9
|
+
require_relative 'init'
|
9
10
|
require_relative 'pathname'
|
10
11
|
|
11
12
|
module Homeconf
|
@@ -26,12 +27,16 @@ module Homeconf
|
|
26
27
|
@directory = File.realdirpath(File.expand_path(directory))
|
27
28
|
|
28
29
|
if @directory.eql? @homedir
|
29
|
-
raise InvalidHomeconfDir, "cannot use directory '#{@directory}': #{
|
30
|
+
raise InvalidHomeconfDir, "cannot use directory '#{@directory}': #{ENV['USER']} home directory cannot be used."
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def create
|
34
35
|
mkdir_unless_exists @directory
|
36
|
+
|
37
|
+
init = Init.new(@directory)
|
38
|
+
mkdir_unless_exists init.dirname
|
39
|
+
|
35
40
|
ignore_file = File.join(@directory, IGNORE_FILE)
|
36
41
|
return if File.exist?(ignore_file)
|
37
42
|
|
@@ -64,6 +69,9 @@ module Homeconf
|
|
64
69
|
unlinked_files.each do |f|
|
65
70
|
link(f)
|
66
71
|
end
|
72
|
+
|
73
|
+
init = Init.new(@directory, verbose: @verbose)
|
74
|
+
init.run
|
67
75
|
end
|
68
76
|
|
69
77
|
def validate
|
@@ -95,11 +103,13 @@ module Homeconf
|
|
95
103
|
# Returns whether the homeconf is initialized. Homeconf is initialized when all files and directories in the
|
96
104
|
# homeconf directory that are not ignored and symlinked from the home directory.
|
97
105
|
def initialized?
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
106
|
+
begin
|
107
|
+
validate_dir @directory
|
108
|
+
unlinked_dirs.empty? && unlinked_files.empty?
|
109
|
+
rescue StandardError => e
|
110
|
+
puts "Error: #{e}" if @verbose
|
111
|
+
false
|
112
|
+
end
|
103
113
|
end
|
104
114
|
|
105
115
|
def validate_dir(directory)
|
@@ -117,16 +127,21 @@ module Homeconf
|
|
117
127
|
FileFinder.homeconf_files @directory
|
118
128
|
end
|
119
129
|
|
130
|
+
def list_init_d
|
131
|
+
Init.new(@directory, verbose: @verbose).files
|
132
|
+
end
|
133
|
+
|
120
134
|
def linked?(filepath)
|
121
135
|
basename = File.basename(filepath)
|
122
|
-
link = File.join(
|
136
|
+
link = File.join(@homedir, basename)
|
123
137
|
return false unless File.symlink?(link)
|
124
138
|
|
125
|
-
expected_link_target = File.join(@directory, basename)
|
126
139
|
link_target = File.readlink(link)
|
127
140
|
link_target = File.join(@homedir, link_target) unless Pathname.new(link_target).absolute?
|
141
|
+
return false unless File.exist?(link_target)
|
128
142
|
|
129
143
|
link_target = File.realpath(link_target)
|
144
|
+
expected_link_target = File.join(@directory, basename)
|
130
145
|
expected_link_target.eql?(link_target)
|
131
146
|
end
|
132
147
|
|
@@ -183,14 +198,17 @@ module Homeconf
|
|
183
198
|
end
|
184
199
|
|
185
200
|
def mkdir_unless_exists(directory, permissions = 0o755)
|
186
|
-
|
187
|
-
Dir.
|
188
|
-
|
201
|
+
begin
|
202
|
+
unless Dir.exist? directory
|
203
|
+
Dir.mkdir directory, permissions
|
204
|
+
puts "Created directory. #{directory}" if @verbose
|
205
|
+
end
|
206
|
+
rescue Errno::ENOENT
|
207
|
+
raise HomeconfDirNotFound, "No such directory. #{File.dirname directory}"
|
208
|
+
rescue Errno::ENOTDIR
|
209
|
+
raise InvalidHomeconfDir, "Not a directory. #{File.dirname directory}"
|
189
210
|
end
|
190
|
-
rescue Errno::ENOENT
|
191
|
-
raise HomeconfDirNotFound, "No such directory. #{File.dirname directory}"
|
192
|
-
rescue Errno::ENOTDIR
|
193
|
-
raise InvalidHomeconfDir, "Not a directory. #{File.dirname directory}"
|
194
211
|
end
|
212
|
+
|
195
213
|
end
|
196
214
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require_relative 'errors'
|
5
|
+
require_relative 'file_finder'
|
6
|
+
module Homeconf
|
7
|
+
INITD_DIRNAME = 'init.d'
|
8
|
+
|
9
|
+
class Init
|
10
|
+
attr_reader :dirname, :verbose
|
11
|
+
|
12
|
+
def initialize(homeconf_dir, verbose: false)
|
13
|
+
@verbose = verbose
|
14
|
+
@dirname = File.join(homeconf_dir, INITD_DIRNAME)
|
15
|
+
end
|
16
|
+
|
17
|
+
def files
|
18
|
+
initd = realpath(@dirname)
|
19
|
+
return [] if initd.nil?
|
20
|
+
initd.children
|
21
|
+
.select(&:file?)
|
22
|
+
.reject { |p| p.eql?('.') || p.eql?('..') }
|
23
|
+
.select(&:executable?)
|
24
|
+
.map(&:to_s)
|
25
|
+
.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
files.each do |file|
|
30
|
+
result = system(file)
|
31
|
+
unless result
|
32
|
+
puts "Error running init.d script '#{File.basename(file)}': #{$?}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def realpath(filepath)
|
40
|
+
path = nil
|
41
|
+
begin
|
42
|
+
path = Pathname.new(filepath).expand_path.realpath
|
43
|
+
rescue Errno::ENOENT
|
44
|
+
return nil
|
45
|
+
rescue => e
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
raise InvalidHomeconfDir.new("Not a directory. #{filepath}") unless path.directory?
|
49
|
+
path
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/lib/homeconf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: homeconf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Lundquist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faker
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/homeconf/errors.rb
|
114
114
|
- lib/homeconf/file_finder.rb
|
115
115
|
- lib/homeconf/homeconf.rb
|
116
|
+
- lib/homeconf/init.rb
|
116
117
|
- lib/homeconf/pathname.rb
|
117
118
|
- lib/homeconf/version.rb
|
118
119
|
homepage: https://github.com/EpicMaven/homeconf
|
@@ -121,8 +122,8 @@ licenses:
|
|
121
122
|
metadata:
|
122
123
|
homepage_uri: https://github.com/EpicMaven/homeconf
|
123
124
|
bug_tracker_uri: https://github.com/EpicMaven/homeconf/issues
|
124
|
-
source_code_uri: https://github.com/EpicMaven/homeconf/tree/v0.
|
125
|
-
documentation_uri: https://rubydoc.info/gems/EpicMaven/0.
|
125
|
+
source_code_uri: https://github.com/EpicMaven/homeconf/tree/v0.2.0
|
126
|
+
documentation_uri: https://rubydoc.info/gems/EpicMaven/0.2.0
|
126
127
|
post_install_message:
|
127
128
|
rdoc_options:
|
128
129
|
- "--main"
|