Skip to content

Instantly share code, notes, and snippets.

Andy hongkongkiwi

View GitHub Profile
@hongkongkiwi
hongkongkiwi / add-ssh-hosts
Created Mar 13, 2020
Add keys to known hosts file for a list of domains.
View add-ssh-hosts
#!/usr/bin/env bash
SSH_SCAN_HOSTNAMES=${1:-"${SSH_SCAN_HOSTNAMES}"}
SSH_SCAN_HOSTNAMES=${SSH_SCAN_HOSTNAMES:-"github.com gitlab.com"}
SSH_DIR="$HOME/.ssh"
command -v ssh-keyscan >/dev/null 2>&1 || { echo >&2 "I require ssh-keygen but it's not installed. Aborting."; exit 1; }
command -v tee >/dev/null 2>&1 || { echo >&2 "I require tee but it's not installed. Aborting."; exit 1; }
for SSH_SCAN_HOSTNAME in $SSH_SCAN_HOSTNAMES; do
@hongkongkiwi
hongkongkiwi / update-mergerfs
Created Mar 7, 2020
Updates mergerfs to the latest version
View update-mergerfs
#!/usr/bin/env bash
# Read a single char from /dev/tty, prompting with "$*"
# Note: pressing enter will return a null string. Perhaps a version terminated with X and then remove it in caller?
# See https://unix.stackexchange.com/a/367880/143394 for dealing with multi-byte, etc.
function get_keypress {
local REPLY IFS=
>/dev/tty printf '%s' "$*"
[[ $ZSH_VERSION ]] && read -rk1 # Use -u0 to read from STDIN
# See https://unix.stackexchange.com/q/383197/143394 regarding '\n' -> ''
@hongkongkiwi
hongkongkiwi / pre-commit
Created Mar 2, 2020
Pre-commit hook to validate a .gitlab-ci.yml by uploading to gitlab server and validating using API
View pre-commit
#!/usr/bin/env bash
###########################
# Validate .gitlab-ci.yml #
# by Peter Weinert #
###########################
lif [[ "$OSTYPE" == "darwin"* ]]; then
SED_BIN="gsed"
command -v "gsed" >/dev/null 2>&1 || { echo >&2 "I require gsed but it's not installed. Install with 'brew install gnu-sed'. Aborting."; exit 1; }
@hongkongkiwi
hongkongkiwi / update-docker-machine
Created Mar 2, 2020
Helper script to update docker-machine to latest version from github. Could be run in cron if you want to keep up to date. Can modify to be applicable to any app
View update-docker-machine
#!/usr/bin/env bash
[ "$EUID" -ne 0 ] && { echo >&2 "Please run as root or with sudo"; exit 2; }
INSTALL_LOCATION="/usr/local/bin/docker-machine"
REPO=docker/machine
VERSION=`curl -s "https://github.com/${REPO}/releases/latest/download" 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+`
[ -z "$VERSION" ] && echo >&2 "Could not get latest version from ${REPO}!"
if command -v docker-machine >/dev/null 2>&1; then
@hongkongkiwi
hongkongkiwi / update-docker-machine
Created Mar 2, 2020
Helper script to update docker-machine to latest version from github. Could be run in cron if you want to keep up to date. Can modify to be applicable to any app
View update-docker-machine
#!/usr/bin/env bash
[ "$EUID" -ne 0 ] && { echo >&2 "Please run as root or with sudo"; exit 2; }
INSTALL_LOCATION="/usr/local/bin/docker-machine"
REPO=docker/machine
VERSION=`curl -s "https://github.com/${REPO}/releases/latest/download" 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+`
[ -z "$VERSION" ] && echo >&2 "Could not get latest version from ${REPO}!"
if command -v docker-machine >/dev/null 2>&1; then
@hongkongkiwi
hongkongkiwi / update-docker-machine
Created Mar 2, 2020
Helper script to update docker-machine to latest version from github. Could be run in cron if you want to keep up to date. Can modify to be applicable to any app
View update-docker-machine
#!/usr/bin/env bash
[ "$EUID" -ne 0 ] && { echo >&2 "Please run as root or with sudo"; exit 2; }
INSTALL_LOCATION="/usr/local/bin/docker-machine"
REPO=docker/machine
VERSION=`curl -s "https://github.com/${REPO}/releases/latest/download" 2>&1 | grep -Po [0-9]+\.[0-9]+\.[0-9]+`
[ -z "$VERSION" ] && echo >&2 "Could not get latest version from ${REPO}!"
if command -v docker-machine >/dev/null 2>&1; then
@hongkongkiwi
hongkongkiwi / download-windows-10.sh
Created Mar 1, 2020
Bash script to download the latest Windows 10 ISO
View download-windows-10.sh
#!/usr/bin/env bash
LANG_CODE="en"
LANG_NAME="English"
ARCH="x64"
OUTPUT_DIR="/tmp"
# Get Lock so we can only have one instance of this script running
exec {lock_fd}>"/var/lock/`basename "$0"`" || exit 1
flock -n "$lock_fd" || { echo "ERROR: flock() failed." >&2; exit 1; }
@hongkongkiwi
hongkongkiwi / gist:599d263db1128c91cd3b4ebf7522ad32
Created Feb 24, 2020
gitlab-ci.yml for building a docker image and pushing to a private gitlab registry
View gist:599d263db1128c91cd3b4ebf7522ad32
image: docker:19.03.1
before_script:
- docker info
- echo "$CI_REGISTRY_PASSWORD" | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
build_image:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
View gist:9d8691dae803f254e6591b9b8a29616b
######################
### Kernel headers ###
######################
#To build this module from source, I did the following on my RPI2.
#Install build tools:
sudo -s
apt install build-essential bc git wget
View gist:ed8afee7ef53642c807b900f68a35aad
######################
### Kernel headers ###
######################
#To build this module from source, I did the following on my RPI2.
#Install build tools:
sudo -s
apt install build-essential bc git wget
You can’t perform that action at this time.