Skip to content

Instantly share code, notes, and snippets.

@nhoag
nhoag / dyn-menu.sh
Last active October 16, 2020 17:46
Dynamic menu in bash
#!/bin/bash
ENTITIES=$(ls -1)
SELECTION=1
while read -r line; do
echo "$SELECTION) $line"
((SELECTION++))
done <<< "$ENTITIES"
@nhoag
nhoag / sphp.sh
Last active May 7, 2019 19:26 — forked from w00fz/sphp.sh
PHP switcher
#!/bin/bash
# Check if command was run as root.
if [[ $(id -u) -eq 0 ]]; then
echo "The command \"sphp\" should not be executed as root or via sudo directly."
echo "When a service requires root access, you will be prompted for a password as needed."
exit 1
fi
# Usage
@nhoag
nhoag / autokey-acquia.sh
Last active January 22, 2017 13:26
Auto-handling of ssh keys for Acquia Hosting
#!/bin/bash
# Acquia
CLOUDAPI_ID='id'
CLOUDAPI_KEY='key'
DOCROOT="docroot"
CREDS="${CLOUDAPI_ID}:${CLOUDAPI_KEY}"
ssh-keygen -q -b 4096 -t rsa -N "" -f ./script.key
@nhoag
nhoag / pre-push.sh
Created September 6, 2016 18:00 — forked from pixelhandler/pre-push.sh
Git pre-push hook to prevent force pushing master branch
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. Copy the file into your repo at `.git/hooks/pre-push`
# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
@nhoag
nhoag / git-large-humanized.sh
Created November 20, 2015 03:18
Return a list of the largest objects in a Git repo in a human-readable format
#!/bin/bash
HASHES_SIZES=$(git verify-pack -v .git/objects/pack/pack-*.idx \
| sort -k 3 -rn \
| head -20 \
| awk '{print $1,$3}' \
| sort)
HASHES=$(echo "$HASHES_SIZES" \
| awk '{printf $1"|"}' \
| sed 's/\|$//')
@nhoag
nhoag / 9191_config.php
Created February 4, 2016 15:43
This is a sample addition to the config.php for SimpleSAMLphp for Acquia Cloud.
<?php
// All custom changes below. Modify as needed.
// Defines account specific settings.
// $ah_options['database_name'] should be the Acquia Cloud workflow database name which
// will store SAML session information.set
// You can use any database that you have defined in your workflow.
// Use the database "role" without the stage ("dev", "stage", or "test", etc.)
$ah_options = array(
'database_name' => 'mydatabasename',
'session_store' => array(
@nhoag
nhoag / bandwidth-per-min.sh
Created December 23, 2015 18:55
Calculate bandwidth per minute from access log
#!/bin/bash
cat access.log \
| awk -F' ' '{
time = substr($4, 2, 17);
times[time] = time;
bandwidth[time] += $10
} END {
for (t in times) print times[t],bandwidth[t]/1024/1024
}' \
@nhoag
nhoag / bash-boilerplate.sh
Last active January 16, 2016 02:12
Bash Script Boilerplate
#!/bin/bash
set -a ; set -o errexit ; set -o nounset
function usage() {
cat <<EOF
Usage: ${0} ARG
OPTIONS:
-h Show usage
EOF
@nhoag
nhoag / gpg-import-and-export-instructions.md
Created January 2, 2016 14:19 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

@nhoag
nhoag / migrate-git.sh
Created January 31, 2013 17:27
Migrate a Git repo. Original: https://gist.github.com/4593250
#!/bin/bash
src_git="$1"
dst_git="$2"
git clone --mirror ${src_git} migrate
cd migrate
git remote add dst ${dst_git}
git push --mirror dst
cd ..