#!/bin/sh
#
# 2008-01-10 Munetoh Do not use UUID fo SYSTEM_PS data_name 
# 2008-01-12 Munetoh Cleanup

PS_FILE_DIR=/etc/tpm
DUMMY_PS_FILE=/opt/OpenPlatformTrustServices/tcdemo/dummy_system.data

echo "Restard TCSD with stored PS file for KNOPPIX running on multiple PC platforms"

# Check existing PS file 

#PS_FILE=$PS_FILE_DIR/$UUID.data
PS_FILE=$PS_FILE_DIR/system.data
echo " PS File : $PS_FILE"

if [ ! -d $PS_FILE_DIR ]; then
	mkdir -p $PS_FILE_DIR
fi

if [ -f $PS_FILE ]; then
	if [ ! -s $PS_FILE ]; then
		echo "$PS_FILE size is 0 (empty). replace with dummy PS file."
		/bin/cp $DUMMY_PS_FILE $PS_FILE		
	fi	
else
	echo "$PS_FILE is missing. put dummy PS file there."
	/bin/cp $DUMMY_PS_FILE $PS_FILE
fi

# Update TCSD conf

echo "update tcsd.conf"
mkdir -p /etc/tpm
echo "system_ps_file = $PS_FILE" > /etc/tcsd.conf
if [ -f /sys/kernel/security/tpm0/binary_bios_measurements ]; then
  echo "BIOS IML is available"
  echo "firmware_log_file = /sys/kernel/security/tpm0/binary_bios_measurements" >> /etc/tcsd.conf
  echo "firmware_pcrs = 0,1,2,3,4,5,6,7,8" >> /etc/tcsd.conf
fi
if [ -f /sys/kernel/security/ima/binary_runtime_measurements ]; then
  echo "Kernel(Linux-IMA) IML is available"
  echo "kernel_log_file = /sys/kernel/security/ima/binary_runtime_measurements" >> /etc/tcsd.conf
  echo "kernel_pcrs = 10" >> /etc/tcsd.conf
fi
#cat /etc/tcsd.conf

# restart TCSD
echo "restart tcsd"
killall tcsd
/usr/sbin/tcsd

# Status

ps aux | grep tcsd | grep sbin
ls -l $PS_FILE

echo "done?"