add readme, support multiple repositories
AREADME.md
@@ -0,0 +1,20 @@
# git-autopush
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
Example `docker run` command:
`docker run --rm --env-file .env -v ./ssh:/ssh:ro -v ./git:/git:ro "$(docker build -q .)"`
`./ssh` should contain your key for pushing
`./git` should contain the repositores you want to push
### .env parameters
* PUSH_KEY: file name of the private ssh key in the `ssh` directory to be used for pushing, e.g. `id_rsa`
* PUSH_DELAY: how long to sleep between pushes, should be a string compatible with sleep(1)
* PUSH_URLS: a `|` and `space` separated list of urls and directory names, e.g. `git@someserver:myrepo myrepo.git|git@someserver:myotherrepo myrepo2.git`
* `git@someserver:myrepo` and `git@someserver:myotherrepo` are the urls passed to git as a push destination
* `myrepo.git` and `myrepo2.git` are directory names relates to `/git` inside the container
### TODO
* allow custom refspecs to be added (for e.g. git-bug)
* port script to python and use json config instead of environment variables
DTODO.md-2
@@ -1,2 +0,0 @@
* allow custom refspecs to be added (for e.g. git-bug)
* allow multiple repositories
Mautopush.sh
@@ -10,18 +10,24 @@ if [ -z "$PUSH_DELAY" ]; then
exit 1
fi
if [ -z "$PUSH_URL" ]; then
echo "Please set PUSH_DELAY in .env to a string compatible with sleep(1)"
if [ -z "$PUSH_URLS" ]; then
echo "Please set PUSH_URLS in .env"
exit 1
fi
cd /git
git rev-parse --git-dir || (echo "No repository detected at /git" && exit 1)
#use global config to not modify the repository
git config --global core.sshCommand "/usr/bin/ssh -o 'StrictHostKeyChecking no' -i /ssh/$PUSH_KEY"
while true; do
#using --mirror causes errors when pushing, but --prune,--force, plus these refspecs should catch most stuff
git push --force --prune "$PUSH_URL" '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' '+refs/change/*:refs/change/*' || true
IFS="|"
for PAIR in $PUSH_URLS; do
#URL comes first, because they can't contain spaces, but directories can
URL="$(echo $PAIR | cut -d ' ' -f 1)"
DIR="$(echo $PAIR | cut -d ' ' -f 2-)"
cd "$DIR"
#using --mirror causes errors when pushing, but --prune,--force, plus these refspecs should catch most stuff
git push --force --prune "$URL" '+refs/heads/*:refs/heads/*' '+refs/tags/*:refs/tags/*' '+refs/change/*:refs/change/*' || true
cd - > /dev/null
done
sleep "$PUSH_DELAY"
done