[9552] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # Quick and dirty hack to import all data
|
---|
[10817] | 4 | #
|
---|
| 5 | # Rick van der Zwet <rick@wirelessleiden.nl>
|
---|
[9552] | 6 |
|
---|
[9670] | 7 | BASEROOT=`cd $(dirname $0); pwd -P`
|
---|
[10923] | 8 | DATAROOT="$BASEROOT/scan-data"
|
---|
| 9 | SSH_USER="backup"
|
---|
[9564] | 10 | MAP_CACHE=${MAP_CACHE:-"/usr/local/var/httpd/cache/maps"}
|
---|
[9555] | 11 | MANAGE="`dirname $0`/manage.py"
|
---|
| 12 | SSH_KEY="`dirname $0`/id_rsa"
|
---|
| 13 | export PYTHON_EGG_CACHE=/tmp/
|
---|
[9552] | 14 |
|
---|
[10817] | 15 | DEBUG=${DEBUG:-"false"}
|
---|
[10923] | 16 | force=false
|
---|
[9690] | 17 |
|
---|
[10817] | 18 | new_imports=false
|
---|
[9690] | 19 |
|
---|
[10923] | 20 | if [ "$1" = "-f" ]; then
|
---|
| 21 | force=true
|
---|
| 22 | fi
|
---|
| 23 |
|
---|
[9690] | 24 | debug() {
|
---|
| 25 | $DEBUG && echo $*
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | debug "# DATAROOT: $DATAROOT"
|
---|
| 29 | debug "# SSH_USER: $SSH_USER"
|
---|
[9630] | 30 |
|
---|
[10817] | 31 | if [ ! -r "$SSH_KEY" ]; then
|
---|
| 32 | echo "# ERROR: automatic ssh key $SSH_KEY not readable"
|
---|
| 33 | exit 1
|
---|
[9630] | 34 | fi
|
---|
[9552] | 35 |
|
---|
[11312] | 36 | debug "# Rsync webfolder"
|
---|
[10817] | 37 | changes_files=`rsync -O --out-format="%n%L" -az -e "ssh -i $SSH_KEY -l $SSH_USER -o StrictHostKeyChecking=no" tyan.wirelessleiden.nl:/usr/local/www/webfolder/scan-data/ $DATAROOT`
|
---|
| 38 |
|
---|
[10923] | 39 | if ! $force && [ -z "$changes_files" ]; then
|
---|
[10817] | 40 | exit 0
|
---|
| 41 | fi
|
---|
| 42 |
|
---|
[9690] | 43 | debug "# unzip compressed .tar.gz files"
|
---|
[9566] | 44 | for FILE in `find $DATAROOT -name '*.tar.gz' | sort`; do
|
---|
[9777] | 45 | TARDIR=`dirname $FILE`/`basename $FILE .tar.gz`
|
---|
| 46 | if [ ! -d $TARDIR ]; then
|
---|
| 47 | mkdir $TARDIR
|
---|
| 48 | tar -C $TARDIR -xvzf $FILE
|
---|
| 49 | fi
|
---|
[9552] | 50 | done
|
---|
| 51 |
|
---|
[9690] | 52 | debug "# unzip compressed .zip files"
|
---|
[9667] | 53 | for FILE in `find $DATAROOT -name '*.zip' | sort`; do
|
---|
[9777] | 54 | ARCHIVEDIR=`dirname $FILE`/`basename $FILE .zip`
|
---|
| 55 | if [ ! -d $ARCHIVEDIR ]; then
|
---|
| 56 | mkdir $ARCHIVEDIR
|
---|
| 57 | (cd $ARCHIVEDIR; unzip -qn $FILE )
|
---|
| 58 | fi
|
---|
[9667] | 59 | done
|
---|
| 60 |
|
---|
[10817] | 61 | do_import() {
|
---|
| 62 | $MANAGE import_datafile $* 1>/dev/null 2>/dev/null && new_imports=true
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[9564] | 65 | # Import all measure data
|
---|
[9566] | 66 | for 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
|
---|
[9552] | 68 | USERNAME=`basename $USERDIR`
|
---|
| 69 | DEVICE=`basename $DEVICEDIR`
|
---|
[10817] | 70 | ARGS="-b -g $USERNAME -e $USERNAME@wirelessleiden.nl -k $DEVICE"
|
---|
[9564] | 71 |
|
---|
[9823] | 72 | echo "# INFO: Processing $USERNAME/$DEVICE"
|
---|
[9777] | 73 | # DroidStumber imports
|
---|
| 74 | FILES=`find $DEVICEDIR -name 'ScanResult-*'`
|
---|
[9823] | 75 | if [ -n "$FILES" ]; then
|
---|
[10817] | 76 | do_import $ARGS $FILES
|
---|
[9823] | 77 | fi
|
---|
[9777] | 78 |
|
---|
[9823] | 79 | #Kismet Imports
|
---|
[9566] | 80 | FILES="`find $DEVICEDIR -name '*gpsxml*'`"
|
---|
[9823] | 81 | for GPSXML in $FILES; do
|
---|
| 82 | NETXML=`echo $GPSXML | sed 's/gpsxml/netxml/g' `
|
---|
[10817] | 83 | do_import $ARGS $NETXML $GPSXML
|
---|
[9823] | 84 | done
|
---|
[9564] | 85 |
|
---|
[9823] | 86 | # NetStumbler imports
|
---|
[9623] | 87 | FILES=`find $DEVICEDIR -name '*.ns1'`
|
---|
[9823] | 88 | if [ -n "$FILES" ]; then
|
---|
[10817] | 89 | do_import $ARGS $FILES
|
---|
[9823] | 90 | fi
|
---|
[9552] | 91 | done
|
---|
| 92 | done
|
---|
| 93 |
|
---|
[10817] | 94 | if $new_imports && [ -r $MAP_CACHE ]; then
|
---|
| 95 | echo "# INFO: New imports, clearing cache of $MAP_CACHE"
|
---|
[9569] | 96 | htcacheclean -v -l10K -p$MAP_CACHE
|
---|
[9555] | 97 | fi
|
---|
[9552] | 98 |
|
---|