Skip to content

Instantly share code, notes, and snippets.

@larsxschneider
Created March 6, 2018 18:58
Show Gist options
  • Save larsxschneider/58c824caf47a8271ee9485a2ef329212 to your computer and use it in GitHub Desktop.
Save larsxschneider/58c824caf47a8271ee9485a2ef329212 to your computer and use it in GitHub Desktop.
Run git-sizer on all repositories of a GitHub Enterprise appliance.
#!/usr/bin/env bash
#
# Run git-sizer (https://github.com/github/git-sizer) on all
# repositories of a GitHub Enterprise appliance.
#
# Attention:
# This script is not supported by or affiliated with GitHub. Use it at
# your own risk! The author assumes no responsibility for any data loss
# or hardship incurred directly or indirectly by using it.
# !!! DO NOT RUN THIS SCRIPT ON YOUR PRODUCTION APPLIANCE !!!
#
# Usage:
# 1. SSH into the administrative shell of your GitHub Enterprise appliance
# 2. Download the "linux-amd64" version of git-sizer, unzip it, and
# place it in /home/admin/bin/git-sizer
# 3. Downlad this script to /home/admin/bin/ghe-sizer.sh
# 4. Run `sudo /home/admin/bin/ghe-sizer.sh &`
# 5. Wait... until the file /data/user/tmp/sizer-results/done appears
# 6. Inspect /data/user/tmp/sizer-results/results to see the results.
# Inspect /data/user/tmp/sizer-results/failures to see the failures.
#
GIT_SIZER=/home/admin/bin/git-sizer
RESULT_DIR=/data/user/tmp/sizer-results
read -r -d '' RUN<<EOF
REPO={};
NETWORK=\$(basename \$(dirname \$REPO));
cd \$REPO;
$GIT_SIZER >$RESULT_DIR/\$NETWORK || echo \$REPO >>$RESULT_DIR/failures;
EOF
mkdir -p "$RESULT_DIR"
find /data/repositories/ \
-mindepth 7 \
-maxdepth 7 \
-type d \
-not -path '*/gist/*' -and \
-not -path '*.wiki.git' -and \
-path '*/network.git' \
| split -l 100 --filter "parallel -i sh -c '$RUN' -- \$(dd 2> /dev/null)"
egrep -l '\!{7,}|\*{7,}' "$RESULT_DIR"/* \
| while read f; do \
NETWORK_ID=$(basename "$f"); \
REPO_NAME=$(echo " \
SELECT CONCAT(users.login, \"/\", repositories.name) \
FROM repository_networks, repositories, users \
WHERE repository_networks.id = $NETWORK_ID AND \
repository_networks.root_id = repositories.id AND \
repositories.owner_id = users.id;" \
| ghe-dbconsole -y 2>&1 | sed '1,2d')
printf "\n\n###\n### REPO: $REPO_NAME\n###\n\n"; \
cat "$f"; \
done >"$RESULT_DIR/results"
> "$RESULT_DIR/done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment