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