homeconf 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cf63d8611a53b1460d46778e90accab8aa4262a20331cad2eb18ced5d4277c8
4
- data.tar.gz: 945cb15e1663b10ffebc9e2b46f3c70bd98a1945e18a15b197666d95c3b53429
3
+ metadata.gz: 437c7110926daf0a53413ed3cce8b8d4b51269d8d076695473cd05e040c2251f
4
+ data.tar.gz: f6a0cc2690ff3b95357a9600ab433ac6cc0019f8aa6c052622fbb685b77b4812
5
5
  SHA512:
6
- metadata.gz: 359ee4fe10983458d18cfb6930e86dd5fac1f5a5e4c5493e0204b1e6623a945a0fd2e2e92b8a4193e50d640f61c6e9df2a36414e96d0e072bfb20af7552ce971
7
- data.tar.gz: 3d5af3427c823d99fd26d5066a7f1882872585cfb02f642616823e201ba844ed659fa21a46dd7375351e23d7af199ae85479a24d204270cb542569a1a6406a56
6
+ metadata.gz: 2cc6cffd26e349a6452f1adab18018d9d3ffecc374df8b3fe1fff34366ad6fb33688f735582de4e454e5c5d2178ca38164293a243d4a019289d13b2c6ca518b0
7
+ data.tar.gz: 610abcb77db3cfece8157171417ec93e8af590ee939b6b817b44795451401e1e972607cb971ef25a0ba7d453a8b923773ef3b8d49829569802250a29169f776c
data/bin/homeconf CHANGED
@@ -6,6 +6,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
 
7
7
  require 'getoptlong'
8
8
  require 'homeconf'
9
+ require 'set'
9
10
 
10
11
  @this = File.basename $PROGRAM_NAME
11
12
 
@@ -44,6 +45,11 @@ def print_config(homeconf)
44
45
  print_linked_table(homeconf, homeconf.list_homeconf_dirs)
45
46
  puts 'homeconf files:'
46
47
  print_linked_table(homeconf, homeconf.list_homeconf_files)
48
+
49
+ puts 'init.d scripts:'
50
+ homeconf.list_init_d.each do |init_file|
51
+ puts " #{File.basename(init_file)}"
52
+ end
47
53
  end
48
54
 
49
55
  def print_linked_table(homeconf, filepaths)
@@ -7,7 +7,10 @@
7
7
  # private_dir
8
8
  # *~
9
9
  # *.iml
10
- #
10
+
11
+ # homeconf init.d directory
12
+ init.d
13
+
11
14
  # vcs
12
15
  .git
13
16
  .svn
@@ -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}': #{$USER} home directory cannot be used."
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
- validate_dir @directory
99
- unlinked_dirs.empty? && unlinked_files.empty?
100
- rescue StandardError => e
101
- puts "Error: #{e}" if @verbose
102
- false
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,6 +127,10 @@ 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
136
  link = File.join(@homedir, basename)
@@ -184,14 +198,17 @@ module Homeconf
184
198
  end
185
199
 
186
200
  def mkdir_unless_exists(directory, permissions = 0o755)
187
- unless Dir.exist? directory
188
- Dir.mkdir directory, permissions
189
- puts "Created directory. #{directory}" if @verbose
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}"
190
210
  end
191
- rescue Errno::ENOENT
192
- raise HomeconfDirNotFound, "No such directory. #{File.dirname directory}"
193
- rescue Errno::ENOTDIR
194
- raise InvalidHomeconfDir, "Not a directory. #{File.dirname directory}"
195
211
  end
212
+
196
213
  end
197
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Homeconf
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.1'
5
5
  end
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.1.2
4
+ version: 0.2.1
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-06-10 00:00:00.000000000 Z
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.1.2
125
- documentation_uri: https://rubydoc.info/gems/EpicMaven/0.1.2
125
+ source_code_uri: https://github.com/EpicMaven/homeconf/tree/v0.2.1
126
+ documentation_uri: https://rubydoc.info/gems/EpicMaven/0.2.1
126
127
  post_install_message:
127
128
  rdoc_options:
128
129
  - "--main"
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  - !ruby/object:Gem::Version
142
143
  version: '0'
143
144
  requirements: []
144
- rubygems_version: 3.4.8
145
+ rubygems_version: 3.3.5
145
146
  signing_key:
146
147
  specification_version: 4
147
148
  summary: Homeconf manages portable, version controlled home directory configuration.