chom 0.1.0 → 0.1.1

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/lib/chom.rb +27 -10
  4. data/lib/chom/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1cc091de534a70bdd5eec5eea81e56f7ed37130
4
- data.tar.gz: 18eedf9fb794f0e00aa196bfe83936f2d806e55f
3
+ metadata.gz: 6e31734c651a29814b24b60d5657eb2f14c38cd6
4
+ data.tar.gz: a17e5d1067e46820438d0782b5fc32f3d0d0080a
5
5
  SHA512:
6
- metadata.gz: cefec073222ac44f00a0d3cb9266b71cc8927b49f2ecca0b23c97a347e08b5d8a6f928a5cc5d22685a6a2926cc382c2bbcc6fbe1a1ff4f02a1eee93daf23f929
7
- data.tar.gz: 414adf10d66c140db8462baf4ce8e909ed5cca3163ac1c9c2204b158a583e19120e3bd7109edacd566d2933f84b3b86fabb8fd3a1497546a0991c04354d5e68c
6
+ metadata.gz: d219bf160ca7914a5a3d21612ba67a3b0d2a515df8a9ff65b1267745f0fd64da6971b22df79c4d2bb1c1cb314894de63d5c4190cf603c2505ab1ab34d2217cc9
7
+ data.tar.gz: 2f2dfaeade81914c0e718cbb709dbc550e323b74276264432d8176c1d74d8f0ac7c7a8fbcc57c7131d9980a43a4d809231a723f4e072ad1ba696eae8e5ca028e
data/README.md CHANGED
@@ -6,8 +6,7 @@ web server.
6
6
  Specificaly, it executes:
7
7
 
8
8
  $ chown -R g+w .
9
- $ chmod -R <username>:www .
10
-
9
+ $ chmod -R <username>:<system www group> .
11
10
 
12
11
  ## Installation
13
12
 
@@ -6,16 +6,17 @@ require 'fileutils'
6
6
  #
7
7
  # Specificaly, it executes:
8
8
  # $ chown -R g+w .
9
- # $ chmod -R <username>:www .
9
+ # $ chmod -R <username>:<system www group> .
10
10
 
11
11
  module Chom
12
12
  # The App class stores Chom's functionality. It is executed with Chom::App.new.run.
13
13
  class App
14
14
  attr_reader :user
15
15
 
16
- # Creates Chom instance and assigns logged in user's username to @user.
16
+ # Creates Chom instance and sets user and group
17
17
  def initialize
18
18
  @user = Etc.getlogin
19
+ @group = system_www_group
19
20
  end
20
21
 
21
22
  # Chom command line utility executes run to recursively chown and chmod the current directory.
@@ -26,30 +27,46 @@ module Chom
26
27
 
27
28
  private
28
29
 
30
+ # Figure out system www group
31
+ def system_www_group
32
+ %w(www-data www).each do |possible_www_group|
33
+ begin
34
+ return possible_www_group if Etc.getgrnam possible_www_group
35
+ rescue ArgumentError
36
+ next
37
+ end
38
+ end
39
+ failure_exit_with_msg "I can't figure out the proper www group for this system."
40
+ end
41
+
29
42
  # Recursively changes ownership of current directory to the logged in user with the group www.
30
43
  def chown_dir_and_files_recursively
31
44
  print "Attempting 'chown -R g+w .' as '#{@user}'... "
32
45
  FileUtils.chmod_R 'g+w', '.'
33
46
  puts 'Success!'
34
47
  rescue Errno::EPERM
35
- puts 'Failed.'
36
- suggest_running_as_sudo_and_exit
48
+ failure_exit_with_msg sudo_msg
37
49
  end
38
50
 
39
51
  # Recursively changes permissions of current directory to be group writable.
40
52
  def chmod_dir_and_files_recursively
41
- print "Attempting 'chmod -R #{@user}:www' as '#{@user}'... "
42
- FileUtils.chown_R @user, 'www', '.'
53
+ print "Attempting 'chmod -R #{@user}:#{@group}' as '#{@user}'... "
54
+ FileUtils.chown_R @user, @group, '.'
43
55
  puts 'Success!'
44
56
  rescue Errno::EPERM
45
- puts 'Failed.'
46
- suggest_running_as_sudo_and_exit
57
+ failure_exit_with_msg sudo_msg
47
58
  end
48
59
 
49
60
  # Suggests running chom using sudo if regular execution fails due to lack of rights.
50
- def suggest_running_as_sudo_and_exit
51
- puts "Try running with 'sudo chom'."
61
+ def failure_exit_with_msg(msg)
62
+ puts 'Failed.'
63
+ puts msg
52
64
  exit false
53
65
  end
66
+
67
+ # Failure Message for both chown and chmod
68
+ def sudo_msg
69
+ "Try running with 'sudo chom'."
70
+ end
54
71
  end
55
72
  end
@@ -1,5 +1,5 @@
1
1
  # This module holds the Chom version information.
2
2
  module Chom
3
3
  # This is the Chom version number.
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.1.1'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Lerner