├── LICENSE ├── README.md └── updateRepos.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Carlos Silva 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gitRepoUpdater 2 | ## This shell script updates all of the git repositories that you have in a folder 3 | ### Instructions 4 | 5 | To update all git repos in a folder you can use: 6 | ```sh 7 | $ ./updateRepos.sh all 8 | ``` 9 | or 10 | ```sh 11 | $ ./updateRepos.sh -a 12 | ``` 13 | 14 | To evaluate which repo update you can use: 15 | ```sh 16 | $ ./updateRepos.sh each 17 | ``` 18 | or 19 | ```sh 20 | $ ./updateRepos.sh -e 21 | ``` 22 | 23 | if you want to use the complete wizard, just use this: 24 | ```sh 25 | $ ./updateRepos.sh 26 | ``` 27 | --- 28 | ### Installing to use globally 29 | To install this script and use it anywhere in your system you may clone this repository 30 | ```git 31 | git clone https://github.com/devCharles/gitRepoUpdater.git 32 | ``` 33 | then cd into the new directory 34 | ```sh 35 | $ cd gitRepoUpdater 36 | ``` 37 | now we must copy the 'updateRepos.sh' script to ```/usr/local/bin``` 38 | ```sh 39 | $ sudo cp updateRepos.sh /usr/local/bin 40 | ``` 41 | and you can use the script by simply using 42 | ```sh 43 | $ updateRepos.sh [flag] 44 | ``` 45 | 46 | ### Notes 47 | - in order to use this script you may need to have the right permission level to execute the script 48 | -------------------------------------------------------------------------------- /updateRepos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cecho() { 4 | local code="\033[" 5 | case "$1" in 6 | black | bk) color="${code}0;30m";; 7 | red | r) color="${code}1;31m";; 8 | green | g) color="${code}1;32m";; 9 | yellow | y) color="${code}1;33m";; 10 | blue | b) color="${code}1;34m";; 11 | purple | p) color="${code}1;35m";; 12 | cyan | c) color="${code}1;36m";; 13 | gray | gr) color="${code}0;37m";; 14 | *) local text="$1" 15 | esac 16 | [ -z "$text" ] && local text="$color$2${code}0m" 17 | echo -e "$text" 18 | } 19 | 20 | declare -a updatedRepos=() 21 | 22 | addUpdatedRepo(){ 23 | updatedRepos=("${updatedRepos[@]}" "$1") 24 | } 25 | 26 | printUpdatedRepos(){ 27 | if [ ${#updatedRepos[@]} -gt 0 ]; then 28 | cecho p "# ${#updatedRepos[@]} Updated repositories:" 29 | cecho p "# --------------------------------------" 30 | for repo in "${updatedRepos[@]}"; 31 | do 32 | cecho p "# > ${repo}" 33 | done 34 | cecho p "# --------------------------------------" 35 | else 36 | cecho r "# ------------------" 37 | cecho r "# | NOTHING UPDATED! |" 38 | cecho r "# ------------------" 39 | fi 40 | 41 | } 42 | 43 | declare -a failedRepos=() 44 | 45 | addFailedRepo(){ 46 | failedRepos=("${failedRepos[@]}" "$1") 47 | } 48 | 49 | printFailedRepos(){ 50 | if [ ${#failedRepos[@]} -gt 0 ]; then 51 | cecho r "# ${#failedRepos[@]} Failed repositories:" 52 | cecho r "# --------------------------------------" 53 | for repo in "${failedRepos[@]}"; 54 | do 55 | cecho r "# > ${repo}" 56 | done 57 | cecho r "# --------------------------------------" 58 | else 59 | cecho g "# ------------------" 60 | cecho g "# | NOTHING FAILED! |" 61 | cecho g "# ------------------" 62 | fi 63 | 64 | 65 | } 66 | 67 | update(){ 68 | clear 69 | dir=$1; 70 | cd $dir ; 71 | if [ -d .git ]; then 72 | cecho b "# UPDATING => $dir "; 73 | cecho c "$(git fetch)"; 74 | git rev-parse --verify develop 75 | if [ "$?" == "0" ]; then 76 | cecho c "$(git checkout 'develop')"; 77 | cecho c "# Branch develop will be updated" 78 | else 79 | git rev-parse --verify develop 80 | # git rev-parse --verify master 81 | if [ "$?" == "0" ]; then 82 | cecho c "$(git checkout 'master')"; 83 | cecho c "# Branch master will be updated" 84 | fi 85 | fi 86 | output=$(git pull) 87 | status=$? 88 | cecho c $output; 89 | if [[ $status != 0 ]]; then cecho r "${dir} failed :("; addFailedRepo ${dir}; fi 90 | addUpdatedRepo ${dir} 91 | cecho b "\n" 92 | else 93 | cecho y "#### $PWD does not contains a git repository" 94 | fi 95 | cd .. ; 96 | } 97 | 98 | finish(){ 99 | clear 100 | cecho g "########################################"; 101 | cecho g "# DONE! "; 102 | printUpdatedRepos ${updatedRepos} 103 | printFailedRepos ${failedRepos} 104 | cecho g "########################################"; 105 | cecho g "\nSEE YOU LATER BRO..." 106 | } 107 | 108 | clear 109 | cecho g "\t\t---- GIT UPDATER ----" 110 | if [ "$1" == "-a" ] || [ "$1" == "all" ]; then 111 | cecho p "\tALL GIT REPOS WILL BE UPDATED\n" 112 | for d in */ ; do 113 | update $d; 114 | done 115 | finish 116 | elif [ "$1" == "-e" ] || [ "$1" == "each" ]; then 117 | for d in */ ; do 118 | cd $d 119 | isGit="0" 120 | if [ -d .git ]; then 121 | isGit="1" 122 | fi 123 | cd .. 124 | if [ "$isGit" == "1" ]; then 125 | cecho y "Do you want to update => $d (yes/no)" 126 | read -p ">>> " res 127 | while [ "$res" != "yes" ] && [ "$res" != "no" ]; do 128 | cecho r "please write 'yes' or 'no'" 129 | read -p ">>> " res 130 | done 131 | if [ "$res" == "yes" ]; then 132 | update $d; 133 | else 134 | cecho r "$d Was NOT updated" 135 | fi 136 | fi 137 | done 138 | finish 139 | else 140 | 141 | cecho y "Do you want to update your repos in folder ${PWD} ? (yes/no)"; 142 | read -p ">>> " resp 143 | while [ "$resp" != "yes" ] && [ "$resp" != "no" ]; do 144 | cecho r "please write 'yes' or 'no'" 145 | read -p ">>> " resp 146 | done 147 | 148 | if [ "$resp" == "yes" ]; then 149 | clear 150 | cecho y "Do you want to update all repositories or want to decide per folder?" 151 | cecho y "1) update all" 152 | cecho y "2) ask me for each one" 153 | read -p ">>> " op; 154 | opone="1"; 155 | optwo="2" 156 | while [ "$op" != "$opone" ] && [ "$op" != "$optwo" ]; do 157 | cecho r "please choose a valid option" 158 | read -p ">>> " op; 159 | done 160 | if [ "$op" == "$opone" ]; then 161 | for d in */ ; do 162 | update $d; 163 | done 164 | finish; 165 | elif [ "$op" == "$optwo" ];then 166 | for d in */ ; do 167 | cecho y "Do you want to update => $d (yes/no)" 168 | read -p ">>> " res 169 | while [ "$res" != "yes" ] && [ "$res" != "no" ]; do 170 | cecho r "please write 'yes' or 'no'" 171 | read -p ">>> " res 172 | done 173 | if [ "$res" == "yes" ]; then 174 | update $d; 175 | else 176 | cecho y "$d Was not updated" 177 | fi 178 | done 179 | finish 180 | fi 181 | elif [ "$resp" == "no" ]; then 182 | cecho p "WELL.. see you later bro!!!" 183 | else 184 | cecho r "please write 'yes' or 'no'"; 185 | fi 186 | fi 187 | --------------------------------------------------------------------------------