Last active
September 8, 2017 07:58
-
-
Save zhonger/3ef07fd54c9594130a998ccc42ddaaad to your computer and use it in GitHub Desktop.
This file contains 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 | |
#author:zhonger | |
#date:2017-09-08 | |
#contact:zhonger@live.cn | |
echo "----------------------------------------------------------------------- " | |
echo "| Git-mirror | " | |
echo "| | " | |
echo "| Functions: This is a shell which mirror git from github to gitlab. | " | |
echo "| | " | |
echo "| Input parameters: github repository name and gitlab repository name | " | |
echo "| default inputs 'Homebrew/brew'. When there is a input, the two | " | |
echo "| repository is the same. | " | |
echo "| | " | |
echo "| Attention: please modify the config variable 'gitlabUrl' firstly. | " | |
echo "| | " | |
echo "| Author:@zhonger(zhonger@live.cn) | " | |
echo "| Web site: https://lisz.io | " | |
echo "----------------------------------------------------------------------- " | |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin | |
export PATH | |
githubUrl=https://github.com/ | |
gitlabUrl=ssh://git@git.shuosc.org:8000/ | |
githubRes=$githubUrl$1 | |
gitlabRes='' | |
gitPath=~/git/$1 | |
if [ $# == 1 ] | |
then | |
gitlabRes=$gitlabUrl$1 | |
else | |
gitlabRes=$gitlabUrl$2 | |
fi | |
echo "GithubRes is : $githubRes" | |
echo "GitlabRes is : $gitlabRes" | |
echo "$gitPath" | |
if [ ! -x $gitPath ] | |
then | |
echo "The git local path is not found, and it will be maked ..." | |
mkdir -p $gitPath | |
git clone $githubRes $gitPath | |
cd $gitPath | |
echo "Add gitlab repository ..." | |
git remote add gitlab $gitlabRes | |
echo "Git push to gitlab" | |
git push gitlab master | |
else | |
echo "The git local path is exist." | |
cd $gitPath | |
echo "Start to git pull from github." | |
git pull origin master | |
echo "Git pull is successful. It will start to git push" | |
git push gitlab master | |
fi | |
echo "The $1 git-mirror process is successful." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment