66 lines
1.2 KiB
Bash
Executable File
66 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# $NetBSD: script,v 1.2 2004/03/09 21:36:37 garbled Exp $
|
|
|
|
BACKUPDIR="/var/sushi"
|
|
CONFFILE="/etc/daily.conf"
|
|
BACKUP="${BACKUPDIR}/daily.conf"
|
|
|
|
echo "Saving changes..."
|
|
|
|
if [ ! -d $BACKUPDIR ]; then
|
|
mkdir $BACKUPDIR
|
|
chown root:wheel $BACKUPDIR
|
|
chmod 700 $BACKUPDIR
|
|
fi
|
|
|
|
# backup
|
|
cp -p $CONFFILE $BACKUP
|
|
|
|
# temporary files
|
|
cp -p $BACKUP $BACKUP.new
|
|
cp -p $BACKUP $BACKUP.old
|
|
|
|
. /etc/defaults/daily.conf
|
|
. $CONFFILE
|
|
|
|
a=1
|
|
for i in `/usr/share/sushi/system/dailyconf/script3`
|
|
do
|
|
new=$(echo `eval echo \\$${a}` | sed -e 's/ $//')
|
|
old=`eval echo \\$${i}`
|
|
if [ "$new" != "$old" ]; then
|
|
line=`grep -n $i $BACKUP | cut -f1 -d:`
|
|
# if no line, add new entry, otherwise edit the entry.
|
|
if [ -z $line ]; then
|
|
if [ "$new" = "YES" -o "$new" = "NO" ]; then
|
|
echo "$i=$new" >> $BACKUP.new
|
|
else
|
|
echo "$i=\"$new\"" >> $BACKUP.new
|
|
fi
|
|
else
|
|
sed "${line}s/$old/$new/" < $BACKUP.old > $BACKUP.new
|
|
if [ $? -ne 0 ]; then
|
|
echo "sed failed"
|
|
rm -f $BACKUP.new $BACKUP.old
|
|
exit 1
|
|
fi
|
|
fi
|
|
cp -p $BACKUP.new $BACKUP.old
|
|
fi
|
|
a=`expr $a + 1`
|
|
done
|
|
|
|
cp -p $BACKUP.new $CONFFILE
|
|
|
|
if [ $? -eq 0 ]; then
|
|
echo "Successfully wrote a new $CONFFILE"
|
|
echo ""
|
|
cat $CONFFILE
|
|
else
|
|
echo "Failed"
|
|
fi
|
|
|
|
rm -f $BACKUP.new $BACKUP.old
|
|
|
|
exit 0
|