#!/bin/bash
# *************************************************************
# $File: twctl $
# $Author: Marko Schulz <info@tuxnet24.de $
# $Date: 2013-04-17 12:44:23 +0200 (Mi, 17 Apr 2013) $
# $Description: Wrapper script to work with tripwire. $
# *************************************************************

tw_bindir="/usr/sbin"
tw_config="/etc/tripwire/tw.cfg"
tw_policy="/etc/tripwire/tw.pol"
tw_sitekey="/etc/tripwire/site.key"
tw_reportdir="/var/lib/tripwire/report"
tw_localkey="/etc/tripwire/$(hostname)-local.key"

# *************************************************************
# MAIN

# Get the program action
action=$1

# Get the raw config & policy file (text/plain)
tw_config_raw=$(echo ${tw_config} | sed 's/\.cfg/cfg\.txt/g')
tw_policy_raw=$(echo ${tw_policy} | sed 's/\.pol/pol\.txt/g')

case "${action}" in
	config)
		# Konfigurieren aktualisieren
		${tw_bindir}/twadmin -m F -c ${tw_config} -S ${tw_sitekey} ${tw_config_raw}
	;;
	policy)
		# Policy aktualisieren
		${tw_bindir}/twadmin -m P -c ${tw_config} -S ${tw_sitekey} ${tw_policy_raw}
	;;
	init)
		# Datenbank erstellen
		${tw_bindir}/tripwire -m i -c ${tw_config} -S ${tw_sitekey} -p ${tw_policy} -L ${tw_localkey}
	;;
	update)
		# Datenbank aktualisieren
		${tw_bindir}/tripwire -m u -r ${tw_reportdir}/$(ls -1rt ${tw_reportdir} | tail -1)
	;;
	check)
		# System PrÃ¼fen und report mail generieren
		${tw_bindir}/tripwire --check --quiet --email-report
	;;
	*)
		echo -e "\aUsage: $0 {config|policy|init|update|check}"; exit 1
	;;
esac

exit $?

# vim: syntax=sh ts=4 sw=4 sts=4 sr noet
# EOF
