Last active
August 29, 2015 13:59
-
-
Save mdeous/10555582 to your computer and use it in GitHub Desktop.
Automatic versionned tools update script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Batch VCS repositories update script. | |
| # Finds all git/svn/mercurial repositories recursively | |
| # and updates them. | |
| # | |
| # USAGE: | |
| # ./update.sh [PATH] | |
| # | |
| # PATH | |
| # Root folder within which repositories should be searched for. | |
| # If not provided, script's location is used as the root folder. | |
| # | |
| declare -A VCS_DIRS | |
| VCS_DIRS=(['.git']="gitupdate" ['.svn']="svnupdate" ['.hg']="hgupdate") | |
| CUR_DIR="$(pwd)" | |
| RED="\033[0;31m" | |
| YELLOW="\033[0;33m" | |
| GREEN="\033[0;32m" | |
| BLUE="\033[0;34m" | |
| WHITE="\033[1;37m" | |
| NOCOLOR="\033[0;0m" | |
| errcheck() { # args: update_status, update_file, no_update_lines | |
| if [[ $1 -ne 0 ]]; then | |
| echo -e "${RED}FAILED (retcode=$1)${NOCOLOR}" | |
| else | |
| linecount=$(wc -l $2 | cut -d' ' -f1) | |
| if [[ ${linecount} -eq $3 ]]; then | |
| echo -e "${GREEN}NO UPDATE${NOCOLOR}" | |
| else | |
| echo -e "${BLUE}UPDATED${NOCOLOR}" | |
| fi | |
| fi | |
| rm $2 | |
| } | |
| gitupdate() { | |
| git pull &>/tmp/gitupdate | |
| errcheck $? "/tmp/gitupdate" 1 | |
| } | |
| svnupdate() { | |
| svn up &>/tmp/svnupdate | |
| errcheck $? "/tmp/svnupdate" 2 | |
| } | |
| hgupdate() { | |
| (hg pull && hg update) &>/tmp/hgupdate | |
| errcheck $? "/tmp/hgupdate" 5 | |
| } | |
| if [[ $# -eq 1 ]]; then | |
| ROOT_PATH="$1" | |
| test -d ${ROOT_PATH} || (echo -e "${RED}Path not found: ${ROOT_PATH}${NOCOLOR}" && exit 1) | |
| else | |
| ROOT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd )" | |
| fi | |
| for VCS_DIR in ${!VCS_DIRS[@]}; do | |
| for APP_CVS_DIR in `find ${ROOT_PATH} -type d -name "${VCS_DIR}"`; do | |
| toolname="$(basename $(readlink -f ${APP_CVS_DIR}/..))" | |
| echo -e -n "${YELLOW}[+] Updating ${WHITE}${toolname}${YELLOW}... " | |
| cd $APP_CVS_DIR/.. | |
| ${VCS_DIRS[$VCS_DIR]} | |
| done | |
| done | |
| cd $CUR_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment