|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2008, 2009, 2010, 2011, 2012 Roland Olbricht |
| 4 | +# |
| 5 | +# This file is part of Overpass_API. |
| 6 | +# |
| 7 | +# Overpass_API is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Affero General Public License as |
| 9 | +# published by the Free Software Foundation, either version 3 of the |
| 10 | +# License, or (at your option) any later version. |
| 11 | +# |
| 12 | +# Overpass_API is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Affero General Public License |
| 18 | +# along with Overpass_API. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +BUF="$QUERY_STRING&" |
| 21 | + |
| 22 | +STATE= |
| 23 | +EXECBASE="`dirname $0`/../" |
| 24 | +BIN_DIR="${EXECBASE}bin" |
| 25 | + |
| 26 | +IFS=$'&' |
| 27 | +for KEY_VAL in $QUERY_STRING; do |
| 28 | +{ |
| 29 | + if [[ ${KEY_VAL:0:9} == "osm_base=" ]]; then |
| 30 | + STATE="${KEY_VAL:9}" |
| 31 | + fi |
| 32 | +}; done |
| 33 | +unset IFS |
| 34 | + |
| 35 | + |
| 36 | +TARGET_TIME="`echo "$STATE" | $BIN_DIR/uncgi`" |
| 37 | +LOWER="0" |
| 38 | +UPPER="`cat /var/www/augmented_diffs/state.txt`" |
| 39 | +LOCAL_DIR="/var/www/augmented_diffs/" |
| 40 | + |
| 41 | +get_replicate_filename() |
| 42 | +{ |
| 43 | + printf -v TDIGIT3 %03u $(($TARGET % 1000)) |
| 44 | + ARG=$(($TARGET / 1000)) |
| 45 | + printf -v TDIGIT2 %03u $(($ARG % 1000)) |
| 46 | + ARG=$(($ARG / 1000)) |
| 47 | + printf -v TDIGIT1 %03u $ARG |
| 48 | + LOCAL_PATH="$LOCAL_DIR/$TDIGIT1/$TDIGIT2" |
| 49 | + REPLICATE_FILENAME="$LOCAL_PATH/$TDIGIT3" |
| 50 | +}; |
| 51 | + |
| 52 | +update_state() |
| 53 | +{ |
| 54 | + get_replicate_filename |
| 55 | + if [[ -s "$REPLICATE_FILENAME.state.txt" ]]; then { |
| 56 | + TIMESTAMP_LINE=`cat "$REPLICATE_FILENAME.state.txt"` |
| 57 | + DATA_VERSION=${TIMESTAMP_LINE:9} |
| 58 | + }; fi |
| 59 | +}; |
| 60 | + |
| 61 | +while [[ $(($LOWER + 1)) -lt $UPPER ]]; do |
| 62 | +{ |
| 63 | + TARGET=$((($LOWER + $UPPER) / 2)) |
| 64 | + update_state |
| 65 | + #echo "$TARGET - $TIMESTAMP_LINE" |
| 66 | + if [[ -s "$REPLICATE_FILENAME.state.txt" && "$DATA_VERSION" < "$TARGET_TIME" ]]; then |
| 67 | + { |
| 68 | + LOWER=$TARGET |
| 69 | + }; else |
| 70 | + { |
| 71 | + UPPER=$TARGET |
| 72 | + }; fi |
| 73 | +}; done |
| 74 | + |
| 75 | +echo "Content-Type: text/plain; charset=utf-8" |
| 76 | +echo |
| 77 | +echo "$LOWER" |
0 commit comments