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