#!/usr/bin/env bash working_dir="$(dirname $(realpath $0))" conf_file="${working_dir}/conf/update_git_repositories.conf" log_file="$(mktemp)" #--------------------------------------- #----------------------------- # Some functions #----------------------------- #--------------------------------------- clean_up() { # Perform program exit housekeeping rm $log_file blank_line exit $1 } echononl(){ 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 } error(){ blank_line if $terminal ; then echo -e " [ \033[31m\033[1mFehler\033[m ]: $*" else echo "" echo "[ Error ]: $*" echo "" fi blank_line } echo_done() { if $terminal ; then echo -e "\033[1G[ \033[1;32mdone\033[m ]" fi } echo_ok() { 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() { if $terminal ; then echo -e "\033[1G[ \033[1;33m\033[1mwarn\033[m ]" fi } echo_failed(){ if $terminal ; then echo -e "\033[1G[ \033[1;31mfail\033[m ]" fi } echo_skipped() { 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 #----------------------------- #--------------------------------------- if [[ -f "$conf_file" ]]; then source "$conf_file" fi [[ -z "$GIT_BASE_DIRECTORIES" ]] && GIT_BASE_DIRECTORIES="/usr/local/src /root/bin /root/crontab" 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 [[ ! -d "${_git_base_dir}" ]] && continue 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 \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_done else echo_failed error "$(cat $log_file)" fi #fi done done #if [[ -d "/root/crontab/backup-rcopy" ]]; then # 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_done # else # echo_failed # error "$(cat $log_file)" # fi #fi blank_line clean_up