#!/bin/bash # $HeadURL: https://svn.pasta.freemyip.com/main/miniade/trunk/bin/nop-sh $ $LastChangedRevision: 10133 $ # Modules . $(miniade) || { echo "${0##*/}: ERROR: miniade failed (hint: run 'miniade' to see error)" >&2; exit 1; } # Configurable stuff # Other globals BIN_DIR=$(dirname $0) main() { local MY_ARGS # Process options miniade_process_options --help-handler=help MY_ARGS "$@" && set -- "${MY_ARGS[@]}" # Process arguments [ $# = 0 ] || miniade_bad_usage # Sanity checks and derivations # Wait till 00:00 GMT #echo "$(date): going to sleep ..." #sleeptill 0100 # Pre-cache downloads. This would be done as part of osm-to-garmin-batch but # osm-to-garmin-batch will use an existing download if already cached. We # pre-cache to ensure that the main job gets right down to computation rather # and downloading. echo "$(date): downloading ..." miniade_evaler "rm -fr ~/download-cache-dir" miniade_evaler "mkdir ~/download-cache-dir" URLS=$(sed -r -n -e 's/.*:(http:\/\/[^:]*):.*/\1/p' -e 's/^[A-Z_]*=(https?:\/\/.*)/\1/p' $BIN_DIR/osm-to-garmin-batch) for URL in $URLS; do miniade_evaler "wget -qP ~/download-cache-dir $URL &" done miniade_evaler "wait" # Submit batch jobs echo "$(date): submitting batch jobs ..." miniade_evaler "$BIN_DIR/osm-to-garmin-batch" } sleeptill() { NOW_TIMESTAMP=$(date +%s) WAKEUP_TIMESTAMP=$(date -d ${1/:/} +%s) if ((WAKEUP_TIMESTAMP < NOW_TIMESTAMP)); then ((WAKEUP_TIMESTAMP+=24*3600)) fi miniade_evaler "sleep $((WAKEUP_TIMESTAMP-NOW_TIMESTAMP))" } main "$@"