Deleted TEMPDIR on exit

To avoid undeleted tmp.XXXXXXXXX directories left in /tmp, and output
unified style patch for later apply.

Change-Id: I6069c3cf36e345e5101ae3cf884e647c1d42030e
This commit is contained in:
JUN JIE NAN 2013-12-31 14:33:37 +08:00
parent 0df3bc702b
commit e542742e1d
1 changed files with 11 additions and 5 deletions

View File

@ -1,9 +1,15 @@
#!/bin/sh
#!/bin/bash
TEMPDIR=`mktemp -d /tmp/tmp.XXXXXXXXXX`
trap "rm -rf $TEMPDIR" EXIT
CFGFILE=heat.conf.sample
tools/config/generate_sample.sh -b ./ -p heat -o $TEMPDIR
if ! diff $TEMPDIR/$CFGFILE etc/heat/$CFGFILE
then
echo "E: heat.conf.sample is not up to date, please run tools/config/generate_sample.sh"
GENERATOR=tools/config/generate_sample.sh
mkdir -p $TEMPDIR/{a,b}/etc/heat
cp etc/heat/$CFGFILE $TEMPDIR/a/etc/heat
$GENERATOR -b ./ -p heat -o $TEMPDIR/b/etc/heat &> /dev/null
if [ ! -f "$TEMPDIR/b/etc/heat/$CFGFILE" ]; then
echo "Error: $CFGFILE can not be generated by $GENERATOR." 1>&2
exit 2
elif ! (cd $TEMPDIR; diff -Naur a b); then
echo "Error: $CFGFILE is not up to date, please run $GENERATOR." 1>&2
exit 42
fi