#!/bin/bash # default_background Version 0.1 # Most of this code was from Eric Harrison's "K12LTSP-Backgrounds" code # Original Source: ftp://k12linux.mesd.k12.or.us/pub/K12LTSP/testing/SRPMS/k12ltsp-backgrounds-0-0.src.rpm # Some code originates from http://www.tldp.org/LDP/abs/html/ # Additional code by Jon Spriggs (jon {dot} spriggs {at sign} g {for google} mail {dot} com) # Eric's code produced only a default background image. Because of the environment I'm trying to create # I want to set either a mandatory image or colour plate (depending on whether the environment will be # remote or local). As this is not yet defined for my environment, I'm taking a sledgehammer and nut. # The original code has been modified to accept the following switches: # # --mandatory # AKA -m # # --colour # --color # AKA -c # # --revert # --remove # --delete # AKA -r # # Or, no switches which implies default only. # Let's start with the code itself. ROOT_UID=0 # Only users with $UID 0 have root privileges. E_NOTROOT=127 # Non-root exit error. # Run as root, of course. if [ "$UID" -ne "$ROOT_UID" ] then echo "You are not root. You must be root to run this script, otherwise it won't work. Sorry." exit $E_NOTROOT fi touch /etc/sysconfig/background/default.img case "$1" in "") VAR1= ;; *) VAR1=$1 ;; esac case "$2" in "") VAR2= ;; *) VAR2=$2 ;; esac case "$3" in "") VAR3= ;; *) VAR3=$3 ;; esac case "$4" in "") VAR4= ;; *) VAR4=$4 ;; esac case "$5" in "") VAR5= ;; *) VAR5=$5 ;; esac SETORUNSET=set ProcessVariables () { case "$1" in --help) showusage ;; --usage) showusage ;; -m) MANDATORY=TRUE ;; --mandatory) MANDATORY=TRUE ;; --revert) SETORUNSET=unset ;; --remove) SETORUNSET=unset ;; --delete) SETORUNSET=unset ;; -r) SETORUNSET=unset ;; "") return 1 ;; *) FILEORCOLOUR=$1 ;; esac } showusage () { echo "`basename $0` {-m | -r} (file)" echo "-m Sets a mandatory background" echo "-r Removes a mandatory or default background" echo "If used with no switches, this will produce this screen" echo "If a filename only is provided, then this file will be used as the default background" exit 255 } ProcessVariables $1 ProcessVariables $2 ProcessVariables $3 ProcessVariables $4 ProcessVariables $5 if [ ! "$FILEORCOLOUR" ] then showusage exit 0 fi echo $SETORUNSET $FILEORCOLOUR \(Mandatory? $MANDATORY\) if [ -f "$FILEORCOLOUR" ] then COLOUR=FALSE else COLOUR=TRUE fi if [ `echo "$COLOUR" | grep "FALSE"` ] then # is it an image file? IMAGE=`file $FILEORCOLOUR | cut -d":" -f2- | grep -i image` if [ ! "$IMAGE" ] then showusage fi fi if [ `echo "$SETORUNSET" | grep "set"` ] then mv /etc/sysconfig/background/default.img /etc/sysconfig/background/default.img.last cp "$FILEORCOLOUR" /etc/sysconfig/background/default.img chown root:root /etc/sysconfig/background/default.img chmod 0644 /etc/sysconfig/background/default.img fi if [ `echo "$MANDATORY" | grep "TRUE"` ] then gconftool-2 --direct --type string \ --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory \ --$SETORUNSET /desktop/gnome/background/picture_filename /etc/sysconfig/background/default.img else gconftool-2 --direct --type string \ --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults \ --$SETORUNSET /desktop/gnome/background/picture_filename /etc/sysconfig/background/default.img fi