aboutsummaryrefslogtreecommitdiff
path: root/packages/crashbox-config/git/usr/bin/gh-mirror
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2018-12-04 21:31:01 -0800
committerJakob Odersky <jakob@odersky.com>2018-12-04 21:39:07 -0800
commit9588e9366d3455f203e5482a41f712777595bb13 (patch)
tree272aeababb1b68f477301d67198a82c80d044c01 /packages/crashbox-config/git/usr/bin/gh-mirror
parentdb27247dd7d7209ab93419eb33d2ecb21e74c1ec (diff)
downloadinfra-9588e9366d3455f203e5482a41f712777595bb13.tar.gz
infra-9588e9366d3455f203e5482a41f712777595bb13.tar.bz2
infra-9588e9366d3455f203e5482a41f712777595bb13.zip
Simplify terraform and provisioning scripts. Move away from config packages.
Diffstat (limited to 'packages/crashbox-config/git/usr/bin/gh-mirror')
-rwxr-xr-xpackages/crashbox-config/git/usr/bin/gh-mirror59
1 files changed, 0 insertions, 59 deletions
diff --git a/packages/crashbox-config/git/usr/bin/gh-mirror b/packages/crashbox-config/git/usr/bin/gh-mirror
deleted file mode 100755
index 54985cb..0000000
--- a/packages/crashbox-config/git/usr/bin/gh-mirror
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/bash
-# Mirror repositories from GitHub
-#
-# Arguments: (users|orgs) <name> <output_directory>
-#
-# Clones (or updates) all repositories of a GitHub user or
-# organization. Repositories are created as children of the given
-# output directory.
-#
-# Example:
-# gh-mirror users jodersky mirrors/github/jodersky
-#
-# This script uses GitHub's API, version 3
-# https://developer.github.com/v3/repos/#list-user-repositories
-set -o errexit
-
-account_type="$1"
-account_name="$2"
-out_dir="${3:-.}"
-mkdir -p "$out_dir"
-
-if [[ -z $account_type ]] || [[ -z $account_name ]]; then
- echo "Usage: (users|orgs) <name> <output_directory>" >&2
- exit 1
-fi
-
-tmp="$(mktemp /tmp/mirror-XXXXXXXXXXXX)"
-url="https://api.github.com/$account_type/$account_name/repos?per_page=100"
-
-function finish {
- echo "An error was encountered." >&2
- echo "curl headers are saved in $tmp" >&2
-}
-trap finish ERR
-
-while [[ ! -z "$url" ]]; do
- echo "Fetching $url..." >&2
-
- mapfile -t repo_data < <(curl --dump-header "$tmp" "$url" | jq --compact-output '.[]')
- url="$(< "$tmp" grep Link | grep -oE "[a-zA-Z0-9:/?=.&_]*>; rel=.next" | cut -d'>' -f1)"
-
- for repo in "${repo_data[@]}"; do
- clone_url="$(echo "$repo" | jq -r .clone_url)"
- project="$(basename "$clone_url")"
- description=$(echo "$repo" | jq -r .description)
-
- git_dir="$out_dir/$project"
-
- if [ -d "$git_dir" ]; then
- echo "updating $project" >&2
- git -C "$git_dir" fetch --prune
- else
- echo "mirroring new $project" >&2
- git clone --mirror "$clone_url" "$git_dir"
- fi
- echo "$description" > "$git_dir/description"
- done
-done
-rm "$tmp"