Skip to content

Instantly share code, notes, and snippets.

View rgpower's full-sized avatar

Rick Power rgpower

  • Halifax, NS
View GitHub Profile
@rgpower
rgpower / dir2heredoc.sh
Created May 27, 2024 14:14
capture directory contents as heredoc(s) - shallow
# first argument to scritpt is directory, for example /etc/apt/sources.list.d
# output looks like:
# cat > /etc/apt/sources.list.d/trivy.sources <<EOF
#Types: deb
#URIs: https://aquasecurity.github.io/trivy-repo/deb
#Suites: jammy
#Components: main
#Aarch: amd64
#Signed-By: -----BEGIN PGP PUBLIC KEY BLOCK-----
# .
@rgpower
rgpower / delete-all-pdbs.sh
Created October 8, 2023 12:27
delete all pod disruption budges
for pdb in $(kubectl get pdb --all-namespaces -o json | \
jq -r '.items[] | select(.status.disruptionsAllowed<1) | [.metadata.namespace,.metadata.name] | join("/")'); \
do kubectl -n "${pdb%%/*}" delete pdb/"${pdb##*/}"; done
@rgpower
rgpower / fetch-azure-policy-meta.sh
Created October 19, 2022 15:51
Fetch Azure Policy Metadata, following paged responses
#!/bin/bash
i=0
done=0
url="https://management.azure.com/providers/Microsoft.PolicyInsights/policyMetadata?api-version=2019-10-01"
while [ $done -ne 1 ]
do
echo az rest --output-file "pm-${i}.json" --url "$url"
az rest --output-file "pm-${i}.json" --url "$url"
@rgpower
rgpower / jqmerge.sh
Created October 19, 2022 11:46
use jq to merge json files
# courtesy of Szymon Stepniak
# See https://e.printstacktrace.blog/merging-json-files-recursively-in-the-command-line/
jq -s 'def deepmerge(a;b):
reduce b[] as $item (a;
reduce ($item | keys_unsorted[]) as $key (.;
$item[$key] as $val | ($val | type) as $type | .[$key] = if ($type == "object") then
deepmerge({}; [if .[$key] == null then {} else .[$key] end, $val])
elif ($type == "array") then
(.[$key] + $val | unique)
else
@rgpower
rgpower / acrlogin.sh
Last active June 17, 2022 11:58
ACR login notes
# this only works on Linux if your $HOME/.docker/config.json has no "credsStore" entry
az acr login -n <registry> --expose-token --output tsv --query accessToken 2>/dev/null \
| docker login <registry-fqdn> --username 00000000-0000-0000-0000-000000000000 --password-stdin
@rgpower
rgpower / .npmrc
Created June 11, 2022 11:53
npm via artifactory
email=<corp-email-address>
always-auth=true
cafile=/usr/share/ca-certificates/corp-certs/corp-ca.crt
registry=https://artifactory.local/artifactory/api/npm/corp-npm-agg/
//artifactory.local/artifactory/api/npm/corp-npm-agg/:_authToken=<artifactory-api-token>
@rgpower
rgpower / verify_match_private_key_and_cert.sh
Created May 27, 2022 20:40
Verify that a given pkcs8 private key and certificate match
$ cat private-pkcs8.pem | openssl pkey -pubout -in - | openssl md5
(stdin)= 3b6b231d32d76732b76d04b1bcb53270
$ cat website.cer | openssl x509 -pubkey -noout -in - | openssl md5 # got the cer by copying from browser
(stdin)= 3b6b231d32d76732b76d04b1bcb53270
@rgpower
rgpower / setup_aks_cilium.sh
Last active November 15, 2022 06:08
Setup cilium on Azure AKS using user-assigned managed identity
#!/usr/bin/env bash
set -euo pipefail
AZURE_RESOURCE_GROUP=$1
CLUSTER_NAME=$2
LOCATION=$3
AZURE_NODEGROUP=$(az aks show -n ${CLUSTER_NAME} -g ${AZURE_RESOURCE_GROUP} -o tsv --query nodeResourceGroup)
@rgpower
rgpower / backup_and_restore_usage.sh
Created April 30, 2022 17:08
Postgres (PG) Backup and Restore: pg_dump and pg_restore usage
# backup
pg_dump -v -Fd -U $USER -f $DUMP_DIR $DB
# restore, doing required drops beforehand to avoid most constraint errors
pg_restore --verbose --clean --no-acl --no-owner -Fd -U $USER -d $DB $DUMP_DIR
@rgpower
rgpower / nodetaints.sh
Created April 29, 2022 15:30
Clear node taints from AKS node pool
#!/usr/bin/env bash
set -euo pipefail
RG=$1
AKS=$2
POOL=$3
SUB=$(az account show -o tsv --query id)