Created
July 18, 2019 03:12
-
-
Save joshuaspence/d7a406435de8216b389ed4589d80264b to your computer and use it in GitHub Desktop.
Random scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
set -o nounset | |
set -o pipefail | |
# Create a temporary directory. | |
SCRATCH_DIR=$(mktemp --directory) | |
function cleanup() { | |
echo "Deleting scratch directory: ${SCRATCH_DIR}" | |
rm --recursive --force "${SCRATCH_DIR}" | |
} | |
trap cleanup EXIT | |
# Create a self-signed certificate. | |
openssl req \ | |
-out "${SCRATCH_DIR}/cert.pem" \ | |
-keyout "${SCRATCH_DIR}/key.pem" \ | |
-nodes \ | |
-newkey rsa:4096 \ | |
-x509 \ | |
-subj "/C=AU/ST=New South Wales/L=Sydney/O=None/CN=${1}" \ | |
-days 365 | |
aws iam upload-server-certificate \ | |
--server-certificate-name "${1}-$(date +%s)" \ | |
--certificate-body "file://${SCRATCH_DIR}/cert.pem" \ | |
--private-key "file://${SCRATCH_DIR}/key.pem" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o nounset | |
set -o pipefail | |
git fetch &> /dev/null | |
for REMOTE_BRANCH in $(git branch --no-color --remotes | grep --invert-match HEAD | sort --random-sort); do | |
clear | |
# Ignore branches that have been updated recently. | |
if [[ "$(git log --since='1 week ago' --pretty=oneline "${REMOTE_BRANCH}" | wc --lines)" -gt 0 ]]; then | |
continue | |
fi | |
IFS=/ read REMOTE BRANCH <<< "${REMOTE_BRANCH}" | |
# Never delete the master branch. | |
if [[ $BRANCH == 'master' ]]; then | |
continue | |
fi | |
# Show the branch. | |
git --no-pager show "${REMOTE_BRANCH}" | |
read -p "Delete branch '${BRANCH}'? " -n 1 -r | |
echo | |
if [[ "${REPLY}" =~ ^[Yy]$ ]]; then | |
git push "${REMOTE}" ":${BRANCH}" | |
fi | |
done | |
git unfuck |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment