Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A script to remove erroneous duplicate ACL permissions on Mac OS 10.6
#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.8.7" > .rvmrc
environment_id="ruby-1.8.7-p249@aclfix"
# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.14.3 (latest)" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
if [[ $- == *i* ]] # check for interactive shells
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
fi
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create use "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1
}
fi
# If you use bundler, this might be useful to you:
# if [[ -s Gemfile ]] && {
# ! builtin command -v bundle >/dev/null ||
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
# }
# then
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
# gem install bundler
# fi
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
# then
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
# fi
#!/usr/bin/env ruby
# == Synopsis
# A script to remove erroneous duplicate ACL permissions on Mac OS 10.6
#
# == Usage
# aclfix.rb [options] source_file
#
# For help use: aclfix.rb -h
#
# == Options
# -h, --help Displays help message
# -v, --version Display the version, then exit
# -q, --quiet Output as little as possible, overrides verbose
# -V, --verbose Verbose output
# -R, --recursive Recursively processes directories
#
# == Copyright
# Copyright (c) 2011 Tim van der Horst. Licensed under the MIT License:
# http://www.opensource.org/licenses/mit-license.php
# Application skeleton sourced from here: http://blog.toddwerth.com/entries/show/5
require 'rubygems'
require 'escape'
require 'optparse'
require 'rdoc/usage'
require 'ostruct'
require 'date'
class App
VERSION = "1.0.5"
attr_reader :options
def initialize(arguments, stdin)
@arguments = arguments
@stdin = stdin
# Set defaults
@options = OpenStruct.new
@options.verbose = false
@options.quiet = false
@options.recursive = false
end
# Parse options, check arguments, then process the command
def run
if parsed_options? && arguments_valid?
puts "Start at #{DateTime.now}" if @options.verbose
output_options if @options.verbose # [Optional]
process_arguments
process_command
puts "Finished at #{DateTime.now}" if @options.verbose
else
output_usage
end
end
protected
def parsed_options?
# Specify options
opts = OptionParser.new
opts.on('-R', '--recursive') { @options.recursive = true }
opts.on('-v', '--version') { output_version ; exit 0 }
opts.on('-h', '--help') { output_help }
opts.on('-V', '--verbose') { @options.verbose = true }
opts.on('-q', '--quiet') { @options.quiet = true }
# TO DO - add additional options
opts.parse!(@arguments) rescue return false
process_options
true
end
# Performs post-parse processing on options
def process_options
@options.verbose = false if @options.quiet
end
def output_options
puts "Options:"
@options.marshal_dump.each do |name, val|
puts " #{name} = #{val}"
end
end
# True if required arguments were provided
def arguments_valid?
true
end
# Setup the arguments
def process_arguments
# TO DO - place in local vars, etc
end
def output_help
output_version
RDoc::usage() #exits app
end
def output_usage
RDoc::usage('usage') # gets usage from comments above
end
def output_version
puts "#{File.basename(__FILE__)} version #{VERSION}"
end
def colorize(text, color_code)
"#{color_code}#{text}\e[0m"
end
def red(text); colorize(text, "\e[31m"); end
def green(text); colorize(text, "\e[32m"); end
def bold(text); colorize(text, "\e[1m"); end
def header(file, already_done)
if not already_done and not @options.quiet
puts bold "#{Dir.pwd}/#{file}:"
end
true
end
def process_file(file)
done = false
if File.exists? file
result = `#{Escape.shell_command(["ls", "-led", "--", file])}`
if result.empty?
done = header(file, done)
warn red "ls had an error!"
else
@acl = result.split("\n")[1..-1].collect do |ace|
ace = ace.split(": ", 2)
ace[0] = ace[0].to_i
ace
end
if @acl.length > 1
if @options.verbose
done = header(file, done)
puts "#{@acl.length} ACEs present"
end
@unique = Array.new
@removal = Array.new
@acl.each do |index, rule|
if @unique.include? rule
@removal.push index
else
@unique.push rule
end
end
if @removal.length > 0
if not @options.quiet
done = header(file, done)
puts green "#{@unique.length} unique ACEs present (#{@acl.length} total)"
end
@removal.reverse!
@removal.each do |index|
if system("chmod", "-a#", index.to_s, file)
if @options.verbose
done = header(file, done)
puts "Removing ACE at index #{index}..."
end
else
if not @options.quiet
done = header(file, done)
warn red "Can't remove ACE at index #{index}!"
end
end
end
end
elsif @acl.length == 1
if @options.verbose
done = header(file, done)
puts "Only one ACE"
end
else
if @options.verbose
done = header(file, done)
puts "No ACL permissions"
end
end
if File.directory? file and @options.recursive
Dir.chdir(file) do
Dir.entries('.').each do |entry|
if entry != '.' and entry != '..'
process_file(entry)
end
end
end
end
end
elsif not @options.quiet
done = header(file, done)
warn red 'No such file or directory'
end
end
def process_command
@arguments.each do |file|
process_file(file)
end
end
end
app = App.new(ARGV, STDIN)
app.run
source 'https://rubygems.org'
gem 'escape'
GEM
remote: https://rubygems.org/
specs:
escape (0.0.4)
PLATFORMS
ruby
DEPENDENCIES
escape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.