class Chom::App
The App
class stores Chom's functionality. It is executed with Chom::App.new
.run.
Attributes
user[R]
Public Class Methods
new()
click to toggle source
Creates Chom
instance and sets user and group
# File lib/chom.rb, line 17 def initialize @user = Etc.getlogin @group = system_www_group end
Public Instance Methods
run()
click to toggle source
Chom
command line utility executes run to recursively chown and chmod the current directory.
# File lib/chom.rb, line 23 def run chown_dir_and_files_recursively chmod_dir_and_files_recursively end
Private Instance Methods
chmod_dir_and_files_recursively()
click to toggle source
Recursively changes permissions of current directory to be group writable.
# File lib/chom.rb, line 52 def chmod_dir_and_files_recursively print "Attempting 'chmod -R #{@user}:#{@group}' as '#{@user}'... " FileUtils.chown_R @user, @group, '.' puts 'Success!' rescue Errno::EPERM failure_exit_with_msg sudo_msg end
chown_dir_and_files_recursively()
click to toggle source
Recursively changes ownership of current directory to the logged in user with the group www.
# File lib/chom.rb, line 43 def chown_dir_and_files_recursively print "Attempting 'chown -R g+w .' as '#{@user}'... " FileUtils.chmod_R 'g+w', '.' puts 'Success!' rescue Errno::EPERM failure_exit_with_msg sudo_msg end
failure_exit_with_msg(msg)
click to toggle source
Suggests running chom using sudo if regular execution fails due to lack of rights.
# File lib/chom.rb, line 61 def failure_exit_with_msg(msg) puts 'Failed.' puts msg exit false end
sudo_msg()
click to toggle source
Failure Message for both chown and chmod
# File lib/chom.rb, line 68 def sudo_msg "Try running with 'sudo chom'." end
system_www_group()
click to toggle source
Figure out system www group
# File lib/chom.rb, line 31 def system_www_group %w(www-data www).each do |possible_www_group| begin return possible_www_group if Etc.getgrnam possible_www_group rescue ArgumentError next end end failure_exit_with_msg "I can't figure out the proper www group for this system." end