mirrorgit

Simple Script for Mirroring git Repos
git clone git://git.ckyln.com/mirrorgit.git
Log | Files | Refs | README | LICENSE

commit 8ae0b7d99e2ae5d9fa8f39d0a4db608e74bcd546
Author: Cem Keylan <cem@ckyln.com>
Date:   Wed, 19 Jun 2019 18:31:01 +0300

Initial Commit

Diffstat:
AREADME.md | 27+++++++++++++++++++++++++++
Amirrorgit.sh | 50++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,27 @@ +# Git Mirroring Script + +Setting up a git mirror is hard, especially if you are trying to mirror your repository to Microsoft's Github. Microsoft does not want you to self-host, so they don't present you with any options for mirroring. + +This little shell script: +* Fetches the repositories to a temporary directory +* Pushes them to the mirror repository + +It is pretty simple. + +## Usage + +Before you use this script you must edit it and add +* Your username +* The server you are mirroring from (eg. https://git.example.com) +* The server you are mirroring to without (eg. github.com) +* A list of the repositories you will be mirroring + +After that you can simply type, + +```shell +sh mirrorgit.sh +``` + +## Dependencies +* Git (obviously) +* SSH keys deployed on the mirror repository diff --git a/mirrorgit.sh b/mirrorgit.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# Cem Keylan (2019) + +##### IMPORTANT ###### +## You must have an ssh key on the mirror repository in order to be able +## to push your mirrors +SSH="NO" +## After you are sure you have ssh keys on the repo, remove or +## comment this line +###################### + +case $SSH in + NO) printf "Please configure the script and read the comments\n" && exit 1 ;; +esac + +USERNAME="" + +## Add only the host name (eg. "https://github.com" ) +FROMHOST="" +## Mirrorhost should not contain https or http (eg. "github.com") +MIRRORHOST="" + +## Add the names of your repositories +## with only a space (eg. "repo1 repo2 repo3") +REPONAMES="" + +[ -z $USERNAME ] && printf "You must add your username to the script before you can use it\n" && exit 1 +[ -z $FROMHOST ] && printf "You must add your own git repo address beforeyou can use the script\n" && exit 1 +[ -z $MIRRORHOST ] && printf "You must add the git repo address you will be mirroring to before you can use this script\n" && exit 1 +[ -z "$REPONAMES" ] && printf "You must add repositories before you can use this script\n" && exit 1 + +case $MIRRORHOST in + https://*) MIRRORHOST=$(echo $MIRRORHOST | cut -c 9-) ;; + http://*) MIRRORHOST=$(echo $MIRRORHOST | cut -c 8-) ;; +esac + +ORIGFOLD=$PWD +TEMPFOLD=$(mktemp -d /tmp/gitmirror-XXXXXX) + +cd $TEMPFOLD +for i in $REPONAMES +do + git clone --mirror $FROMHOST/$USERNAME/$i || exit 1 + cd "$i".git + git push --mirror git@$MIRRORHOST:$USERNAME/$i || exit 1 + cd $TEMPFOLD +done + +printf "Done\n" +cd $ORIGFOLD