source: src/django_gheat/import_scan_data.sh@ 10615

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

Importer fails if one file files, this makes it more reliable...

  • 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# Import all measure data
62for USERDIR in `find $DATAROOT -mindepth 1 -maxdepth 1 -type d | sort`; do
63 for DEVICEDIR in `find $USERDIR -mindepth 1 -maxdepth 1 -type d | sort`; do
64 USERNAME=`basename $USERDIR`
65 DEVICE=`basename $DEVICEDIR`
66 ARGS="-g $USERNAME -e $USERNAME@wirelessleiden.nl -k $DEVICE"
67
68 echo "# INFO: Processing $USERNAME/$DEVICE"
69 # DroidStumber imports
70 FILES=`find $DEVICEDIR -name 'ScanResult-*'`
71 if [ -n "$FILES" ]; then
72 $MANAGE import_datafile $ARGS $FILES
73 fi
74
75 #Kismet Imports
76 FILES="`find $DEVICEDIR -name '*gpsxml*'`"
77 for GPSXML in $FILES; do
78 NETXML=`echo $GPSXML | sed 's/gpsxml/netxml/g' `
79 $MANAGE import_datafile $ARGS $NETXML $GPSXML
80 done
81
82 # NetStumbler imports
83 FILES=`find $DEVICEDIR -name '*.ns1'`
84 if [ -n "$FILES" ]; then
85 $MANAGE import_datafile $ARGS $FILES
86 fi
87 done
88done
89
90if [ -r $MAP_CACHE ]; then
91 debug "# Clear cache $MAP_CACHE"
92 htcacheclean -v -l10K -p$MAP_CACHE
93fi
94
Note: See TracBrowser for help on using the repository browser.