I finally got it to work..
Code:
#!/bin/bash
# Backup for Evolution 3.4.4
# it can be used in USER's cronjobs
# with full paths given
if [ -z $2 -o -d $2 ]; then
echo "Usage: [/path/to/]evobackup.sh {username} [/path/to/]backupfile --quiet"
exit 1
fi
# remember evolutions running state for current user
running=0
username=$1
quiet=$3
homeDirectory=/home/$username
echoQuiet () {
if [ -z "$1" ] # Is parameter #1 zero length?
then
return
else
if [ .$quiet. != ".--quiet." ]; then
echo "$1"
fi
fi
return
}
pgrep -u $username -f '.*alltray.*evolution' > /tmp/evolutionPgrep.pid
checkPgrep=$?
echoQuiet "This is the check of pgrep $checkPgrep"
sed 's/ *//' /tmp/evolutionPgrep.pid | sed 's/[^0-9].*//' | cat > /tmp/evolution.pid
if [ $checkPgrep -eq 0 ]; then
running=2
else
pgrep -u $username -f evolution >/tmp/evolutionPgrep.pid
checkPgrep=$?
sed 's/ *//' /tmp/evolutionPgrep.pid | sed 's/[^0-9].*//' | cat > /tmp/evolution.pid
if [ $checkPgrep -eq 0 ]; then
running=1
fi
fi
echoQuiet "evobackup: running=$running"
# shutdown before doing a backup
if [ $running -gt 0 ]; then
evolution --quit
sleep 5
fi
exec < /tmp/evolution.pid
value=0
while read line
do
value=`expr $value + 1`;
echoQuiet "Checking for processes and killing it: $line";
kill -9 $line
done
echoQuiet "Killed the evolution program."
cd $homeDirectory
if [ -d .config/evolution -a -d .local/share/evolution ]; then
echo -e "[dirs]\ndata=.local/share/evolution\nconfig=.config/evolution\n"\
> evolution.dir
[ -f .local/share/evolution/.running ] && \
rm .local/share/evolution/.running
gconftool-2 --dump /apps/evolution > \
.local/share/evolution/backup-restore-gconf.xml
if [ -d $homeDirectory/.camel_certs ]; then
tar -chzf "${2%%.*}"_`date -I`.tar.gz evolution.dir \
.local/share/evolution .config/evolution .camel_certs
else
tar -chzf "${2%%.*}"_`date -I`.tar.gz evolution.dir \
.local/share/evolution .config/evolution
fi
else
echoQuiet "evolution dirs not found. Exiting."
exit 1
fi
echoQuiet "evobackup: tar exit code $?"
rm .local/share/evolution/backup-restore-gconf.xml
#rm -f evolution.dir
# in case we'll running a GUI program from cron,
# we must give it a display
ROOT_UID=0 # Root has $UID 0.
if [ "$UID" -eq "$ROOT_UID" ] # Will the real "root" please stand up?
then
echo "You are root." >/dev/null
else
[ -z $DISPLAY ] && export DISPLAY=:0.0
[ $running -eq 1 ] && /usr/bin/evolution &
[ $running -eq 2 ] && /usr/bin/alltray -- /usr/bin/evolution &
fi
exit
I have tested it from root's crontab, which will allow me to backup all the users evolution automatically. I changed the script to use $homeDirectory instead of HOME and $username instead of USER so I don't conflict with the built in functions.
It seems to work pretty well. Thanks for the help!