1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Quick and dirty hack to import all data
|
---|
4 |
|
---|
5 | BASEROOT=`cd $(dirname $0); pwd -P`
|
---|
6 | DATAROOT=${1:-"$BASEROOT/scan-data"}
|
---|
7 | MAP_CACHE=${MAP_CACHE:-"/usr/local/var/httpd/cache/maps"}
|
---|
8 | MANAGE="`dirname $0`/manage.py"
|
---|
9 | SSH_KEY="`dirname $0`/id_rsa"
|
---|
10 | export PYTHON_EGG_CACHE=/tmp/
|
---|
11 |
|
---|
12 | DATAROOT_CHOICES="$DATAROOT /usr/local/scan-data"
|
---|
13 |
|
---|
14 | DEBUG=${DEBUG:-false}
|
---|
15 |
|
---|
16 | debug() {
|
---|
17 | $DEBUG && echo $*
|
---|
18 | }
|
---|
19 |
|
---|
20 | if [ "$1" ]; then
|
---|
21 | DATAROOT=$1
|
---|
22 | else
|
---|
23 | for D in $DATAROOT_CHOICES; do
|
---|
24 | if [ -d $D ]; then
|
---|
25 | DATAROOT=$D
|
---|
26 | fi
|
---|
27 | done
|
---|
28 | fi
|
---|
29 | debug "# DATAROOT: $DATAROOT"
|
---|
30 | debug "# SSH_USER: $SSH_USER"
|
---|
31 |
|
---|
32 | echo "# rsync webfolder" 1>&2
|
---|
33 | if [ -r "$SSH_KEY" ]; then
|
---|
34 | SSH_KEY_OPT="-i $SSH_KEY"
|
---|
35 | SSH_USER=backup
|
---|
36 | else
|
---|
37 | echo "# warning automatic ssh key $SSH_KEY not readable"
|
---|
38 | SSH_KEY_OPT=''
|
---|
39 | SSH_USER=${SSH_USER:-${SUDO_USER:-$USER}}
|
---|
40 | fi
|
---|
41 | rsync -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 |
|
---|
43 | debug "# unzip compressed .tar.gz files"
|
---|
44 | for 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
|
---|
50 | done
|
---|
51 |
|
---|
52 | debug "# unzip compressed .zip files"
|
---|
53 | for 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
|
---|
59 | done
|
---|
60 |
|
---|
61 | # Import all measure data
|
---|
62 | for 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
|
---|
88 | done
|
---|
89 |
|
---|
90 | if [ -r $MAP_CACHE ]; then
|
---|
91 | debug "# Clear cache $MAP_CACHE"
|
---|
92 | htcacheclean -v -l10K -p$MAP_CACHE
|
---|
93 | fi
|
---|
94 |
|
---|