Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created December 22, 2010 03:55
Show Gist options
  • Save rockpapergoat/751062 to your computer and use it in GitHub Desktop.
Save rockpapergoat/751062 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -wKU
# 101221, nate
# attempt to fix perm/ownership issues on locally attached storage
# for some reason, these arrays were configured with ownership disabled
#
require 'osx/cocoa'
# get name of root volume,
# subtract it from array of total volumes
# to avoid messing with ownership there
def get_volumes
root = [OSX.load_plist(`diskutil info -plist /`)['VolumeName']]
@volumes = OSX.load_plist(`diskutil list -plist`)['VolumesFromDisks'] - root
end
# change to vsdbutil -i to enable ownership on all mounted vols
def enable_ownership
#@volumes.each { |vol| system "vsdbutil -c \"/Volumes/#{vol}\"" }
%x(vsdbutil -i)
end
def get_logged_in_user
@user = %x(w | awk '/[c]onsole/ {print $1}').chomp
@group = "staff"
end
def set_ownership(user, group, volumes)
#@volumes.each { |vol| FileUtils.chown_R(@user, @group, "\"/Volumes/#{vol}\"", :verbose => true)}
cleaned = @volumes.each {|vol| vol.gsub(/\s/, "\\ ") }
cleaned.each { |escaped| system "chown -Rfv #{@user}:#{@group} \"/Volumes/#{escaped}\"" }
end
def check_root
if ENV['USER'] != "root"
puts "This script must be run as root.\nPlease try again."
exit(1)
end
end
# make it work
check_root
enable_ownership
get_volumes
get_logged_in_user
set_ownership(@user, @group, @volumes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment