#!/bin/sh
# Restore hacked scripts in /etc.  For all files of the form xyz.orig20H
# which differ from plain xyz, the orig20H version will be copied back.
# Recommended to have xyz.jimc so hacks are not permanently lost.
# This happens if /root/selfheal.log exists and has over 3 lines.

# Copyright (c) 2006 by James F. Carter (jimc@math.ucla.edu>
# 2006-08-27, for Maemo-2.0 (Nokia 770)

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You can find the GNU General Public License in your Maemo distribution
# as /usr/share/common-licenses/GPL-2; if it's missing, write to the 
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA 02111-1307, USA.

case "$1" in
    start )
	fil=/var/log/selfheal.log
	if [ -r $fil ] ; then
	    date >> $fil
	    if [ `wc -l < $fil` -le 3 ] ; then exit 0 ; fi
	else
	    exit 0
	fi
	exten=orig20H
	fixme=`find /etc -type f -name "*.$exten" -print`
	for f in $fixme ; do
	    g=${f%.$exten}
	    if cmp $f $g ; then : ; else
		echo "Restoring $g"
		cp -p $f $g
	    fi
	done
	;;
    stop )
	:	# Does nothing
	;;
    * )
	echo "Unrecognized action arg '$1'"
	exit 4
	;;
esac

