[9552] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # Quick and dirty hack to import all data
|
---|
| 4 |
|
---|
[9670] | 5 | BASEROOT=`cd $(dirname $0); pwd -P`
|
---|
[9665] | 6 | DATAROOT=${1:-"$BASEROOT/scan-data"}
|
---|
[9564] | 7 | MAP_CACHE=${MAP_CACHE:-"/usr/local/var/httpd/cache/maps"}
|
---|
[9555] | 8 | MANAGE="`dirname $0`/manage.py"
|
---|
| 9 | SSH_KEY="`dirname $0`/id_rsa"
|
---|
| 10 | export PYTHON_EGG_CACHE=/tmp/
|
---|
[9552] | 11 |
|
---|
[9665] | 12 | DATAROOT_CHOICES="$DATAROOT /usr/local/scan-data"
|
---|
[9690] | 13 |
|
---|
| 14 | DEBUG=${DEBUG:-false}
|
---|
| 15 |
|
---|
| 16 | debug() {
|
---|
| 17 | $DEBUG && echo $*
|
---|
| 18 | }
|
---|
| 19 |
|
---|
[9630] | 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
|
---|
[9690] | 29 | debug "# DATAROOT: $DATAROOT"
|
---|
| 30 | debug "# SSH_USER: $SSH_USER"
|
---|
[9630] | 31 |
|
---|
[9690] | 32 | echo "# rsync webfolder" 1>&2
|
---|
[9630] | 33 | if [ -r "$SSH_KEY" ]; then
|
---|
[9672] | 34 | SSH_KEY_OPT="-i $SSH_KEY"
|
---|
| 35 | SSH_USER=backup
|
---|
[9630] | 36 | else
|
---|
| 37 | echo "# warning automatic ssh key $SSH_KEY not readable"
|
---|
| 38 | SSH_KEY_OPT=''
|
---|
[9777] | 39 | SSH_USER=${SSH_USER:-${SUDO_USER:-$USER}}
|
---|
[9630] | 40 | fi
|
---|
[9690] | 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
|
---|
[9552] | 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 |
|
---|
[9564] | 61 | #Kismet netxml Imports
|
---|
[9566] | 62 | FILES="`find $DATAROOT -name '*netxml*' | sort`"
|
---|
[9630] | 63 | [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
|
---|
[9564] | 64 |
|
---|
| 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`
|
---|
| 70 | ARGS="-g $USERNAME -e $USERNAME@wirelessleiden.nl -k $DEVICE"
|
---|
[9564] | 71 |
|
---|
[9777] | 72 | # DroidStumber imports
|
---|
| 73 | FILES=`find $DEVICEDIR -name 'ScanResult-*'`
|
---|
| 74 | [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
|
---|
| 75 |
|
---|
[9564] | 76 | #Kismet gpsxml Imports
|
---|
[9566] | 77 | FILES="`find $DEVICEDIR -name '*gpsxml*'`"
|
---|
[9623] | 78 | [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
|
---|
[9564] | 79 |
|
---|
[9623] | 80 | # Kismet imports
|
---|
| 81 | FILES=`find $DEVICEDIR -name '*.ns1'`
|
---|
| 82 | [ -n "$FILES" ] && $MANAGE import_datafile $ARGS $FILES
|
---|
[9552] | 83 | done
|
---|
| 84 | done
|
---|
| 85 |
|
---|
[9569] | 86 | if [ -r $MAP_CACHE ]; then
|
---|
[9690] | 87 | debug "# Clear cache $MAP_CACHE"
|
---|
[9569] | 88 | htcacheclean -v -l10K -p$MAP_CACHE
|
---|
[9555] | 89 | fi
|
---|
[9552] | 90 |
|
---|