source: src/django_gheat/import_scan_data.sh

Last change on this file was 11312, checked in by rick, 12 years ago

Be less verbose to make cron running happy.

  • Property svn:executable set to *
File size: 2.4 KB
RevLine 
[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]7BASEROOT=`cd $(dirname $0); pwd -P`
[10923]8DATAROOT="$BASEROOT/scan-data"
9SSH_USER="backup"
[9564]10MAP_CACHE=${MAP_CACHE:-"/usr/local/var/httpd/cache/maps"}
[9555]11MANAGE="`dirname $0`/manage.py"
12SSH_KEY="`dirname $0`/id_rsa"
13export PYTHON_EGG_CACHE=/tmp/
[9552]14
[10817]15DEBUG=${DEBUG:-"false"}
[10923]16force=false
[9690]17
[10817]18new_imports=false
[9690]19
[10923]20if [ "$1" = "-f" ]; then
21 force=true
22fi
23
[9690]24debug() {
25 $DEBUG && echo $*
26}
27
28debug "# DATAROOT: $DATAROOT"
29debug "# SSH_USER: $SSH_USER"
[9630]30
[10817]31if [ ! -r "$SSH_KEY" ]; then
32 echo "# ERROR: automatic ssh key $SSH_KEY not readable"
33 exit 1
[9630]34fi
[9552]35
[11312]36debug "# Rsync webfolder"
[10817]37changes_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]39if ! $force && [ -z "$changes_files" ]; then
[10817]40 exit 0
41fi
42
[9690]43debug "# unzip compressed .tar.gz files"
[9566]44for 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]50done
51
[9690]52debug "# unzip compressed .zip files"
[9667]53for 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]59done
60
[10817]61do_import() {
62 $MANAGE import_datafile $* 1>/dev/null 2>/dev/null && new_imports=true
63}
64
[9564]65# Import all measure data
[9566]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
[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
92done
93
[10817]94if $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]97fi
[9552]98
Note: See TracBrowser for help on using the repository browser.