#!/bin/bash
# by lcj (c) 2005.01.03
# #######################################
# # MAKE BACKUP OF YOUR gdm.conf file ! #
# # USE ONLY AT YOUR OWN RISK!          #
# #######################################
#
# Purpose: Change randomly startig GDM theme in Gnome
# Usage: 
# 1. change the value: GDM_THEMES_LOCATION to directory with theme,
#  defaults to: /usr/share/gdm/themes.
#  remember the / at the end. There should be no other files than the
#  folders with themes in that directory!
# 2. change GDM_CONF_LOCATION to match your system gdm.conf
#  default: /etc/X11/gdm/gdm.conf
# 3. change TDIR (temprorary directory) for storing work files
#  default /root/tmp/ (don't PUT the '/' at the end.
#
# HOW TO RUN ?
#
# Run this script once every boot - like /etc/ini.t/network for example
#
# MAKE SURE ALL DIRS EXIST!
# version: 0.2
# history:
# 03-Jun-2005, based on script for random wallpaper, revised and rewritten version

# CHANGE IF NEEDED ALL 3 VALUES:
####################################################
GDM_THEMES_LOCATION="/usr/share/gdm/themes/"
GDM_CONF_LOCATION="/etc/X11/gdm/gdm.conf"
TEMPCONF="/root/tmp/gdm.conf"
####################################################
# main code, lets enter the directory
cd $GDM_THEMES_LOCATION
# counting number of folders
ile=`ls | wc -l | tr -d "[ ]"`
#reset counter to 1
counter=1
# now get every file name and put it ino pic[licznik] table
for i in `ls`
do
 pic[counter]=${GDM_THEMES_LOCATION}$i
 ((counter=counter+1))
done  
# now lets get the RANDOM number
which_pic=$(($RANDOM % $ile))
# set $ update the wallpaper
# for debugging: 
# echo $which_pic
NEW_THEME=${pic[$which_pic]}
cat $GDM_CONF_LOCATION | sed "s:GraphicalTheme=.*:GraphicalTheme=${NEW_THEME}:g" > ${TEMPCONF}
mv ${TEMPCONF} ${GDM_CONF_LOCATION}
