melder/melder

99 lines
2.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
#
# melder
#
# Copyright 2022 crt0mega <crt0mega@c-r-t.tk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
printf "\033[1;37mmelder Katastrophenwarnungen per Kommandozeile\033[0m\n\n" >&2
declare -gr xmlDocIndex="4"
declare -gr cacheDir=~/.cache/melder
declare -gr configDir=~/.config/melder
declare -gr scriptDir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
# Wenn das Cache-Verzeichnis nicht existiert, erstellen
if ! [ -d $cacheDir ]; then mkdir -p $cacheDir; fi
# Wenn das Config-Verzeichnis nicht existiert, erstellen
if ! [ -d $configDir ]; then mkdir -p $configDir; fi
# Konfiguration einlesen, falls vorhanden. Sonst Standardwerte annehmen
if [ -f $configDir/vars ]; then
source $configDir/vars
else
savedAGS="05314000"
outputFormat="@json"
fi
# Funktionen zugunsten der Übersichtlichkeit ausgelagert
if ! [ -f "$scriptDir/functions" ]; then
printf "\033[1;31mFunktionsbibliothek fehlt!\033[0m\n" >&2
exit 1
fi
source $scriptDir/functions
chkDeps
if ! [ "$1" ]; then
help
fi
case $1 in
-D|-d)
if ! [ "$2" ]; then declare -r ags=$savedAGS; else declare -r ags="$2"; fi
getDashboard $ags
printf "\n"
;;
-A|-a)
if ! [ "$2" ]; then help; fi
savedAGS=$2
printf "AGS $2 in Konfigurationsdatei abgelegt.\n" >&2
;;
-F|-f)
if ! [ "$2" ]; then help; fi
printf "Ausgaebformat $2 in Konfigurationsdatei festgelegt.\n" >&2
outputFormat=$2
;;
-U|-u)
getAGS
;;
-Q|-q)
shift
declare query=$*
if [ "$query" ]; then queryAGS $query; else help; fi
;;
*)
help
;;
esac
# Autosave %)
echo -e "savedAGS=\"$savedAGS\"\noutputFormat=\"$outputFormat\"" > $configDir/vars