Skip to content

Instantly share code, notes, and snippets.

View hongkongkiwi's full-sized avatar
🤓

Andy hongkongkiwi

🤓
View GitHub Profile
@hongkongkiwi
hongkongkiwi / pre-commit
Created March 2, 2020 08:23
Pre-commit hook to validate a .gitlab-ci.yml by uploading to gitlab server and validating using API
#!/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 March 2, 2020 07:25
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
#!/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 March 2, 2020 07:25
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
#!/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 March 2, 2020 07:25
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
#!/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 March 1, 2020 08:43
Bash script to download the latest Windows 10 ISO
#!/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 February 24, 2020 13:16
gitlab-ci.yml for building a docker image and pushing to a private gitlab registry
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
@hongkongkiwi
hongkongkiwi / gist:9d8691dae803f254e6591b9b8a29616b
Created February 23, 2020 13:04
Build Raspberry Pi Kernel
######################
### 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
@hongkongkiwi
hongkongkiwi / gist:ed8afee7ef53642c807b900f68a35aad
Created February 23, 2020 13:04
Build Raspberry Pi Kernel
######################
### 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
@hongkongkiwi
hongkongkiwi / trim
Created February 6, 2020 04:12
Simple trim script that can be used in pipes
#!/bin/sh
awk '{$1=$1};1'
@hongkongkiwi
hongkongkiwi / check_certificate
Created January 25, 2020 08:33
Bash script to check ssl certificate validity, also handles OCSP & CRL checking.
#!/bin/sh
OPENSSL_BIN="openssl"
CERT_NAME="$1"
# CERT_CHAIN=$(mktemp /tmp/output.XXXXXXXXXX) || { echo "Failed to create temp file"; exit 1; }
# CRL_DER_NAME=$(mktemp /tmp/output.XXXXXXXXXX) || { echo "Failed to create temp file"; exit 1; }
if [ "$(uname)" == "Darwin" ]; then
DATE_BIN="gdate"