[ubuntu-uk] Clearing home directory at logout

Andrew Oakley Andrew.Oakley at hesa.ac.uk
Fri Jan 30 16:51:22 GMT 2009


Rob Beard wrote:
> I was wondering if anyone knew how to clear out the home directory on 
> Ubuntu when a user logs out?

See below. Public domain, do as you like.

By default the script will assume the username "visitor". You can pass a
different username as a parameter if you wish.

I use this to create a customised Gnome guest account, for when I lend
my laptop to someone. I don't like Ubuntu 8.10's built-in guest account,
since it presents the user with an entirely vanilla uncustomised
environment. I prefer to customise the environment to make it more
friendly to first-time users; for example, I have it load the Firefox
browser straight away, since that's what 99% of visitors want to use.

Andrew Oakley
Head of Software Development
Higher Education Statistics Agency (HESA)
95 Promenade, Cheltenham, Gloucestershire GL50 1HZ

---- begin loadguest ----

#!/bin/bash

# Loadguest by Andrew Oakley www.aoakley.com public domain 2009-01-30
#
# Resets the home directory back to a predetermined default
# Requires saveguest to be run first
# Ideal for a guest account
# Default username is visitor instead of guest , since guest is used
# for the built-in guest account from Ubuntu 8.10
#
# Save this as /usr/local/bin/loadguest , chmod 755
# Add the following to /etc/gdm/PostLogin/Default:

# if [[ "$LOGNAME" == "visitor" ]]

# then

#   /usr/local/bin/loadguest

# fi

defaultusername=visitor
username=$1

if [[ "$username" == "" ]]

then

  username=$defaultusername

fi

if [[ -f /home/$username.tar.gz ]]

then

  cd /home

  rm -rf $username/*

  tar xvfz /home/$username.tar.gz

else

  echo "/home/$username.tar.gz does not exist or is not a regular file"

fi 

---- end loadguest ----
---- start saveguest ----

#!/bin/bash

# Saveguest by Andrew Oakley www.aoakley.com public domain 2009-01-30
# Saves a Gnome login session and indeed an entire home directory
# MUST BE RUN AS ROOT eg. sudo saveguest
# Requires loadguest
#
# Save this as /usr/local/sbin/saveguest , chmod 755
# Then log in as the user you wish to set up, THEN LOG OUT
# Then run this as root eg. sudo saveguest
defaultusername=visitor
username=$1

if [[ "$username" == "" ]]

then

  username=$defaultusername
fi

if [[ -d /home/$username ]]

then

  cd /home

  mv -f $username.tar.gz $username-old.tar.gz

  tar cvfz $username.tar.gz $username --exclude="*/.thumbnails/*"
--exclude="*ca
che*"

else

  echo "/home/$username does not exist or is not a directory"

  echo "Usage: saveguest [username]"

  echo "Assumes username 'visitor' if no username supplied"

fi  

---- end saveguest ----

_____________________________________________________________________

Higher Education Statistics Agency Ltd (HESA) is a company limited by
guarantee, registered in England at 95 Promenade Cheltenham GL50 1HZ.
Registered No. 2766993. The members are Universities UK and GuildHE.
Registered Charity No. 1039709. Certified to ISO 9001 and ISO 27001. 
 
HESA Services Ltd (HSL) is a wholly owned subsidiary of HESA,
registered in England at the same address. Registered No. 3109219.
_____________________________________________________________________

This outgoing email was virus scanned for HESA by MessageLabs.
_____________________________________________________________________



More information about the ubuntu-uk mailing list