head	1.5;
access;
symbols;
locks; strict;
comment	@# @;


1.5
date	2005.01.18.18.12.55;	author peter;	state Exp;
branches;
next	1.4;

1.4
date	2005.01.11.22.16.24;	author peter;	state Exp;
branches;
next	1.3;

1.3
date	2004.03.09.21.36.37;	author garbled;	state Exp;
branches;
next	1.2;

1.2
date	2001.01.06.07.31.03;	author garbled;	state Exp;
branches;
next	1.1;

1.1
date	2001.01.05.02.06.59;	author garbled;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Minor cleanup and tweaks, be consistent with the other system admin scripts.
@
text
@#!/bin/sh
# $NetBSD: script,v 1.4 2005/01/11 22:16:24 peter Exp $

BIGLIST=`grep -v ^# /usr/share/sushi/system/rcconf/form | \
    awk '{print $1}' | sed -e 's/.*\,\(.*\)/\1/'`

BACKUPDIR="/var/sushi"
CONFFILE="/etc/rc.conf"
BACKUP="${BACKUPDIR}/rc.conf"

echo "Saving changes..."

if [ ! -d $BACKUPDIR ]; then
	mkdir $BACKUPDIR
	chown root:wheel $BACKUPDIR
	chmod 700 $BACKUPDIR
fi

# create a backup
cp -p $CONFFILE $BACKUP
if [ $? -ne 0 ]; then
	echo "Can't create a backup"
	exit 1
fi

# temporary files
cp -p $BACKUP $BACKUP.new
cp -p $BACKUP $BACKUP.old

. /etc/defaults/rc.conf
. $CONFFILE

a=1
for i in $BIGLIST
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 such line, add a 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 to write a new $CONFFILE"
fi

rm -f $BACKUP.new $BACKUP.old

exit 0
@


1.4
log
@Only try to change/update the settings listed in the form.
This stops sushi from mangling rc.conf when the form becomes out-of-sync
with /etc/defaults/rc.conf.

Reviewed by garbled.
@
text
@d2 1
a2 1
# $NetBSD: script,v 1.3 2004/03/09 21:36:37 garbled Exp $
d67 1
a67 1
	echo "Failed"
@


1.3
log
@Apply patches in PR bin/24645 by Peter Postma:
	Here are some enhancements to sushi's System Maintenance menu.
	To summarize the changes:

	* Make a backup of the file before modifying it.
	* Fixes to get all menus/forms working.
	* Missing/invalid settings (like in rc.conf and inetd.conf)
	  have been added/removed.
	* Most files don't get overwritten now but are edited instead.
	  So specials settings in e.g. /etc/rc.conf don't get lost now.
	* Some help menu fixes. ($NetBSD$ tag has been removed because I
	  don't see how it would be useful for either user or developer).
@
text
@d2 4
a5 1
# $NetBSD: script,v 1.2 2001/01/06 07:31:03 garbled Exp $
d19 1
a19 1
# backup
d21 4
d34 1
a34 1
for i in `/usr/share/sushi/system/rcconf/script3`
d39 3
a41 3
		line=`grep -n $i $BACKUP | cut -f1 -d:`
		# if no line, add new entry, otherwise edit the entry.
		if [ -z $line ]; then
d64 1
a64 1
	echo ""
@


1.2
log
@Fix some stupidity in here.  There seem to be some definate problems with
this script, that didn't exist before..  It's going to take some doing to
figure them out..
@
text
@d2 21
a22 1
# $NetBSD: script,v 1.1 2001/01/05 02:06:59 garbled Exp $
d24 2
a25 7
CONFFILE="/etc/rc.conf"
echo -n "#Generated by sushi on " >$CONFFILE
date >>$CONFFILE
echo "if [ -r /etc/defaults/rc.conf ]; then" >>$CONFFILE
echo "	. /etc/defaults/rc.conf" >>$CONFFILE
echo "fi" >>$CONFFILE
echo "rc_configured=YES" >>$CONFFILE
a26 2
IFS="
"
d29 11
a39 4
	ANS=$(echo `eval echo \\$${a}` | sed -e 's/ $//')
	if [ "$ANS" != "`eval echo \\$${i}`" ]; then
		if [ "$ANS" = "YES" -o "$ANS" = "NO" ]; then
			echo "$i=$ANS" >>$CONFFILE
d41 6
a46 1
			echo "$i=\"$ANS\"" >>$CONFFILE
d48 1
d52 14
a65 2
echo "successfully wrote a new $CONFFILE"
cat $CONFFILE
@


1.1
log
@Add all the help menus, and working menu items I currently have for sushi.

Note, these directories are missing Makefiles..  I know that.. and I'm
working on it.
@
text
@d2 2
a3 2
# $NetBSD$
. /etc/default/rc.conf
d5 1
a5 1
echo -n "#Generated by smit on " >$CONFFILE
d7 2
a8 2
echo "if [ -r /etc/default/rc.conf ]; then" >>$CONFFILE
echo "	. /etc/default/rc.conf" >>$CONFFILE
d14 1
a14 1
for i in `smitty/system/rcconf/script3`
@

