[wifi] capture: always delete output directory

Always delete the output directory, even in case of error.
This commit is contained in:
Matteo Cypriani 2011-08-07 20:55:57 +02:00
parent edc7cc4dfd
commit 81611af216
1 changed files with 26 additions and 18 deletions

View File

@ -53,9 +53,16 @@ CHANNEL=1
error()
{
echo "$1"
clean
exit 1
}
# Deletes the temporary files
clean()
{
rm -fr "$DESTDIR"
}
# Verifies the presence of the needed programs
check_dependencies()
{
@ -141,31 +148,31 @@ gather_system_information()
{
echo -n "Gathering system information... "
# Kernel & other information:
uname -a >"$DIR"/uname-a
uname -a >"$DESTDIR"/uname-a
# Wi-Fi interface information:
ifconfig $IFACE >"$DIR"/ifconfig_$IFACE
ifconfig $IFACE >"$DESTDIR"/ifconfig_$IFACE
# PCI devices:
which lspci >/dev/null \
&& lspci >"$DIR"/lspci \
&& lspci >"$DESTDIR"/lspci \
|| echo "lspci not available! Please install pciutils. "
# Loaded kernel modules & USB devices:
case $OS in
Linux)
lsmod >"$DIR"/lsmod
lsmod >"$DESTDIR"/lsmod
which lsusb >/dev/null \
&& lsusb >"$DIR"/lsusb \
&& lsusb >"$DESTDIR"/lsusb \
|| echo "lsusb not available! Please install usbutils. "
;;
NetBSD)
modstat >"$DIR"/modstat
modstat >"$DESTDIR"/modstat
which usbstats >/dev/null \
&& usbstats >"$DIR"/usbstats \
&& usbstats >"$DESTDIR"/usbstats \
|| echo "usbstats not available! Please install usbutil. "
;;
DragonFly)
kldstat >"$DIR"/kldstat
kldstat >"$DESTDIR"/kldstat
which usbstats >/dev/null \
&& usbstats >"$DIR"/usbstats \
&& usbstats >"$DESTDIR"/usbstats \
|| echo "usbstats not available! Please install usbutil. "
;;
esac
@ -175,10 +182,10 @@ gather_system_information()
# Compresses the destination directory to a tarball
create_archive()
{
FILE="${DIR}.tar.gz"
DIR=`basename "$DIR"`
tar -C "$TMP" -czf "$FILE" "$DIR"
echo "Archive \"$FILE\" created."
TARBALL="${DESTDIR}.tar.gz"
DIR=`basename "$DESTDIR"`
tar -C "$TMP" -czf "$TARBALL" "$DIR"
echo "Archive \"$TARBALL\" created."
}
@ -195,6 +202,11 @@ OS_RELEASE=`uname -r`
HOSTNAME=`uname -n`
# Current date:
DATE=`date +%FT%H%M%S`
# Temporary destination directory:
DESTDIR=$(mktemp -d \
"$TMP"/capture_${OS}-${OS_RELEASE}_${IFACE}_${HOSTNAME}_${DATE}_XX)
# Update capture file with full path:
FILE="$DESTDIR/$FILE"
check_dependencies
@ -203,9 +215,6 @@ iface_monitor
iface_up
echo "Trying to capture $NB_PKT packets..."
DIR=$(mktemp -d \
"$TMP"/capture_${OS}-${OS_RELEASE}_${IFACE}_${HOSTNAME}_${DATE}_XX)
FILE="$DIR/$FILE"
CAPTURED=0
while [ $CAPTURED -eq 0 -a $CHANNEL -le 14 ] ; do
iface_set_channel $CHANNEL
@ -223,8 +232,7 @@ done
gather_system_information
create_archive
rm -fr "$TMP/$DIR"
clean
echo
echo "You can now shut down the interface $IFACE if you want:"