warbo-utilities: 804734aac01859c2515b7d51c5dd6981126526d2

     1: #! /usr/bin/env nix-shell
     2: #! nix-shell -i bash -p bash git2html parallel
     3: 
     4: echo "Putting hooks in place"
     5: for repo in *.git
     6: do
     7:     HOOK="$repo/hooks/post-receive"
     8:     # This should be a symlink to post-receive.hook, or otherwise run it
     9:     if [ -h "$HOOK" ]
    10:     then
    11:         true  # OK
    12:     elif [ -f "$HOOK" ]
    13:     then
    14:         grep -q 'post-receive.hook' < "$HOOK" ||
    15:             echo "$HOOK should run ../post-receive.hook (or symlink to it)" 1>&2
    16:     else
    17:         (cd "$repo/hooks" && ln -s ../../post-receive.hook post-receive)
    18:     fi
    19: done
    20: 
    21: echo "Checking connection to chriswarbo.net"
    22: if ssh -q chriswarbo.net exit
    23: then
    24:     echo "Copying repos to chriswarbo.net"
    25:     REMOTE=$(ssh chriswarbo.net "ls /opt/repos/")
    26:     for repo in *.git
    27:     do
    28:         if ! echo "$REMOTE" | grep -q "^$repo$"
    29:         then
    30:             echo "Can't find $repo on remote server, copying..."
    31:             tar c "$repo" | gzip - | ssh chriswarbo.net "cd /opt/repos; tar xz"
    32:         fi
    33:     done
    34: fi
    35: 
    36: for repo in *.git
    37: do
    38:     pushd "$repo" > /dev/null || exit 1
    39:     git config --get remote.origin.fetch && {
    40:         echo "Removing fetch refs from '$repo'" >> /dev/stderr
    41:         git config --unset remote.origin.fetch
    42:     }
    43: 
    44:     git config --get remote.origin.mirror && {
    45:         echo "Removing mirror status of '$repo'" >> /dev/stderr
    46:         git config --unset remote.origin.mirror
    47:     }
    48:     popd > /dev/null || exit 1
    49: done
    50: 
    51: # Since these hooks will try pushing changes to remote repos, even if there are
    52: # no changes it can still take a long time to wait for all of the connections to
    53: # be established.
    54: # By running in parallel, these waiting times can be overlapped, resulting in
    55: # less idle time.
    56: # However, we don't want to abuse remote services by attempting hundreds of
    57: # simultaneous connections, so rather than forking with `&` we use `sem` from
    58: # GNU parallel to prevent more than 8 tasks from running at once.
    59: echo "Running hooks in parallel"
    60: 
    61: nix-shell -p parallel -p bash --run bash << 'EOF'
    62: for repo in *.git
    63: do
    64:     pushd "$repo" > /dev/null
    65:     chmod +x hooks/post-receive
    66:     sem --will-cite -j 8 sh hooks/post-receive
    67:     popd > /dev/null
    68: done
    69: sem --will-cite --wait
    70: EOF
    71: 
    72: echo "Running checks on remote"
    73: ssh chriswarbo.net 'cd /opt/repos; sh check.sh'

Generated by git2html.