Source

vasm / setup_logging.sh

Full commit
#!/bin/sh
logFile="/var/log/vasm.log";

in_use() {
	local property;
	property=$1;
	usingProperty=$( grep -I $property /etc/syslog.conf | sed "s/#.*$//" | sed '/^$/d' | wc -l );
	if [ "$usingProperty" -gt "0" ]; then
		# This property is in use.
		echo true;
	fi;
}

syslog_payload() {
	local facility;
	local payload;
	facility=$1;
	cat <<EOF

# Vasm centralized logging to facility $facility.
$facility.*					-$logFile
EOF
}
	

usingVasm=$( in_use "$logFile" );
if [ $usingVasm ]; then
	# Vasm logging already setup
	echo "Logging already configured for $logFile."
	echo "Doing nothing.";
	exit 0;
else
	echo "Logging not configured for $logFile.";
	echo "Configuring in /etc/syslog.conf.";
	usingLocal0=$( in_use "local0" );
	if [ $usingLocal0 ]; then
		# Something else is using 'local0'
		echo "Logging facility 'local0' already in use."
		echo "Checking for 'local1' now.";
		usingLocal1=$( in_use "local1" );
		if [ $usingLocal1 ]; then
			# Something else is using 'local1';
			echo "Logging facility 'local1' already in use.";
			echo "Aborting configuration of /etc/syslog.conf.";
			echo "Please configure manually for vasm logging.";
		else
			# We can use 'local1'.
			facility="local1";
		fi;
	else
		# We can use 'local0'.
		facility="local0";
	fi;
	
	# Write our conf lines to syslog config file.
	syslog_payload $facility >> /etc/syslog.conf;
	echo "Configured with facility=$facility logfile=$logFile.";
fi;