add readme, support multiple repositories
AREADME.md
| @@ -0,0 +1,20 @@ | |||
|---|---|---|---|
| 1 | + | # git-autopush | |
| 2 | + | ||
| 3 | + | Script+container image that periodically mirrors a local repository to a remote location, e.g. keep a gitlab/github mirror up-to-date with a repo hosted on a private server | |
| 4 | + | ||
| 5 | + | Example `docker run` command: | |
| 6 | + | `docker run --rm --env-file .env -v ./ssh:/ssh:ro -v ./git:/git:ro "$(docker build -q .)"` | |
| 7 | + | ||
| 8 | + | `./ssh` should contain your key for pushing | |
| 9 | + | `./git` should contain the repositores you want to push | |
| 10 | + | ||
| 11 | + | ### .env parameters | |
| 12 | + | * PUSH_KEY: file name of the private ssh key in the `ssh` directory to be used for pushing, e.g. `id_rsa` | |
| 13 | + | * PUSH_DELAY: how long to sleep between pushes, should be a string compatible with sleep(1) | |
| 14 | + | * PUSH_URLS: a `|` and `space` separated list of urls and directory names, e.g. `git@someserver:myrepo myrepo.git|git@someserver:myotherrepo myrepo2.git` | |
| 15 | + | * `git@someserver:myrepo` and `git@someserver:myotherrepo` are the urls passed to git as a push destination | |
| 16 | + | * `myrepo.git` and `myrepo2.git` are directory names relates to `/git` inside the container | |
| 17 | + | ||
| 18 | + | ### TODO | |
| 19 | + | * allow custom refspecs to be added (for e.g. git-bug) | |
| 20 | + | * port script to python and use json config instead of environment variables | |
DTODO.md-2
| @@ -1,2 +0,0 @@ | |||
|---|---|---|---|
| 1 | - | * allow custom refspecs to be added (for e.g. git-bug) | |
| 2 | - | * allow multiple repositories | |
Mautopush.sh
| @@ -10,18 +10,24 @@ if [ -z "$PUSH_DELAY" ]; then | |||
|---|---|---|---|
| 10 | 10 | exit 1 | |
| 11 | 11 | fi | |
| 12 | 12 | ||
| 13 | - | if [ -z "$PUSH_URL" ]; then | |
| 14 | - | echo "Please set PUSH_DELAY in .env to a string compatible with sleep(1)" | |
| 13 | + | if [ -z "$PUSH_URLS" ]; then | |
| 14 | + | echo "Please set PUSH_URLS in .env" | |
| 15 | 15 | exit 1 | |
| 16 | 16 | fi | |
| 17 | 17 | ||
| 18 | 18 | cd /git | |
| 19 | - | git rev-parse --git-dir || (echo "No repository detected at /git" && exit 1) | |
| 20 | - | ||
| 21 | 19 | #use global config to not modify the repository | |
| 22 | 20 | git config --global core.sshCommand "/usr/bin/ssh -o 'StrictHostKeyChecking no' -i /ssh/$PUSH_KEY" | |
| 23 | 21 | while true; do | |
| 24 | - | #using --mirror causes errors when pushing, but --prune,--force, plus these refspecs should catch most stuff | |
| 25 | - | git push --force --prune "$PUSH_URL" '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' '+refs/change/*:refs/change/*' || true | |
| 22 | + | IFS="|" | |
| 23 | + | for PAIR in $PUSH_URLS; do | |
| 24 | + | #URL comes first, because they can't contain spaces, but directories can | |
| 25 | + | URL="$(echo $PAIR | cut -d ' ' -f 1)" | |
| 26 | + | DIR="$(echo $PAIR | cut -d ' ' -f 2-)" | |
| 27 | + | cd "$DIR" | |
| 28 | + | #using --mirror causes errors when pushing, but --prune,--force, plus these refspecs should catch most stuff | |
| 29 | + | git push --force --prune "$URL" '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' '+refs/change/*:refs/change/*' || true | |
| 30 | + | cd - > /dev/null | |
| 31 | + | done | |
| 26 | 32 | sleep "$PUSH_DELAY" | |
| 27 | 33 | done | |