Skip to content

Commit

Permalink
add script for update github upsteam repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-hub committed Feb 1, 2015
1 parent bab8c38 commit c80f37e
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions lnx/github-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/zsh
githubUser="GITHUB-ACCOUNT"
array=( "ORIGINACCOUNT/REPOSITORYNAME" )

GithubUrl() {
repositoryUrl="https://github.com/$1/$2.git"
echo $repositoryUrl
}

GithubClone() {
echo "--------------------"
echo "Git - clone repository"
git clone $1 $2
}

GitAddRemote() {
cd $1
echo "--------------------"
echo "Git - add remote repository"
git remote add upstream $2
}

GithubSync() {
[ "${1#*.git}" = "$1" ] && exit
[ ! -d $1 ] && exit
cd $1
echo "--------------------"
echo "Git - sync upstream - start"
git fetch upstream
git checkout master
git merge upstream/master
echo "--------------------"
echo "Git - sync upstream - finish"
git push origin --tags --prune
git push origin master
}

Split() {
part=${1/\//' '}
if [ $2 -eq 2 ]; then
newpart=`echo $part | awk 'BEGIN{FS=OFS=" "}{$1=$3=""}{print}'`
else
newpart=`echo $part | awk 'BEGIN{FS=OFS=" "}{$2=$3=""}{print}'`
fi
echo "${newpart/ /}"
}

MakeIt() {
remoteUserName=`Split $1 1`
remoteRepositoryName=`Split $1 2`
remoteUrl=$(GithubUrl ${remoteUserName/ /} ${remoteRepositoryName/ /})
url=$(GithubUrl $2 ${remoteRepositoryName/ /})
workingDir=`pwd`
localPath="${remoteRepositoryName/ /}.git"
GithubClone $url $localPath
GitAddRemote $localPath $remoteUrl
cd $workingDir
GithubSync $localPath
cd $workingDir
echo "--------------------"
echo "Cleaning ..."
rm -rf $localPath
}

RunArray () {
action=$3
username=$4
i=1
while (( $i <= $2 ))
do
[ "${array[$i]}" = "" ] && $i=$i+1 && continue
$action ${array[$i]} $username
echo; echo; echo;
i=$i+1
done
}

#RunArray ( ArrayName, Function, Parameter)
MaxItems=${#array[*]}
RunArray array $MaxItems MakeIt $githubUser

echo "all repositories up to date!"; echo "--------------------"; echo;

0 comments on commit c80f37e

Please sign in to comment.