source: src/django_gheat/import_scan_data.sh@ 9777

Last change on this file since 9777 was 9777, checked in by rick, 13 years ago

By making directories the data should be more easy to parse..

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/sh
2#
3# Quick and dirty hack to import all data
4
5BASEROOT=`cd $(dirname $0); pwd -P`
6DATAROOT=${1:-"$BASEROOT/scan-data"}
7MAP_CACHE=${MAP_CACHE:-"/usr/local/var/httpd/cache/maps"}
8MANAGE="`dirname $0`/manage.py"
9SSH_KEY="`dirname $0`/id_rsa"
10export PYTHON_EGG_CACHE=/tmp/
11
12DATAROOT_CHOICES="$DATAROOT /usr/local/scan-data"
13
14DEBUG=${DEBUG:-false}
15
16debug() {
17 $DEBUG && echo $*
18}
19
20if [ "$1" ]; then
21 DATAROOT=$1
22else
23 for D in $DATAROOT_CHOICES; do
24 if [ -d $D ]; then
25 DATAROOT=$D
26 fi
27 done
28fi
29debug "# DATAROOT: $DATAROOT"
30debug "# SSH_USER: $SSH_USER"
31
32echo "# rsync webfolder" 1>&2
33if [ -r "$SSH_KEY" ]; then
34 SSH_KEY_OPT="-i $SSH_KEY"
35 SSH_USER=backup
36else
37 echo "# warning automatic ssh key $SSH_KEY not readable"
38 SSH_KEY_OPT=''
39 SSH_USER=${SSH_USER:-${SUDO_USER:-$USER}}
40fi
41rsync -O --out-format="%n%L" -az -e "ssh $SSH_KEY_OPT -l $SSH_USER -o StrictHostKeyChecking=no" tyan.wirelessleiden.nl:/usr/local/www/webfolder/scan-data/ $DATAROOT
42
43debug "# unzip compressed .tar.gz files"
44for FILE in `find $DATAROOT -name '*.tar.gz' | sort`; do
45 TARDIR=`dirname $FILE`/`basename $FILE .tar.gz`
46 if [ ! -d $TARDIR ]; then
47 mkdir $TARDIR
48 tar -C $TARDIR -xvzf $FILE
49 fi
50done
51
52debug "# unzip compressed .zip files"
53for FILE in `find $DATAROOT -name '*.zip' | sort`; do
54 ARCHIVEDIR=`dirname $FILE`/`basename $FILE .zip`
55 if [ ! -d $ARCHIVEDIR ]; then
56 mkdir $ARCHIVEDIR
57 (cd $ARCHIVEDIR; unzip -qn $FILE )
58 fi
59done
60
61#Kismet netxml Imports
62FILES="`find $DATAROOT -name '*netxml*' | sort`"
63[ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
64
65# Import all measure data
66for USERDIR in `find $DATAROOT -mindepth 1 -maxdepth 1 -type d | sort`; do
67 for DEVICEDIR in `find $USERDIR -mindepth 1 -maxdepth 1 -type d | sort`; do
68 USERNAME=`basename $USERDIR`
69 DEVICE=`basename $DEVICEDIR`
70 ARGS="-g $USERNAME -e $USERNAME@wirelessleiden.nl -k $DEVICE"
71
72 # DroidStumber imports
73 FILES=`find $DEVICEDIR -name 'ScanResult-*'`
74 [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
75
76 #Kismet gpsxml Imports
77 FILES="`find $DEVICEDIR -name '*gpsxml*'`"
78 [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
79
80 # Kismet imports
81 FILES=`find $DEVICEDIR -name '*.ns1'`
82 [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
83 done
84done
85
86if [ -r $MAP_CACHE ]; then
87 debug "# Clear cache $MAP_CACHE"
88 htcacheclean -v -l10K -p$MAP_CACHE
89fi
90
Note: See TracBrowser for help on using the repository browser.