From 6cc2688f21f19215d89369e8f696972bf7b80036 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 3 Feb 2021 16:59:56 +0100 Subject: [PATCH] os-upgrade.sh: changes on script output. --- update_git_repositories.sh | 128 ++++++++++++++++++++++++------------- 1 file changed, 84 insertions(+), 44 deletions(-) diff --git a/update_git_repositories.sh b/update_git_repositories.sh index 7499304..d63fe22 100755 --- a/update_git_repositories.sh +++ b/update_git_repositories.sh @@ -15,66 +15,98 @@ clean_up() { # Perform program exit housekeeping rm $log_file + blank_line exit $1 } - echononl(){ - echo X\\c > /tmp/shprompt$$ - if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then - echo -e -n "$*\\c" 1>&2 - else - echo -e -n "$*" 1>&2 + if $terminal ; then + echo X\\c > /tmp/shprompt$$ + if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then + echo -e -n "[ \033[5m\033[1m...\033[m ]\033[13G$*\\c" 1>&2 + else + echo -e -n "[ \033[5m\033[1m...\033[m ]\033[13G$*" 1>&2 + fi + rm /tmp/shprompt$$ fi - rm /tmp/shprompt$$ } error(){ - echo "" - echo -e "\t[ \033[31m\033[1mError\033[m ]: $*" - echo "" -} - -fatal(){ - echo "" - echo -e "\t[ \033[31m\033[1mFatal\033[m ]: $*" - echo "" - echo -e "\t\033[37m\033[1mInstalllation will be interrupted\033[m\033[m" - echo "" - clean_up 1 - exit 1 -} - -warn (){ - echo "" - echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" - echo "" -} - -info (){ - echo "" - echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" - echo "" + blank_line + if $terminal ; then + echo -e " [ \033[31m\033[1mFehler\033[m ]: $*" + else + echo "" + echo "[ Error ]: $*" + echo "" + fi + blank_line } echo_done() { - echo -e "\033[80G[ \033[32mdone\033[m ]" + if $terminal ; then + echo -e "\033[1G[ \033[1;32mdone\033[m ]" + fi } echo_ok() { - echo -e "\033[80G[ \033[32mok\033[m ]" + if $terminal ; then + echo -e "\033[1G[ \033[1;32mok\033[m ]" + fi +} +echo_ignore() { + if $terminal ; then + echo -e "\033[1G[ \033[1;33mignore\033[m ]" + fi } echo_warning() { - echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]" + if $terminal ; then + echo -e "\033[1G[ \033[1;33m\033[1mwarn\033[m ]" + fi } echo_failed(){ - echo -e "\033[80G[ \033[1;31mfailed\033[m ]" + if $terminal ; then + echo -e "\033[1G[ \033[1;31mfail\033[m ]" + fi } echo_skipped() { - echo -e "\033[80G[ \033[37mskipped\033[m ]" + if $terminal ; then + echo -e "\033[1G[ \033[1;37mskip\033[m ]" + fi +} +echo_wait(){ + if $terminal ; then + echo -en "\033[1G[ \033[5m\033[1m...\033[m ]" + fi +} +blank_line() { + if $terminal ; then + echo "" + fi } + +# ============= +# --- Jobhandling +# ============= + +# - Run 'clean_up' for signals SIGHUP SIGINT SIGTERM +# - trap clean_up SIGHUP SIGINT SIGTERM +# ============= +# --- Some Checks +# ============= + +# - Running in a terminal? +# - +if [[ -t 1 ]] ; then + terminal=true +else + terminal=false +fi + + + #--------------------------------------- #----------------------------- # Read Configurations from $conf_file @@ -89,20 +121,28 @@ fi -for _git_base_dir in $GIT_BASE_DIRECTORIES ; do +if $terminal ; then echo "" + echo "" + echo -e "\033[13G\033[33mUpdate GIT repositories..\033[m" + echo "" +fi + + +for _git_base_dir in $GIT_BASE_DIRECTORIES ; do + blank_line for _dir in $(ls ${_git_base_dir}/) ; do [[ ! -d "${_git_base_dir}/$_dir" ]] && continue [[ ! -d "${_git_base_dir}/${_dir}/.git" ]] && continue [[ "$_dir" = "bash" ]] && continue - echononl " Update Repository ${_git_base_dir}/$(basename $_dir).." + echononl "Update Repository \033[1m$(basename $_dir)\033[m.." #if [[ "$_dir" = "dehydrated-cron" ]]; then # echo_skipped # warn "Update this repository manually, because username and password\n\t is needed." #else git -C "${_git_base_dir}/${_dir}" pull > $log_file 2>&1 if [[ $? -eq 0 ]] ; then - echo_ok + echo_done else echo_failed error "$(cat $log_file)" @@ -112,16 +152,16 @@ for _git_base_dir in $GIT_BASE_DIRECTORIES ; do done if [[ -d "/root/crontab/backup-rcopy" ]]; then - echo "" - echononl " Update Repository /root/crontab/backup-rcopy.." + blank_line + echononl "Update Repository \033[1mbackup-rcopy\033[m.." git -C "/root/crontab/backup-rcopy" pull > $log_file 2>&1 if [[ $? -eq 0 ]] ; then - echo_ok + echo_done else echo_failed error "$(cat $log_file)" fi fi -echo "" +blank_line clean_up