Skip to content

Instantly share code, notes, and snippets.

@ThinGuy
ThinGuy / unicode-spaces.sh
Last active April 4, 2018 12:53
Show difference of unicode spacing options on characters (If you are using a monospace font, this will be a waste of time)
#If you are using a monospace font, this will be a waste of time
unicode-space-test() {
declare -ag SPACE_ARRAY=(
'\u0020|SPACE|Typically 1/4 EM; Adjusted depending on font.'
'\u00A0|NO-BREAK SPACE|As a space; Often not adjusted.'
'\u1680|OGHAM SPACE MARK|Usually not really a space but a dash.'
'\u180E|MONGOLIAN VOWEL SEPARATOR|No width space.'
'\u2000|EN QUAD|1 EN; Fixed-width.'
'\u2001|EM QUAD|1 EM (nominally; the height of the font); Fixed-width.'
'\u2002|EN SPACE|1 EN; Fixed-width.'
@ThinGuy
ThinGuy / ob-os-sanity.sh
Created March 8, 2018 17:55
Openstack OrangeBox Sanity Test
#!/bin/bash
#Script to configure openstack on Orangebox
[[ ${HOSTNAME,,} =~ orangebox ]] && export OB_NUM=$((10#${HOSTNAME:9})) || OB_NUM=20
#Networking Variables - External will be provider, Int will be tenant
export NEUTRON_DNS1="172.27.$((${OB_NUM})).1"
export NEUTRON_DNS2="172.27.$((${OB_NUM}+2)).1"
export NEUTRON_DNS3="172.27.$((${OB_NUM}+3)).254"
@ThinGuy
ThinGuy / private-sks-lxd.sh
Last active April 6, 2018 06:13
Build a private keyserver in a LXD container
#!/bin/bash
#Small function to give text status of OK/FAIL to commands
tstatus() {
RETCODE=$(echo $?)
[[ $RETCODE -eq 0 ]] && printf '\e['$(($(tput cols)-10))'G [ \e[32mOK\e[0m ]\n'
[[ $RETCODE -eq 1 ]] && printf '\e['$(($(tput cols)-10))'G [\e[31mFAIL\e[0m]\n'
return $RETCODE
}
@ThinGuy
ThinGuy / random-ipv6-range.sh
Last active March 16, 2018 13:40
Function to create a range of IPv6 addresses based off a randomly generated MAC address
random-ipv6-range() {
local DESC="\e[1m${FUNCNAME}: Create a sequential range of IP addresses\e[0m\n"
[[ $1 = '--desc' ]] && { printf "${DESC}";return; }
random-ipv6-range_usage() {
printf "\n${DESC}\n"
printf "\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n\n"
printf "\e[2GOptions:\n"
printf "\e[4G -c, --count \e[24GNumber of IPv6 addresses to include in the range\n"
@ThinGuy
ThinGuy / increment-mac.sh
Created March 16, 2018 13:44
Function to increment increment a provide MAC address (or use autogenerated MAC)
increment-mac() {
local DESC="\e[1m${FUNCNAME}: Prints incrementing MAC address numbers\e[0m\n"
[[ $1 = '--desc' ]] && { printf "${DESC}";return; }
increment-mac_usage() {
printf "\n${DESC}\n"
printf "\e[2GUsage: ${FUNCNAME%%_*} [OPTIONS]\n\n"
printf "\e[2GOptions:\n"
printf "\e[4G -c, --count \e[20GNumber of MAC address to print\n"
@ThinGuy
ThinGuy / multihost-wc-ssl.sh
Last active October 5, 2020 05:25
Self Signed Cert Script - multi-host, multi-ip, multi-domain, and wilcard certs
#!/usr/bin/env bash
# vim: set et ts=2 sw=2 filetype=bash :
#
# Copyright (C) 2020 Craig Bender
#
# Author(s): Craig Bender <19372989+ThinGuy@users.noreply.github.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ThinGuy
ThinGuy / juju-openstack-upgrade.sh
Created March 22, 2018 00:35
Rolling Openstack Upgrade with Juju
juju-upgrade-openstack() {
export SERIES=xenial
export RELEASE=pike
export CURRENT_MODEL=$(juju models|awk '/*/{gsub(/*/,"");print $1}')
printf "\e[2GGetting list of applications from juju model \"${CURRENT_MODEL}\" \n"
declare -ag JUJU_APPS=($(juju 2>/dev/null status --format=json|jq 2>/dev/null -r '.applications | to_entries[].key'))
printf "%s\n" ${JUJU_APPS[@]}
printf "\e[2GGetting list of openstack applications from juju model \"${CURRENT_MODEL}\" \n"
declare -ag UPGRADE_APPS=($(for APP in ${JUJU_APPS[@]};do [[ -n $(juju 2>/dev/null config ${APP} action-managed-upgrade) ]] && echo ${APP};done))
printf "%s\n" ${UPGRADE_APPS[@]}
@ThinGuy
ThinGuy / fix-deployed-dns-search.sh
Last active April 2, 2018 11:27
Change dns-search paramater laid down by juju
#If populating MAAS DNS with domains, all domains get added to the search order.
#Resolv.conf only supports 6, so if you have more 6 domains entered, nothing after the 6th gets resolved
#Also, juju for some reason is doing an alpha sort on domain, which in most cases (and in the case of http://launchpad.net/opm) puts
#the MAAS domain near the end, which is past the 6th domain.
#This function will go through all machines and containers in a model and set a given search order, or
#if used without arguments will set the maas domain as the only entry in dns-search
fix-deployed-dns-search() {
@ThinGuy
ThinGuy / show-ssl-san-entries
Last active April 13, 2022 21:06
Print all Subject Alternate Name (SAN) entries in a X509 cert (both hostname and IP addresses)
openssl x509 -in ${CERT} -noout -text|grep -oP '(?<=DNS:|IP Address:)[^,]+'|sort -uV
# Or as a function
show-cert-sans() {
[[ -z ${1} || ${1} =~ ^- ]] && { printf "Usage: ${FUNCNAME} </path/to/ssl/cert>\n";return 2; } || true
[[ -e ${1} ]] || { printf "Can't find SSL Certificate ${1}\n";return 1; }
openssl x509 -in ${1} -noout -text|grep -oP '(?<=DNS:|IP Address:)[^,]+'|sort -uV
}
@ThinGuy
ThinGuy / check-cert
Created April 3, 2018 14:42
Function to list all or specific entries in an x509 certficate
check-cert() {
local DESC="${RO}${FUNCNAME}${RT}: Show which hostnames/ip addresses are listed in Subject Alternate Names (SAN) in a given x509 certifcate\n"
[[ $1 = '--desc' ]] && { printf "${DESC}";return; }
check-cert_usage() {
printf "\n\e[2GUsage: ${RO}${FUNCNAME%%_*} ${RT} -c,--cert </path/to/x509/certificate> [OPTIONS] ${RT}\n"
printf "\e[4G${RO} -c${RT},${RO}--c\e[20G${RT}Path to x509 certificate (Required)\n"
printf "\e[4G${RO} -a${RT},${RO}--all\e[20G${RT}Show all hostnames and ip addresses covered by the provided certificate\n"
printf "\e[4G${RO} -h${RT},${RO}--host\e[20G${RT}Provide a specific hostname to check (or \"all\" to show all hostnames)\n"
printf "\e[4G${RO} -i${RT},${RO}--IP\e[20G${RT}Provide a specific IP address to check (or \"all\" to show all IP addresses)\n"
echo