chom 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/chom.rb +27 -10
- data/lib/chom/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e31734c651a29814b24b60d5657eb2f14c38cd6
|
4
|
+
data.tar.gz: a17e5d1067e46820438d0782b5fc32f3d0d0080a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d219bf160ca7914a5a3d21612ba67a3b0d2a515df8a9ff65b1267745f0fd64da6971b22df79c4d2bb1c1cb314894de63d5c4190cf603c2505ab1ab34d2217cc9
|
7
|
+
data.tar.gz: 2f2dfaeade81914c0e718cbb709dbc550e323b74276264432d8176c1d74d8f0ac7c7a8fbcc57c7131d9980a43a4d809231a723f4e072ad1ba696eae8e5ca028e
|
data/README.md
CHANGED
data/lib/chom.rb
CHANGED
@@ -6,16 +6,17 @@ require 'fileutils'
|
|
6
6
|
#
|
7
7
|
# Specificaly, it executes:
|
8
8
|
# $ chown -R g+w .
|
9
|
-
# $ chmod -R <username
|
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
|
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
|
-
|
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}
|
42
|
-
FileUtils.chown_R @user,
|
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
|
-
|
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
|
51
|
-
puts
|
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
|
data/lib/chom/version.rb
CHANGED