[ubuntu-uk] Clearing home directory at logout

Rob Beard rob at esdelle.co.uk
Fri Jan 30 17:16:08 GMT 2009


On 30/01/2009 16:51, Andrew Oakley wrote:
> 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 ----
>
>    
Ahh thanks Andrew, it looks like this will do exactly what I want, not 
sure if it work with the PostSession, I couldn't seem to get anything in 
PostSession to work but it should at least work with GDM Watchdog.  I'll 
post back if I can get it working.

Rob




More information about the ubuntu-uk mailing list