From ce30ed85a8afcf05024f32981b9af67608c886a6 Mon Sep 17 00:00:00 2001 From: vonavi Date: Sun, 20 Apr 2014 20:42:30 +0300 Subject: [PATCH] Script 'scheduler': convert REPO into a URL if needed. --- schedule | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/schedule b/schedule index 961f9b4..10a0e5d 100755 --- a/schedule +++ b/schedule @@ -2,8 +2,8 @@ # Copyright 2014 Vladimir Ivanov # Distributed under the terms of the GNU General Public License v2 -REPO=fat0troll/lorchess -TOURNAMENT=2014/1-tabiyas +REPO="https://raw.githubusercontent.com/fat0troll/lorchess/master" +TOURNAMENT="2014/1-tabiyas" # Version information VERSION="0.1" @@ -53,7 +53,9 @@ show_tour_sequence() { fi for tour in $sequence; do - local info_url="${BASEURL}/tours/${tour}/tour_info" + convert_repo_url + local base_url="${REPO}/${TOURNAMENT}" + local info_url="${base_url}/tours/${tour}/tour_info" # *NOTE* The incorporation of a newline at the end of # 'tour_info' (--write-out '\n') is important and allows one @@ -101,6 +103,18 @@ show_tour_sequence() { done } +convert_repo_url() { + if [[ ! "$REPO" =~ ^(https?|file):// ]]; then + if [[ ! "$REPO" =~ ^/ ]]; then + # REPO is a relative path + base_dir="$(dirname $0)" + REPO="$(cd ${base_dir}/${REPO}; pwd)" + fi + + REPO="file://${REPO}" + fi +} + get_tour_num() { if [[ "$1" =~ "Тур №"([0-9]+) ]]; then tour_num="${BASH_REMATCH[1]}" @@ -151,7 +165,7 @@ keep_game_info() { store_game_url() { local tour=$(printf "%02g" "$tour_num") local game_dir="${game_date}-${white}-vs-${black}" - local pgn_url="${BASEURL}/tours/${tour}/${game_dir}/1.pgn" + local pgn_url="${base_url}/tours/${tour}/${game_dir}/1.pgn" while read line; do # Search for a URL inside PGN file @@ -252,7 +266,6 @@ SHOW_ALL=false PLAYER="" FORMAT=term SHOW_LINK=false -BASEURL="https://raw.github.com/${REPO}/master/${TOURNAMENT}" while getopts "ap:f:lhv" opt; do case "$opt" in