#!/bin/sh # # Short: Create Mac OS X NetInfo mounts from a text file # Version: 2.04, 12-09-02 # Author: Mark J Swift, msw AT blackpool.ac.uk # Long: This script will create user folders and other required folders # for every user specified by netinfo. # The script also sets appropriate rights on these folders and removes # the lock attribute from every file. # Note, the script requires netinfo groups to have properties: realname, # home_loc and home_loc_owner (introduced in OS X 10.2). # If the user home folder does not exist, this script creates it: # "user_name" (u=r/w,g=r/w,o=r) # The script then creates the following folders inside the users' folder # "user_name/Sites" (u=r/w,g=r/w,o=r) # "user_name/Public" (u=r/w,g=r/w,o=r) # "user_name/Desktop" (u=r/w,g=r/w,o=none) # "user_name/Documents" (u=r/w,g=r/w,o=none) # "user_name/Library" (u=r/w,g=r/w,o=none) # "user_name/Movies" (u=r/w,g=r/w,o=none) # "user_name/Music" (u=r/w,g=r/w,o=none) # "user_name/Pictures" (u=r/w,g=r/w,o=none) # The script also creates the following (Macintosh Manager) folder # within the mount folder: # "Users/Groups Folder/group_name/Hand In Ä/user_name" (u=w,g=r/w,o=none) # (u=user_name,g=wheel) # # 1. Log in as root # # 2. Copy this script into roots home directory # (/private/var/root/Documents). # # 3. Start a new shell process and change directory to roots home. # # cd ~/Documents # # 4. Set the execute flag is set on the script, type: # # chmod u+x mkuserfldrs.sh # # 5. Execute the "mkuserfldrs.sh" script with the following command: # # ~/Documents/mkuserfldrs.sh # # The script will create netinfo entries for every mount # point in the text file. # list of private folders that we want in users home folder reqd_private="Desktop,Documents,Library,Movies,Music,Pictures" # list of public folders that we want in users home folder reqd_public="Sites,Public" # SET CONSTANTS fldrchar=`echo "ab" | tr "ab" "\306\222"` # get the name of this workstation node_name=`uname -n` # -------------------------------- # debug - print host details to screen # -------------------------------- # echo " node_name:$node_name" for ni_user_name in `nireport / /users name` do ni_user_id=`niutil -read / /users/$ni_user_name | grep -y "^uid: " | cut -d: -f2 | tr -d "\040"` # -------------------------------- # debug - print user home details to screen # -------------------------------- # echo " ni_user_name: $ni_user_name" # echo " ni_user_id: $ni_user_id" if [ $ni_user_id -gt 1024 ] then ni_user_realname=`niutil -read / /users/$ni_user_name | grep -y "^realname: " | cut -d: -f2 | cut -c2-` ni_user_home=`niutil -read / /users/$ni_user_name | grep -y "^home: " | cut -d: -f2 | cut -c2-` ni_user_gid=`niutil -read / /users/$ni_user_name | grep -y "^gid: " | cut -d: -f2 | cut -c2-` # -------------------------------- # debug - print user home details to screen # -------------------------------- # echo " ni_user_realname: $ni_user_realname" # echo " ni_user_home: $ni_user_home" # echo " ni_user_gid: $ni_user_gid" count=`echo "$ni_user_home" | grep -c -y "^/Network/Servers/$node_name\b"` if [ $count -ne 0 ] then ni_user_path=/`echo $ni_user_home | cut -d/ -f5-` # check if home fldr exists as either short or long name, rename as necessary homepath=`dirname "$ni_user_path"` homefldr=`basename "$ni_user_path"` if test "$ni_user_name" != "$ni_user_realname" then if test "$homefldr" = "$ni_user_name" then if test -d "$homepath/$ni_user_realname" then echo " : renaming directory $homepath/$ni_user_realname" mv "$homepath/$ni_user_realname" "$ni_user_path" fi fi if test "$homefldr" = "$ni_user_realname" then if test -d "$homepath/$ni_user_name" then echo " : renaming directory $homepath/$ni_user_name" mv "$homepath/$ni_user_name" "$ni_user_path" fi fi fi # does user folder exist? if test -d "$ni_user_path" then # yes, folder is there! echo " : updating directory $ni_user_path" else echo " : making directory $ni_user_path" mkdir "$ni_user_path" fi chown $ni_user_id "$ni_user_path" chgrp 0 "$ni_user_path" chmod 775 "$ni_user_path" # remove lock attribute from user files chflags -R noschg,nouchg "$ni_user_path" # list of private folders that we want to make in users folder reqd_folders=$reqd_private while [ $reqd_folders ]; do # get a folder name folder_name=`echo $reqd_folders | cut -d, -f1` reqd_folders=`echo $reqd_folders | cut -d, -s -f2-` # does folder exist? if test -d "$ni_user_path/$folder_name" then # yes, folder is there! echo " : updating directory $ni_user_path/$folder_name" else echo " : making directory $ni_user_path/$folder_name" mkdir "$ni_user_path/$folder_name" fi chown -R $ni_user_id "$ni_user_path/$folder_name" chgrp -R 0 "$ni_user_path/$folder_name" chmod -R 770 "$ni_user_path/$folder_name" done # list of public folders that we want to make in users folder reqd_folders=$reqd_public while [ $reqd_folders ]; do # get a folder name folder_name=`echo $reqd_folders | cut -d, -f1` reqd_folders=`echo $reqd_folders | cut -d, -s -f2-` # does folder exist? if test -d "$ni_user_path/$folder_name" then # yes, folder is there! echo " : updating directory $ni_user_path/$folder_name" else echo " : making directory $ni_user_path/$folder_name" mkdir "$ni_user_path/$folder_name" fi chown -R $ni_user_id "$ni_user_path/$folder_name" chgrp -R 0 "$ni_user_path/$folder_name" chmod -R 775 "$ni_user_path/$folder_name" done ni_grup_name=`niutil -read / /groups/gid=$ni_user_gid | grep -y "^name: " | cut -d: -f2 | tr -d "\040"` ni_grup_realname=`niutil -read / /groups/$ni_grup_name | grep -y "^realname: " | cut -d: -f2 | cut -c2-` ni_grup_share_fldr=`niutil -read / /groups/$ni_grup_name | grep -y "^home_loc: " | cut -d: -f3 | cut -d/ -f4 | cut -d"<" -f1 ` ni_dirid=`nigrep "^$ni_grup_share_fldr$" . /config/SharePoints | cut -d ' ' -f1 | tail -n 1` ni_share_directory_path=`niutil -read . $ni_dirid | grep -y "^directory_path: " | cut -d" " -f2-` # -------------------------------- # debug - print share details to screen # -------------------------------- # echo " ni_dirid: $ni_dirid" # echo " ni_share_directory_path: $ni_share_directory_path" if test -z "$ni_share_directory_path" then echo " ERROR : cannot create group folders for User $ni_user_realname. SharePoint $ni_grup_share_fldr is missing directory_path property." else hif="Hand In $fldrchar" # does (macintosh manager) "Users/Groups Folder/group name/Hand In Ä" folder exist? if test -d "$ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif" then # does (macintosh manager) "Users/Groups Folder/group name/Hand In Ä/user realname" folder exist? if test -d "$ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" then # yes, folder is there! echo " : updating directory $ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" else echo " : making directory $ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" mkdir "$ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" fi chown $ni_user_id "$ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" chgrp 0 "$ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" chmod 370 "$ni_share_directory_path/Users/Groups Folder/$ni_grup_realname/$hif/$ni_user_realname" fi fi fi fi done