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


1.3
date	2005.01.18.18.12.55;	author peter;	state Exp;
branches;
next	1.2;

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

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


desc
@@


1.3
log
@Minor cleanup and tweaks, be consistent with the other system admin scripts.
@
text
@#!/bin/sh
# $NetBSD: script,v 1.2 2004/03/09 21:36:37 garbled Exp $

BACKUPDIR="/var/sushi"
CONFFILE="/etc/security.conf"
BACKUP="${BACKUPDIR}/security.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/security.conf
. $CONFFILE

a=1
for i in `/usr/share/sushi/system/securityconf/script3`
do
	new=$(echo `eval echo \\$${a}` | sed -e 's/ $//' | sed -e 's/^0*//')
	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.2
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 1
a2 1
# $NetBSD: script,v 1.1 2001/03/06 21:24:13 garbled Exp $
d16 1
a16 1
# backup
d18 4
d37 2
a38 2
		# if no line, add new entry, otherwise edit the entry.
		if [ -z $line ]; then
d64 1
a64 1
	echo "Failed"
@


1.1
log
@Add a menu entry to sushi to deal with editing the /etc/security.conf file.
@
text
@d2 21
a22 1
# $NetBSD: script,v 1.1 2001/01/05 02:06:59 garbled Exp $
d24 2
a25 7
pwd
CONFFILE="/etc/security.conf"
echo -n "#Generated by sushi on " >$CONFFILE
date >>$CONFFILE
echo "if [ -r /etc/defaults/security.conf ]; then" >>$CONFFILE
echo "	. /etc/defaults/security.conf" >>$CONFFILE
echo "fi" >>$CONFFILE
a26 2
IFS="
"
d29 11
a39 4
	ANS=$(echo `eval echo \\$${a}` | sed -e 's/ $//' | sed -e 's/^0*//')
	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
@

