d6e4e53ea66d832e6bb98c24ea1183839242d19a
configuration/environments_scripts/central_reverse_proxy/files/usr/local/bin/downloadNewArchivedTracTracEvents.sh
| ... | ... | @@ -3,6 +3,8 @@ |
| 3 | 3 | # Downloads all TracTrac event data based on ${GIT_ROOT}/configuration/tractrac-json-urls |
| 4 | 4 | # into the target directory (specified as $1) for those event URLs whose specific folder |
| 5 | 5 | # does not yet exist in the target directory. |
| 6 | +# The TRACTRAC_API_TOKEN environment variable must contain a TracTrac API token valid for |
|
| 7 | +# reading the events. It will be passed on to the downloadTracTracEvent script |
|
| 6 | 8 | TARGET_DIR="${1}" |
| 7 | 9 | if [[ $# -eq 1 ]]; then |
| 8 | 10 | GIT_ROOT=/home/wiki/gitwiki |
| ... | ... | @@ -14,10 +16,13 @@ for i in `cat "${JSON_URLS_FILE}"`; do |
| 14 | 16 | EVENT_DB="$( basename $( dirname ${i} ) )" |
| 15 | 17 | if [ -d "${TARGET_DIR}/${EVENT_DB}" ]; then |
| 16 | 18 | echo "Directory for event ${EVENT_DB} already found. Not downloading again. Use" |
| 17 | - echo " downloadTracTracEvent ${i} ${TARGET_DIR}" |
|
| 19 | + echo " ${GIT_ROOT}/configuration/downloadTracTracEvent ${i} ${TARGET_DIR}" |
|
| 18 | 20 | echo "to force an update." |
| 19 | 21 | else |
| 20 | 22 | echo "Did not find directory for event ${EVENT_DB} yet in ${TARGET_DIR}. Downloading..." |
| 21 | - downloadTracTracEvent "${i}" "${TARGET_DIR}" |
|
| 23 | + if [ -n "${TRACTRAC_API_TOKEN}" ]; then |
|
| 24 | + echo "Using authenticated requests for the params files" |
|
| 25 | + fi |
|
| 26 | + downloadTracTracEvent "${i}" "${TARGET_DIR}" "${TRACTRAC_API_TOKEN}" |
|
| 22 | 27 | fi |
| 23 | 28 | done |
configuration/environments_scripts/central_reverse_proxy/files/usr/local/bin/downloadTracTracEvent
| ... | ... | @@ -1,6 +1,6 @@ |
| 1 | 1 | #!/bin/bash |
| 2 | 2 | # Example usage: |
| 3 | -# ./downloadTracTracEvent https://event.tractrac.com/events/event_20150625_KielerWoch/jsonservice.php /tmp/KielerWoche2015 |
|
| 3 | +# ./downloadTracTracEvent https://event.tractrac.com/events/event_20150625_KielerWoch/jsonservice.php /tmp/KielerWoche2015 [ {TracTracAPIToken} ] |
|
| 4 | 4 | # |
| 5 | 5 | # To obtain the set of TracTrac JSON URLs currently in use by the archive, on |
| 6 | 6 | # dbserver.internal.sapsailing.com try this: |
| ... | ... | @@ -9,25 +9,34 @@ |
| 9 | 9 | # for i in `cat /tmp/tractrac-json-urls`; do ./downloadTracTracEvent $i /tmp/tractrac-tracks; done |
| 10 | 10 | # and you will get a folder per event under /tmp/tractrac-tracks with all .mtb and .txt files as well |
| 11 | 11 | # as the .json file in them. |
| 12 | +# If a TracTrac API token is passed as the last parameter, it will be used to authenticate the requests |
|
| 13 | +# made to TracTrac. |
|
| 12 | 14 | EVENT_JSON_URL="${1}" |
| 13 | 15 | EVENT_DB="$( basename $( dirname ${EVENT_JSON_URL} ) )" |
| 14 | 16 | TARGET_DIR="${2}/${EVENT_DB}" |
| 17 | +TRACTRAC_API_TOKEN="${3}" |
|
| 18 | +if [ -n "${TRACTRAC_API_TOKEN}" ]; then |
|
| 19 | + WGET_AUTHENTICATION_OPTION="--header=Authorization: Bearer ${TRACTRAC_API_TOKEN}" |
|
| 20 | + echo "Authenticating the TracTrac requests" |
|
| 21 | +else |
|
| 22 | + WGET_AUTHENTICATION_OPTION="" |
|
| 23 | +fi |
|
| 15 | 24 | if [ ! -d "${TARGET_DIR}" ]; then |
| 16 | 25 | echo "${TARGET_DIR} does not exist; making it..." |
| 17 | 26 | mkdir -p "${TARGET_DIR}" |
| 18 | 27 | fi |
| 19 | 28 | pushd "${TARGET_DIR}" |
| 20 | 29 | # create a patched version of the .json file that uses only relative params_url values: |
| 21 | -wget -O - "${EVENT_JSON_URL}" | sed -e 's/"params_url":"[^"]*\/\([^"/]*\.txt\)"/"params_url":"\1"/g' >"${EVENT_DB}.json" |
|
| 22 | -for params_url in `wget -O - "${EVENT_JSON_URL}" | jq -r '.races[].params_url'`; do |
|
| 30 | +wget -O - "${WGET_AUTHENTICATION_OPTION}" "${EVENT_JSON_URL}" | sed -e 's/"params_url":"[^"]*\/\([^"/]*\.txt\)"/"params_url":"\1"/g' >"${EVENT_DB}.json" |
|
| 31 | +for params_url in `wget -O - "${WGET_AUTHENTICATION_OPTION}" "${EVENT_JSON_URL}" | jq -r '.races[].params_url'`; do |
|
| 23 | 32 | echo ${params_url} |
| 24 | - wget "${params_url}" |
|
| 33 | + wget "${WGET_AUTHENTICATION_OPTION}" "${params_url}" |
|
| 25 | 34 | FILE="`basename ${params_url}`" |
| 26 | 35 | STORED_URI_PART=`grep -i ^stored-uri: "${FILE}" | head -1 | sed -e 's/^stored-uri://'` |
| 27 | 36 | STORED_URI="`dirname ${EVENT_JSON_URL}`/${STORED_URI_PART}" |
| 28 | 37 | echo "stored-uri: ${STORED_URI}" |
| 29 | 38 | # presumably the dirname of the stored URI is something like "datafiles" |
| 30 | 39 | mkdir -p `dirname ${STORED_URI_PART}` |
| 31 | - wget -O "${STORED_URI_PART}" "${STORED_URI}" |
|
| 40 | + wget -O "${STORED_URI_PART}" "${WGET_AUTHENTICATION_OPTION}" "${STORED_URI}" |
|
| 32 | 41 | done |
| 33 | 42 | popd |
configuration/environments_scripts/central_reverse_proxy/users/wiki/crontab-download-new-archived-trac-trac-events
| ... | ... | @@ -1 +1 @@ |
| 1 | -15 12 * * * export PATH=/bin:/usr/bin:/usr/local/bin; downloadNewArchivedTracTracEvents.sh /home/trac/static/TracTracTracks "/home/wiki/gitwiki" >/home/wiki/downloadNewArchivedTracTracEvents.out 2>/home/wiki/downloadNewArchivedTracTracEvents.err |
|
| 1 | +15 12 * * * export PATH=/bin:/usr/bin:/usr/local/bin; . /home/wiki/secrets; export TRACTRAC_API_TOKEN; downloadNewArchivedTracTracEvents.sh /home/trac/static/TracTracTracks "/home/wiki/gitwiki" >/home/wiki/downloadNewArchivedTracTracEvents.out 2>/home/wiki/downloadNewArchivedTracTracEvents.err |