require 'reap/task' # # File Permissions Task # class Reap::Perm < Reap::Task task_desc "Normalize ownership and permissions of package files." section_required true attr_accessor :user, :group, :filemod, :dirmod def init @user = section['user'] @group ||= @user @filemod ||= 644 @dirmod ||= 755 end def run puts "Reap is shelling out work to chmod..." # misc misc = FileList.new misc.include('[A-Z]*') misc.exclude('InstalledFiles') chmod( misc ) unless misc.empty? # lib libs = FileList.new libs.include('lib/**/*') libs.exclude('lib/CVS/**/*') libs.include('packages/*/lib/**/*') libs.exclude('packages/*/lib/CVS/**/*') libs.exclude('packages/CVS/**/*') chmod( libs ) unless libs.empty? # bin bins = FileList.new bins.include('bin/**/*') bins.exclude('bin/CVS/**/*') bins.include('packages/*/bin/**/*') bins.exclude('packages/*/bin/CVS/**/*') bins.exclude('packages/CVS/**/*') chmod( bins, 755 ) unless bins.empty? end # support functions def chmod( file_list, file_mode=644, dir_mode=755 ) dirs, files = file_list.partition{ |l| File.directory?(l) } unless files.empty? fstr = '"' + files.join('" "') + '"' sh %{chmod #{file_mode} #{fstr}} end unless dirs.empty? fstr = '"' + dirs.join('" "') + '"' sh %{chmod #{dir_mode} #{fstr}} end end def run_chown puts "NOT YET IMPLEMENTED" end # def _chown( file_list, user, group ) # fstr = '"' + file_list.join('" "') + '"' # if user # if group # sh %{chown #{user}.#{group} #{fstr}} # else # sh %{chown #{user} #{fstr}} # end # end # end end #Reap.register( Reap::Perm )