Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Store a user's Home folder on a USB drive' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Store a user's Home folder on a USB drive
Authored by: ptb@mac.com on Oct 29, '05 05:30:33PM
I have to simplified this script so fewer changes would need to be made from user to user. Unfortunately, after trying to login without the portable hard drive connected, a dialog appeared: You are unable to log in to the user account "user" at this time I'm giving up at this point, but wanted to share what I came up with in case it helps someone else.

#!/bin/bash

# PortableHome.sh ##################################################
# http://www.macosxhints.com/article.php?story=20050423203849332

# Change name for your portable storage device #####################
# To determine "name", in a Terminal window, type: /sbin/mount
# Look for the storage device name displayed after "/Volumes/".

name="Domicilium";

### You do not need to make any other modifications to this file ###


# Description ######################################################
# If you want to transport your home directory between any number of
# Macs using any portable storage device, this script makes it easy.
# Upon login, if the portable storage device is connected, it will
# load your user environment from the home directory stored there.
# Otherwise, it will use the home directory on the internal drive.

# Requirements #####################################################
# --> Account with administrator privileges to install and configure
# --> Portable storage device: iPod, FireWire, USB, or flash drive

# Recommendations ##################################################
# --> Create an additional user with admin privileges, as a backup
# --> Try this with a test account before switching your primary
# --> Shutdown before connecting or removing the storage device


# Initial one-time portable storage device setup ###################
# Connect the formatted portable storage device before continuing.
# To determine "devicename", in a Terminal window, type: /sbin/mount
# Look for the storage device name displayed after "/Volumes/".

# Type the following commands in a Terminal window, except:
# replace "devicename" with the appropriate storage device name,
# and replace "usernamehere" with your short user name.

#    /usr/bin/sudo /bin/mkdir -m 1775 "/Volumes/devicename/Users"

#    /usr/bin/sudo /usr/sbin/chown root:admin 
#       "/Volumes/devicename/Users"

#    /usr/bin/sudo /bin/cp -Rp 
#       "/System/Library/User Template/English.lproj" 
#       "/Volumes/devicename/Users/usernamehere"

#    /usr/bin/sudo /usr/sbin/chown -R usernamehere:staff 
#       "/Volumes/devicename/Users/usernamehere"


# Installation on each Mac #########################################
# As administrator save this file as: /Library/Hooks/PortableHome.sh

# Type the following commands in a Terminal window:

#    /usr/bin/sudo /bin/chmod +x /Library/Hooks/PortableHome.sh

#    /usr/bin/sudo /usr/bin/defaults write 
#       /Library/Preferences/com.apple.loginwindow LoginHook 
#       /Library/Hooks/PortableHome.sh

#    /usr/bin/sudo /usr/bin/defaults write 
#       /Library/Preferences/SystemConfiguration/autodiskmount 
#       AutomountDisksWithoutUserLogin -bool true


# Expected behavior ################################################
# Test if the portable storage device is connected and home exists.
# If so, change the defined location of home to the portable drive.
# Otherwise, change the defined location of home to internal drive.
#
# There is no need to do a -destroyprop first, because by definition
# with the -createprop switch, even if a named property already
# exists, it is overwritten.


# Variable substitutions ###########################################
path="/Volumes/${name}";
user=$1;


# Script ###########################################################
if [ -s "${path}/Users/${user}" ]
then
   /usr/bin/niutil -createprop . /users/${user} home ${path}/Users/${user}
else
   /usr/bin/niutil -createprop . /users/${user} home /Users/${user}
fi

exit 0


[ Reply to This | # ]