#!/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 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 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 "" } echo_done() { echo -e "\033[80G[ \033[32mdone\033[m ]" } echo_ok() { echo -e "\033[80G[ \033[32mok\033[m ]" } echo_warning() { echo -e "\033[80G[ \033[33m\033[1mwarn\033[m ]" } echo_failed(){ echo -e "\033[80G[ \033[1;31mfailed\033[m ]" } echo_skipped() { echo -e "\033[80G[ \033[37mskipped\033[m ]" } trap clean_up SIGHUP SIGINT SIGTERM #--------------------------------------- #----------------------------- # 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" for _git_base_dir in $GIT_BASE_DIRECTORIES ; do echo "" for _dir in $(ls ${_git_base_dir}/) ; do [[ ! -d "${_git_base_dir}/$_dir" ]] && continue [[ ! -d "${_git_base_dir}/${_dir}/.git" ]] && continue echononl " Update Repository ${_git_base_dir}/$(basename $_dir).." 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 else echo_failed error "$(cat $log_file)" fi fi done done echo "" clean_up