Created
August 17, 2018 10:58
-
-
Save peterjc/2f1bf0633afbbbb93e074625758fa9a7 to your computer and use it in GitHub Desktop.
Script to simplify setting up git repository for cron-based mirroring of a GitHub fork
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 | |
set -euo pipefail | |
# See https://blastedbio.blogspot.co.uk/2016/05/sync-github-mirror-with-cron.html and | |
# https://gist.github.com/peterjc/eccac1942a9709993040425d33680352 for mirroring script | |
# | |
# Usage: | |
# | |
# 1. Fork upstream repo under HuttonICS, disable wiki, projects, issues etc. Protect master branch. | |
# 2. Run: | |
# | |
# ./mirror_setup.sh repo-name https://github.com/upstream-owner/repo-name.git | |
# | |
# 3. Copy and paste repo-name_key.pub into GitHub fork settings as deploy key with write permissions | |
# 4. Add crontab entry | |
# | |
# | |
#The script does this: | |
# | |
# 1. ssh-keygen -t rsa -b 4096 -C "repo-name key" -f repo-name_key -N "" | |
# 2. Clone upstream repo using HTTPS, cd repo-name | |
# 3. git remote add mirror *HuttonForkUsingGit* | |
# 4. git fetch mirror | |
name="$1" | |
upstream="$2" | |
if [ ! -f "${name}_key" ]; then | |
echo "Generating ${name} SSH key" | |
ssh-keygen -t rsa -b 4096 -C "huttonics/${name} deployment (Peter's iMac)" -f ${name}_key -N "" | |
fi | |
if [ ! -d "${name}/.git" ]; then | |
echo "Cloning upstream ${name} repository ${upstream}" | |
git clone "$upstream" "$name" | |
cd $name | |
git remote add mirror [email protected]:HuttonICS/${name}.git | |
cd .. | |
fi | |
echo "=======================================================" | |
echo | |
echo "For the GitHub deployment key:" | |
echo | |
cat ${name}_key.pub | |
echo | |
echo "Paste this into https://github.com/HuttonICS/${name}/settings/keys" | |
echo | |
echo "=======================================================" | |
echo | |
echo "For the cron tab:" | |
echo "~/cron/mirror_git ~/cron/${name} ~/cron/${name}_key ~/cron/${name}.log" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has been superseded by https://gist.github.com/peterjc/899a6d24badd47d6305ddc5e299fd4bd which uses the GitHub API with a personal access token allowing it find repositories and add the deployment keys automatically.