MacInTouch: updating then resetting a Mac for an Out of the Box experience

I have done exactly what Barry would like to do, and it is worth it for the OOB experience!

In my case all I did was install all the Apple updates and the software they had bought.

Once you are ready to reset the Mac; open the Terminal and delete the AppleSetupDone file, which will cause the Apple Setup Assistant to run on the next boot.

Here’s the detailed version:

loki:~$ cd /private/var/db/
loki:/private/var/db$ ls -la .AppleSetupDone 
--w----r--   1 root  wheel  0 Jul 16  2004 .AppleSetupDone
loki:/private/var/db$sudo rm .AppleSetupDone
Password:

Translation to English for those of you still learning UNIX:
‘change directory’ to /private/var/db/
‘list in long format and show files and folders whose name starts with a dot or double dot’
‘superuser do’ ‘remove’ .AppleSetupDone
then put in your password to approve the action.

All done!

MacInTouch: timely news and tips about the Apple Macintosh
[Barry Brown]
I am thinking of getting a Mac mini for a friend as a gift. I’d like to to install and configure some third-party apps and the latest updates before giving it away. That’s easy enough. But I also want the out-of-box experience for the recipient to be the same as if the mini was new: it goes through the Welcome movie, account setup, and network setup. How can I “reset” the Mac so it removes all the accounts and walks the new user through the setup process when it’s turned on again?

6 thoughts to “MacInTouch: updating then resetting a Mac for an Out of the Box experience”

  1. Well, that method doesn’t erase the first user, its group and all groups he’s integrated in.

    I have a shell script that does it so I can have a perfectly out-of-the box experience (ie the user created by the assistant has UID 501 and so on…). You just need to start in Single-User Mode, fsck, mount the boot volume as readable then execute the script and, finally, remove the script.

    Put the script at volume root (so you won’t search it when in SU mode) and make it executable (chmod +x /path/to/the/script.

    Here is the script :

    ==============================

    #!/bin/sh

    #########
    # This script will erase user with UID 501, the first created
    # It also removes the associated group and removes the user
    # from system groups.
    # Finally, it removes the file indicating the Setup Assistand was done so
    # it’s relaunched at next boot.
    #########

    #########
    #
    # Laurent Pertois, Massy, le 13 juillet 2005
    #
    #########

    NIDB_FILE=”/var/db/netinfo/local.nidb”
    PASSWORD_FILES=”/var/db/shadow/hash”
    USER_SHORT_NAME=”`/usr/bin/nicl -raw “${NIDB_FILE}” -search /users 0 1 uid 501 | /usr/bin/grep -w “name:” | /usr/bin/awk ‘{print $2}’`”
    USER_GENERATEDUID=”`/usr/bin/nicl -raw “${NIDB_FILE}” -read /users/${USER_SHORT_NAME} generateduid | /usr/bin/awk ‘{print $2}’`”
    USER_HOME=”/Users/${USER_SHORT_NAME}”
    APPLE_ASSISTANT=”/var/db/.AppleSetupDone”

    if [ ! -e “${NIDB_FILE}” ]; then
    echo “Il n’y a pas de base NetInfo !” ;exit
    fi

    echo ” Deleting user ‘${USER_SHORT_NAME}’ !” 2>&1

    echo ” Deleting user ‘${PASSWORD_FILES}/${USER_GENERATEDUID}’ !” 2>&1
    /bin/rm “$PASSWORD_FILES/$USER_GENERATEDUID” “$PASSWORD_FILES/$USER_GENERATEDUID.state”

    echo ” Deleting user ‘${USER_SHORT_NAME}’ from NetInfo/users !” 2>&1
    /usr/bin/nicl -raw “${NIDB_FILE}” -delete /users/$USER_SHORT_NAME

    echo ” Deleting group ‘${USER_SHORT_NAME}’ from NetInfo/groups !” 2>&1
    /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/$USER_SHORT_NAME

    echo ” Removing user ‘${USER_SHORT_NAME}’ from NetInfo/groups/admin !” 2>&1
    /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/admin users $USER_SHORT_NAME

    echo ” Removing user ‘${USER_SHORT_NAME}’ from NetInfo/groups/appserveradm !” 2>&1
    /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/appserveradm users $USER_SHORT_NAME

    echo ” Removing user ‘${USER_SHORT_NAME}’ from NetInfo/groups/appserverusr !” 2>&1
    /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/appserverusr users $USER_SHORT_NAME

    echo ” Deleting ‘${USER_HOME}’ !” 2>&1
    /bin/rm -r “${USER_HOME}”

    echo ” Deleting ‘${APPLE_ASSISTANT}’ !” 2>&1
    /bin/rm “${APPLE_ASSISTANT}”

    ==================================

    Beware of line cuts, I have a downloadable version here :

    Feel free to improve but don’t forget to tell me :

    legends AT free DOT fr

  2. My mistake, I forgot to check if the user is called admin. In this case, we should not delete the admin group but just removing the user from the group.

    The linked zip file is correct now, here is the code :

    #!/bin/sh

    #########
    # This script will erase user with UID 501, the first created
    # It also removes the associated group and removes the user
    # from system groups.
    # Finally, it removes the file indicating the Setup Assistand was done so
    # it’s relaunched at next boot.
    #########

    #########
    #
    # Laurent Pertois, Massy, le 5 octobre 2005
    #
    #########

    NIDB_FILE=”/var/db/netinfo/local.nidb”
    PASSWORD_FILES=”/var/db/shadow/hash”
    USER_SHORT_NAME=”`/usr/bin/nicl -raw “${NIDB_FILE}” -search /users 0 1 uid 501 | /usr/bin/grep -w “name:” | /usr/bin/awk ‘{print $2}’`”
    USER_GENERATEDUID=”`/usr/bin/nicl -raw “${NIDB_FILE}” -read /users/${USER_SHORT_NAME} generateduid | /usr/bin/awk ‘{print $2}’`”
    USER_HOME=”/Users/${USER_SHORT_NAME}”
    APPLE_ASSISTANT=”/var/db/.AppleSetupDone”

    if [ ! -e “${NIDB_FILE}” ]; then
    echo “There is no NetInfo Database !” ;exit
    fi

    echo ” Deleting user ‘${USER_SHORT_NAME}’ !” 2>&1

    echo ” Deleting user ‘${PASSWORD_FILES}/${USER_GENERATEDUID}’ !” 2>&1 /bin/rm “$PASSWORD_FILES/$USER_GENERATEDUID” “$PASSWORD_FILES/$USER_GENERATEDUID.state”

    echo ” Deleting user ‘${USER_SHORT_NAME}’ from NetInfo/users !” 2>&1 /usr/bin/nicl -raw “${NIDB_FILE}” -delete /users/$USER_SHORT_NAME

    echo ” Deleting group ‘${USER_SHORT_NAME}’ from NetInfo/groups !” 2>&1
    if [ “${USER_SHORT_NAME}” = admin ]; then
    echo ” admin is a system group, we can’t delete it, we will remove the user at next step” 2>&1;
    else
    /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/$USER_SHORT_NAME;
    fi

    echo ” Removing user ‘${USER_SHORT_NAME}’ from NetInfo/groups/admin !” 2>&1 /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/admin users $USER_SHORT_NAME

    echo ” Removing user ‘${USER_SHORT_NAME}’ from NetInfo/groups/appserveradm !” 2>&1 /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/appserveradm users $USER_SHORT_NAME

    echo ” Removing user ‘${USER_SHORT_NAME}’ from NetInfo/groups/appserverusr !” 2>&1 /usr/bin/nicl -raw “${NIDB_FILE}” -delete /groups/appserverusr users $USER_SHORT_NAME

    echo ” Deleting ‘${USER_HOME}’ !” 2>&1 /bin/rm -r “${USER_HOME}”

    echo ” Deleting ‘${APPLE_ASSISTANT}’ !” 2>&1 /bin/rm “${APPLE_ASSISTANT}”

    ———————

    Beware of line cut !

  3. I tried the script on a machine running Panther. Doesn’t work, gives me an error when trying to delete the 501 user. .AppleSetupDone file isn’t deleted either. Does this run only on Tiger?

  4. Pingback: StyleMac.com

Comments are closed.