autopush.sh
| 1 | #!/bin/sh |
| 2 | set -e |
| 3 | if [ -z "$PUSH_KEY" ]; then |
| 4 | echo "Please set PUSH_KEY in .env" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
| 8 | if [ -z "$PUSH_DELAY" ]; then |
| 9 | echo "Please set PUSH_DELAY in .env to a string compatible with sleep(1)" |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
| 13 | if [ -z "$PUSH_URLS" ]; then |
| 14 | echo "Please set PUSH_URLS in .env" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | cd /git |
| 19 | #use global config to not modify the repository |
| 20 | git config --global core.sshCommand "/usr/bin/ssh -o 'StrictHostKeyChecking no' -i /ssh/$PUSH_KEY" |
| 21 | while true; do |
| 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 |
| 32 | sleep "$PUSH_DELAY" |
| 33 | done |
| 34 |