Skip to content

Instantly share code, notes, and snippets.

View ThinGuy's full-sized avatar

craig bender ThinGuy

View GitHub Profile
@ThinGuy
ThinGuy / aws-ec2_metadata.txt
Created April 8, 2022 00:37
Metadata keys for AWS EC2
block-device-mapping/ami
block-device-mapping/ebsN
block-device-mapping/ephemeralN
block-device-mapping/root
block-device-mapping/swap
elastic-gpus/associations/elastic-gpu-id
elastic-inference/associations/eia-id
events/maintenance/history
events/maintenance/scheduled
events/recommendations/rebalance
@ThinGuy
ThinGuy / fbcon-show-rotation.sh
Created March 28, 2022 16:55
Linux console rotation
fbcon-show-rotation() {
(clear;printf "\n\nfbcon=rotate:0\t\tfbcon=rotate:1\tfbcon=rotate:2\t\tfbcon=rotate:3\n";(printf "\\u256D\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500T\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500\\u256E\t\\u256D\\u2500\\u2500\\u2500R\\u2500\\u2500\\u2500\\u256E\t\\u256D\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500B\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500\\u2500\\u256E\t\\u256D\\u2500\\u2500\\u2500L\\u2500\\u2500\\u2500\\u256E\n"; printf "\\u2502\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u2502\t\\u2502\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u2502\t\\u2502\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u2502\t\\u2502\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u2502\n"; printf "L\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\u200AR\t\\u2502\\u200A\\u200A\\u200A\\u200A\\u200A\\u200A\\
@ThinGuy
ThinGuy / apt-cloud-init.yaml
Last active March 29, 2022 23:04
Configuring APT with Cloud-Init - Examples standard cloud-init (public cloud, MAAS, etc), Juju, and LXD.
#cloud-config
## Writing out any credentials for private ppa access. If you need this configured early, use a bootcmd
## If can wait until the target environment is available, use a write_files:
bootcmd:
- ['cloud-init-per', 'once', 'apt1', 'echo', 'bWFjaGluZSBwcml2YXRlLXBwYS5sYXVuY2hwYWQubmV0L2Nhbm9uaWNhbC1rZXJuZWwtcnQvcmVsZWFzZS91YnVudHUgbG9naW4gamFuZS11c2VyIHBhc3N3b3JkICA2UFBSNzRwcU9SWElqc3JJczhBVwptYWNoaW5lIHByaXZhdGUtcHBhLmxhdW5jaHBhZC5uZXQvY2Fub25pY2FsLWtlcm5lbC1ydC9wcm9wb3NlZC91YnVudHUgbG9naW4gamFuZS11c2VyIHBhc3N3b3JkICBCRnBNc0RXZjVtV1lzU3cxUExRYwptYWNoaW5lIHByaXZhdGUtcHBhLmxhdW5jaHBhZC5uZXQvY3Jicy9zdGFibGUvdWJ1bnR1IGxvZ2luIGphbmUtdXNlciBwYXNzd29yZCAgUWZramZWWWNSSTVkR3VWYlhJb2gKbWFjaGluZSBwcml2YXRlLXBwYS5sYXVuY2hwYWQubmV0L3VidW50dS1hZHZhbnRhZ2Uvc2VjdXJpdHktYmVuY2htYXJrcy91YnVudHUgbG9naW4gamFuZS11c2VyIHBhc3N3b3JkICBhb3hMNHZlR0RGU1kwaGpWUUhHSAptYWNoaW5lIHByaXZhdGUtcHBhLmxhdW5jaHBhZC5uZXQvY3Jicy9zdGFibGUvdWJ1bnR1IGxvZ2luIGphbmUtdXNlciBwYXNzd29yZCAgdTBRRTNHTXZpR2RqTnB2NEx3aHUKbWFjaGluZSBwcml2YXRlLXBwYS5s
@ThinGuy
ThinGuy / htmltab.sh
Created January 31, 2022 02:44
Create csv (or "p"sv in this case) from an htmltabl using htmltab
sudo apt install pipx -yq
pipx install git+https://github.com/flother/htmltab
# Too many commas in table to make a CSV. Cleanup output and use pipes as the delimiter
(htmltab https://linux.dell.com/repo/community/openmanage|sed 's/,"|/|"/g;s/),"/)|/g;s/","/|/g;1s/,/|/g;s/,,/|/g;s/LTS,/LTS|/g;s/),v/)|v/g;s/),N/)|N/g;s/,\r$/|/g;s/(/ (/g')|tee ~/dell.psv
@ThinGuy
ThinGuy / dnsmasq.conf
Created January 30, 2022 01:00 — forked from j4zzcat/dnsmasq.conf
Preseed file for network console installation, ubuntu 19.10
interface=eth1
bind-interfaces
domain=pxe.local
dhcp-range=eth1,192.168.100.51,192.168.100.55,255.255.255.0,8h
dhcp-option=3,192.168.100.2 # gateway
dhcp-option=6,192.168.100.2 # dns
enable-tftp
tftp-root=/srv/tftp
dhcp-vendorclass=BIOS,PXEClient:Arch:00000
dhcp-vendorclass=UEFI32,PXEClient:Arch:00006
@ThinGuy
ThinGuy / ubuntu-disable-nm.sh
Created January 29, 2022 21:58
Disable NetworkManager
ubuntu-disable-nm() {
(systemctl list-unit-files Network* --legend=false --no-pager|awk '{print $1}')| \
xargs -rn1 -P0 sudo bash -c \
'systemctl stop $0;systemctl disable $0;systemctl mask $0;systemctl daemon-reload;systemctl reset-failed'
};export -f ubuntu-disable-nm
@ThinGuy
ThinGuy / get-priv-ppa-creds.py
Created January 28, 2022 03:08
Dump Private PPA URLs with credentials
#!/usr/bin/env python3
import sys
import codecs
import os
from urllib.parse import urlparse
from launchpadlib.launchpad import Launchpad
cachedir = "~/.launchpadlib/cache"
if sys.stdout.encoding is None:
sys.stdout = codecs.open("/dev/stdout", "w", 'utf-8')
@ThinGuy
ThinGuy / pg-size.sh
Created January 26, 2022 00:21
Dump all DB sizes in a given instance of postgresql (human readable + raw)
for DB in $(sudo -iu postgres psql -Atc '\l'| awk -F"|" '!/^=|^postgres=|template/{print $1}');do
export LLC="$(printf '\u2500')" SLONG=$(echo Database: ${DB}|wc -m)
printf "\n\e[1mDatabase:\e[0m ${DB}\n";
eval printf "%.3s" ${LLC}{0..$(echo ${SLONG})};echo;
sudo -iu postgres psql ${DB} -xtc \
'SELECT pg_size_pretty( pg_database_size( '"'"''${DB}''"'"' ) ) As human_size, pg_database_size( '"'"''${DB}''"'"' ) As raw_size;'
done
@ThinGuy
ThinGuy / pg-reindex-rest.sh
Last active April 13, 2022 21:07
Reindex schemas, db and system
###########################################################
# Reindex all indexes in the current instance of postgres #
###########################################################
(sudo -iu postgres psql -Atc 'SELECT tablename,indexname from pg_indexes ORDER BY tablename,indexname;')| \
awk -F"|" '{print $1,$2}'| \
xargs -rn2 -P1 bash -c \
'echo "Reindexing index $1 from table $0";sudo -iu postgres psql -c "REINDEX INDEX $1;"'
########################################################################################
# Reindex all indices in all tables in all databases in current instance of postgresql #
@ThinGuy
ThinGuy / pg-reindex-tables.sh
Created January 25, 2022 23:13
Reindex every psql table in a db
(sudo -iu postgres psql maasdb -Atc '\dt+;')| \
awk -F"|" 'NR>2{print $2}'| \
xargs -rn1 -P1 bash -c \
'sudo -iu postgres psql maasdb -c "REINDEX TABLE ${0}"'