42 lines
1.3 KiB
Text
42 lines
1.3 KiB
Text
|
#!/bin/bash
|
||
|
|
||
|
# Copyright 2020 Midgard
|
||
|
#
|
||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
# you may not use this file except in compliance with the License.
|
||
|
# You may obtain a copy of the License at
|
||
|
#
|
||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||
|
#
|
||
|
# Unless required by applicable law or agreed to in writing, software
|
||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
# See the License for the specific language governing permissions and
|
||
|
# limitations under the License.
|
||
|
|
||
|
|
||
|
# Configure me
|
||
|
SSHARGS="myserver.example.org"
|
||
|
SYMBOLS="USD GBP"
|
||
|
SERVERSIDE_PATH_TO_RATES="/usr/local/lib/pricedb/rates"
|
||
|
|
||
|
|
||
|
set -euo pipefail
|
||
|
|
||
|
pricedb="$HOME/ledger/pricedb.ledger"
|
||
|
cd "$(dirname "$pricedb")"
|
||
|
|
||
|
last_date="$(tail -n1 "$pricedb" | sed 's/P \([0-9 :-]*\) .*/\1/')"
|
||
|
printf 'Fetching all exchange rates after %s\n' "$last_date"
|
||
|
|
||
|
values="$(ssh $SSHARGS "$SERVERSIDE_PATH_TO_RATES '$last_date' $SYMBOLS")"
|
||
|
if [ $? -eq 0 -a -n "$values" ]; then
|
||
|
printf '%s\n' "$values" >> "$pricedb"
|
||
|
printf '%s\n' "$values"
|
||
|
fi
|
||
|
|
||
|
git diff --quiet "$pricedb" && exit
|
||
|
git diff --cached --quiet || { echo "Not adding to Git because there are staged changes"; exit; }
|
||
|
git add "$pricedb"
|
||
|
git commit -m "Update pricedb"
|