diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f578c6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +conf/*.conf +BAK/* diff --git a/conf/update_git_repositories.conf.sample b/conf/update_git_repositories.conf.sample new file mode 100644 index 0000000..d5b4169 --- /dev/null +++ b/conf/update_git_repositories.conf.sample @@ -0,0 +1,13 @@ +# ---------------------------------------------------- +# --- +# - Parameter Settings for Script 'update_git_repositories' +# --- +# ---------------------------------------------------- + +# - List of directories, which contains git repositories +# - +# - Multiple entries are possible by using a blank separated list +# - +# - Example: GIT_BASE_DIRECTORIES="/usr/local/src /root/bin" +# - +GIT_BASE_DIRECTORIES="/usr/local/src /root/bin" diff --git a/update_git_repositories.sh b/update_git_repositories.sh new file mode 100755 index 0000000..6cc4a26 --- /dev/null +++ b/update_git_repositories.sh @@ -0,0 +1,114 @@ +#!/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