Created
June 29, 2012 19:57
-
-
Save rockpapergoat/3020305 to your computer and use it in GitHub Desktop.
simulate casper's "fill each user" function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'FileUtils' | |
require 'pathname' | |
def get_homedir(user) | |
begin | |
Etc.getpwnam("#{user}")["dir"].chomp | |
rescue Exception => e | |
end | |
end | |
def get_all_over500_users | |
user_hash = {} | |
`dscl . -list /users UniqueID | sort -k2 -n`.split("\n").each do |pair| | |
pair.split(" ").collect! { user_hash[pair.split(" ")[0]] = pair.split(" ")[1].to_i} | |
end | |
user_hash.delete_if {|k,v| v.to_i < 500 } | |
# can also do it like this, but it reports all directory entries, not just local | |
# Etc.passwd { |d| user_hash[d.name] = d.uid if d.uid > 500 } | |
end | |
def stash_user_file(file,path) | |
users = get_all_over500_users | |
users.each_key do |u| | |
puts "copying files to #{u}\'s home at #{path}." | |
system "ditto -V #{file} #{get_homedir(u)}/#{path}/#{File.basename(file)}" | |
FileUtils.chown_R("#{u}", nil, "#{get_homedir(u)}/#{path}/#{File.basename(file)}") | |
end | |
end | |
stash_user_file("/Library/Preferences/blah","/Library/Preferences") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment