Wicked Cool Shell Scripts
Wicked Cool Shell Scripts :: shell script 048-fixguest.sh

Shell Script 048-fixguest.sh

#!/bin/sh

# fixguest - Clean up the guest account during the logout process

# don't trust environment variables: reference read-only sources

iam="$(whoami)"
myhome="$(grep "^${iam}:" /etc/passwd | cut -d: -f6)"

# *** Do NOT run this script on a regular user account!

if [ "$iam" != "guest" ] ; then
  echo "Error: you really don't want to run fixguest on this account." >&2
  exit 1
fi

if [ ! -d $myhome/..template ] ; then
  echo "$0: no template directory found for rebuilding." >&2
  exit 1
fi

# remove all files and directories in the home account

cd $myhome

rm -rf * $(find . -name ".[a-zA-Z0-9]*" -print)

# now the only thing present should be the ..template directory

cp -Rp ..template/* .

exit 0

Explore The Book!
[book cover]
Table of Contents
Read Some Scripts!
Shell Script Library
Book Errata
All The Links
Read the Reviews
Talk About It
Author Bio
Buy The Book!



Other books by author Dave Taylor
Learning Unix for Mac OS X (O'Reilly & Associates)
Solaris 9 for Dummies (Wiley)
Teach Yourself Unix in 24 Hours (Sams/Macmillan)
Teach Yourself Unix System Administration in 24 Hours (Sams/Macmillan)
Creating Cool HTML 4 Web Pages (Wiley)
Ten Quick Steps to Learning Mac OS X Unix (ebook!)