aboutsummaryrefslogblamecommitdiff
path: root/roles/git/files/runner-mirror/mirror.sh
blob: a517b86b798ae7b47d8e25b1cf3a991b6e5f0207 (plain) (tree)
































                                                                       
#!/bin/sh

function mirror() {
    local repo=$1

    if [ ! -d $repo ]; then
        git clone --mirror https://github.com/johannst/$repo
    else
        git -C $repo fetch --all --prune
    fi

    git -C $repo push --mirror ssh://git.memzero.de/mirror/$repo
}

function lock() {
    # Open lock file.
    exec 42<> /tmp/mirror.lock
    # Get exclusive lock.
    flock -x 42
    # Automatically unlock on exit.
    trap "flock -u 42" EXIT
}

# Ensure only a single script instance runs at a time.
lock

mkdir -p mirrors
pushd mirrors

for R in $(cat /projects.list | awk -F '/' '/mirror/ { print $2 }'); do
    echo "==> REPO: $R"
    mirror $R
done