diff --git a/make_dir_ausgaben.sh b/make_dir_ausgaben.sh new file mode 100755 index 0000000..099d7cd --- /dev/null +++ b/make_dir_ausgaben.sh @@ -0,0 +1,215 @@ +#!/usr/bin/env bash + +# ============= +# --- Some Definitions +# ============= + +logfile=$(mktemp) + +base_dir=/home/chris/O.OPEN/Büro/Ausgaben + +dirs="Bülos Hetzner InternetX Sinma Sonstige Telekom" +dirs_telekom="Festnetz MobileData MobileFon" + + +default_year="$(date +%Y)" +default_month="$(date +%m)" + + +# --- +# --- DON'T MAKE CHANGES AFTER THIS LINE +# --- + + +# ============= +# --- Some functions +# ============= + +clean_up() { + + rm -f $logfile + exit $1 +} + + +echononl(){ + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo "$*\\c" 1>&2 + else + echo -e -n "$*" 1>&2 + fi + rm /tmp/shprompt$$ +} + +fatal(){ + echo "" + echo -e "\t[ \033[31m\033[1mfataler Fehler\033[m ]: $*" + echo "" + echo -e "\t\033[31m\033[1mInstalllation wird abgebrochen\033[m\033[m" + echo "" + clean_up 1 +} + +error(){ + echo "" + echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" + echo "" +} + +warn (){ + echo "" + echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" + echo "" +} + +info (){ + echo "" + echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" + echo "" +} + +echo_ok() { + echo -e "\033[80G[ \033[32mok\033[m ]" +} +echo_failed(){ + echo -e "\033[80G[ \033[1;31mfailed\033[m ]" +} +echo_skipped() { + echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]" +} + +trap clean_up SIGHUP SIGINT SIGTERM + +## --- +## --- END: functions + + +clear +echo +echo -e "\t\033[32mSkript erstellt Verzeichnisstruktur für monatliche Bilanz\033[m" +echo +echo +echo + +echo "" +echo -e "\033[32m--\033[m" +echo "" +echo "Für welches Jahr (JJJJ) soll die Verzeichnisstruktur erstellt werden?" +echo "" +year="" +if [[ -n "$default_year" ]] ; then + echononl "Jahr [${default_year}]: " + read year + if [[ "X$year" = "X" ]]; then + year="$default_year" + fi +else + echononl "Jahr [JJJJ]: " + read year + while [ "X$year" = "X" ] ; do + echo -e "\n\t\033[33m\033[1mDie Angabe von 'Jahr' ist erforderlich!\033[m\n" + echononl "Jahr [JJJJ]: " + read year + done +fi +year_short="$(echo ${year:${#year} - 2})" + +echo "" +echo -e "\033[32m--\033[m" +echo "" +echo "Für welche Monat (MM) soll die Verzeichnisstruktur erstellt werden?" +echo "" +month="" +if [[ -n "$default_month" ]] ; then + echononl "Monat [${default_month}]: " + read month + if [[ "X$month" = "X" ]]; then + month="$default_month" + fi +else + echononl "Monat [MM]: " + read month + while [ "X$month" = "X" ] ; do + echo -e "\n\t\033[33m\033[1mDie Angabe von 'Monat' ist erforderlich!\033[m\n" + echononl "Monat [MM]: " + read month + done +fi + + +echo +echo -e "\t\033[32mErstelle die Verzeichnisstruktur für die monatlich Bilanz \033[1m${month}/${year}\033[m" +echo + +info "Continue creating the folder structure type uppercase 'YES'" +echo -e -n "\033[1mContinue:\033[m " +read OK + +if [[ "$OK" != "YES" ]] ; then + fatal "Abort by user request - Answer as not 'YES'" +fi + +echo "" +echo "" + +echononl "Create folder '${base_dir}/$year'.." +if [[ ! -d "${base_dir}/$year" ]]; then + mkdir "${base_dir}/$year" > $logfile 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error $(cat $logfile) + fi +else + echo_skipped +fi + +echononl "Create folder '${base_dir}/${year}/$month'.." +if [[ ! -d "${base_dir}/${year}/$month" ]]; then + mkdir "${base_dir}/${year}/$month" > $logfile 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error $(cat $logfile) + fi +else + echo_skipped +fi + +for _dir in $dirs ; do + echononl "Create folder '${base_dir}/${year}/${month}/$_dir'.." + if [[ ! -d "${base_dir}/${year}/${month}/$_dir" ]]; then + mkdir "${base_dir}/${year}/${month}/$_dir" > $logfile 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error $(cat $logfile) + fi + else + echo_skipped + fi + + if [[ "$_dir" = "Telekom" ]]; then + for _dir_telekom in $dirs_telekom ; do + echononl "Create folder '${base_dir}/${year}/${month}/${_dir}/$_dir_telekom'.." + if [[ ! -d "${base_dir}/${year}/${month}/${_dir}/$_dir_telekom" ]] ; then + mkdir "${base_dir}/${year}/${month}/${_dir}/$_dir_telekom" > $logfile 2>&1 + if [[ $? -eq 0 ]]; then + echo_ok + else + echo_failed + error $(cat $logfile) + fi + else + echo_skipped + fi + done + fi +done + +echo "" +clean_up 0