Ignore:
Timestamp:
May 13, 2012, 11:12:05 AM (13 years ago)
Author:
rick
Message:

Only run the heavy lifting is we actually do have new files.

While here remove the lets-fix-all-use-cases-in-one-script-and-make-it-unreadable. stuff.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/import_scan_data.sh

    r9823 r10817  
    22#
    33# Quick and dirty hack to import all data
     4#
     5# Rick van der Zwet <rick@wirelessleiden.nl>
    46
    57BASEROOT=`cd $(dirname $0); pwd -P`
    68DATAROOT=${1:-"$BASEROOT/scan-data"}
     9SSH_USER=${2:-"backup"}
    710MAP_CACHE=${MAP_CACHE:-"/usr/local/var/httpd/cache/maps"}
    811MANAGE="`dirname $0`/manage.py"
     
    1013export PYTHON_EGG_CACHE=/tmp/
    1114
    12 DATAROOT_CHOICES="$DATAROOT /usr/local/scan-data"
     15DEBUG=${DEBUG:-"false"}
    1316
    14 DEBUG=${DEBUG:-false}
     17new_imports=false
    1518
    1619debug() {
     
    1821}
    1922
    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
    2923debug "# DATAROOT: $DATAROOT"
    3024debug "# SSH_USER: $SSH_USER"
    3125
    3226echo "# 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}}
     27if [ ! -r "$SSH_KEY" ]; then
     28  echo "# ERROR: automatic ssh key $SSH_KEY not readable"
     29  exit 1
    4030fi
    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
     31
     32changes_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`
     33
     34if [ -z "$changes_files" ]; then
     35  exit 0
     36fi
    4237
    4338debug "# unzip compressed .tar.gz files"
     
    5954done
    6055
     56do_import() {
     57  $MANAGE import_datafile $* 1>/dev/null 2>/dev/null && new_imports=true
     58}
     59
    6160# Import all measure data
    6261for USERDIR in `find $DATAROOT -mindepth 1 -maxdepth 1 -type d | sort`; do
     
    6463    USERNAME=`basename $USERDIR`
    6564    DEVICE=`basename $DEVICEDIR`
    66     ARGS="-g $USERNAME -e $USERNAME@wirelessleiden.nl -k $DEVICE"
     65    ARGS="-b -g $USERNAME -e $USERNAME@wirelessleiden.nl -k $DEVICE"
    6766
    6867    echo "# INFO: Processing $USERNAME/$DEVICE"
     
    7069    FILES=`find $DEVICEDIR -name 'ScanResult-*'`
    7170    if [ -n "$FILES" ]; then
    72       $MANAGE import_datafile $ARGS $FILES
     71      do_import $ARGS $FILES
    7372    fi
    7473
     
    7776    for GPSXML in $FILES; do
    7877      NETXML=`echo $GPSXML | sed 's/gpsxml/netxml/g' `
    79       $MANAGE import_datafile $ARGS $NETXML $GPSXML
     78      do_import $ARGS $NETXML $GPSXML
    8079    done
    8180
     
    8382    FILES=`find $DEVICEDIR -name '*.ns1'`
    8483    if [ -n "$FILES" ]; then
    85       $MANAGE import_datafile $ARGS $FILES
     84      do_import $ARGS $FILES
    8685    fi
    8786  done
    8887done
    8988
    90 if [ -r $MAP_CACHE ]; then
    91   debug "# Clear cache $MAP_CACHE"
     89if $new_imports && [ -r $MAP_CACHE ]; then
     90  echo "# INFO: New imports, clearing cache of $MAP_CACHE"
    9291  htcacheclean -v -l10K -p$MAP_CACHE
    9392fi
Note: See TracChangeset for help on using the changeset viewer.