This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Create array of credentials and machines | |
declare -ag PPA_CREDS=(); | |
while IFS= read -er CRED;do | |
PPA_CREDS+=("${CRED}") | |
done < <(sudo awk '{print $4":"$6,$2}' /etc/apt/auth.conf.d/*) | |
# Look up matching matchines in apt sources files and insert matching credential | |
# then print apt source line with inserted credentials | |
printf "\n\e[1mCredentialed Apt Sources Lines:\e[0m\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following will exectute one or more curl commands that will test your credentialed access to | |
# various Ubuntu Advantage repositories that you are entitled to with your UA subscription. | |
sudo awk '{print $4":"$6,$2}' /etc/apt/auth.conf.d/90ubuntu-advantage|xargs -rn2 -P0 bash -c 'curl -sSlL -u ${0} https://${1}ubuntu/dists;echo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ -z ${1} || ${1} =~ -h ]] && { printf "\n\e[2GUsage: ${0##*/} <ip_address>\n\n";exit 2; } || { export STUCK_IP=${1}; } | |
# MAAS IP Address Allocation | |
# Type Name | |
# ━━━━ ━━━━ | |
# 0 AUTO | |
# 1 STICKY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pre-Depends: bsdextrautils, coreutils, findutils | |
(find /sys/devices -regextype "posix-extended" -maxdepth 6 -regex '.*drm/card[0-9]$' -printf "%p|" -o -regex '.*(DP|HDMI|DVI).*[0-9]$' -printf "%f\n"|\ | |
paste -sd,|\ | |
xargs -rn1 -P1 bash -c 'P=${0%%|*} C=${P##*/} CC=($(echo ${0##*|}|\ | |
sed "s/,/ /g")) | |
printf "Card,Port-Index,Connector,Status\n" | |
printf "${C},,,\n" | |
for con in ${CC[@]};do | |
(printf ",$(awk '"'"'{print $NF}'"'"' ${P}/${con}/ddc/name),${con#*-},$(cat ${P}/${con}/status)\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# vim: set et ts=2 sw=2 filetype=bash : | |
[[ $_ != $0 ]] || { printf "\n\e[2G\e[1mPlease source this script!\e[0m ( e.g. \"source ${BASH_SOURCE[0]}\" )\n\n"; sleep 1;exit; } | |
lxd2hosts() { | |
local DESC="\n${FUNCNAME}: Populate /etc/hosts with running LXD instances\n\n" | |
lxd2hosts_usage() { | |
printf "\n${DESC}\n" | |
printf "Usage: ${FUNCNAME%%_*} [ Options ] \n\n" | |
printf "\nOptions:\n\n" | |
printf "\e[2G -4|--ipv4\e[18GUpdate IPv4 section ( Default: true )\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maas-deploy-time() { | |
[[ -z ${1} || ${1} =~ -h ]] && { printf '\e[2G${FUNCNAME} <hostname>\e[0m\n\n' 1>&2; return 1; } || { local MAAS_NODE=${1}; } | |
local MAAS_DBCONN="$(sudo cat /var/snap/maas/current/regiond.conf|awk 'BEGIN{ RS = "" ; FS = ": |\n" }/database/{print "postgres://"$10":"$6"@"$2":"$8"/"$4}')" | |
local PG_OPTS='psql -F"|" -P pager=off -P footer=off' | |
psql ${MAAS_DBCONN} ${PG_OPTS} -Atc "SELECT DISTINCT EXTRACT(EPOCH FROM DATE_TRUNC('second',created)) as epoch,node_hostname,(description) FROM maasserver_event WHERE node_hostname LIKE '${MAAS_NODE}' AND description SIMILAR TO '(From%Ready%to%Allocated%|From%Deploying%to%Deployed%)' AND description NOT LIKE '' ORDER BY epoch DESC LIMIT 2"| \ | |
awk '{if (/Deployed/) {DV=$1;next};if (/Allocated/) {RV=$1;next}} END {EV=(DV-RV);min = (EV / 60)-((EV % 60)*1/60) ; sec = EV % 60 ; printf "%02dm:%02ds\n",min,sec}' | |
};export -f maas-deploy-time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#cloud-config | |
merge_how: | |
- name: list | |
settings: [append] | |
- name: dict | |
settings: [no_replace, recurse_list] | |
bootcmd: | |
- set -x | |
- cloud-init-per once env1 printf "export PATH=\x22/usr/local/bin\x3a/bin\x3a/usr/bin\x3a/usr/local/sbin\x3a/usr/sbin\x3a\x24HOME/.local/bin\x3a\x24HOME/bin\x3a/var/lib/snapd/snap/bin\x3a/snap/bin\x22"|tee 1>/dev/null /etc/environment | |
- cloud-init-per once yumup1 yum check-update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd ~ | |
sudo apt install libpq-dev -yq; | |
git clone https://github.com/aaparmeggiani/pg_tail; | |
cd pg_tail; | |
make; | |
sudo su - postgres -c '/home/ubuntu/pg_tail/pg_tail -d maasdb -t maasserver_event -c node_hostname,node_system_id,action,description,username'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
maas-show-events() { | |
maas-show-events_usage() { | |
printf "\n\e[2GUsage: ${FUNCNAME%%_*} -n <hostname> [options]\e[0m\n\n' 1>&2\n" | |
printf "\n\e[2GOptions:\n\n" | |
printf "\e[2G-n, --name\e[25GShow events for the given hostname\n\n" | |
printf "\e[2G-d, --desc\e[25GEvents listed in descending chronological order ( newest -> oldest )\n\n" | |
printf "\e[2G-h, --help\e[25GThis message\n\n" | |
printf "\n" | |
};export -f maas-show-events_usage | |
local MSEO='ASC' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This requires you to be logged into the MAAS cli, have jq and bsdextrautils installed | |
export MAAS_PROFILE=admin | |
maas-subnet-check() { | |
declare -ag COL_HEADERS=() COL_ULINES=() | |
while IFS= read -r C;do COL_HEADERS+=("${C}");done < <(printf "MAAS ID\nCIDR\nGateway\nDNS\nMAAS Vlan ID\nVlan Tag\nSpace\nDHCP Enabled\nExternal DHCP\nRelayed From\n") | |
while IFS= read -r U;do COL_ULINES+=("${U}");done < <(for H in "${COL_HEADERS[@]}";do eval printf '%.0s\\u2500' {1..${#H}}; echo;done) | |
printf "\n\e[0;38;2;0;200;0mMAAS Subnet Check:\e[0m\n\n"; | |
(for i in ${!COL_HEADERS[@]};do printf '%s\n' "${COL_HEADERS[i]}";done|paste -sd"|";for i in ${!COL_ULINES[@]};do printf '%s\n' "${COL_ULINES[i]}";done|paste -sd"|"; maas ${MAAS_PROFILE} subnets read|jq -r '.[]|"\(.id)|\(.cidr)|\(.gateway_ip|tostring|gsub("^null.*$";"unset"))|\(.dns_servers|@csv|gsub("^$";"unset")|gsub("\"";""))|\(.vlan.id)|\(.vlan.vid)|\(.space)|\(.vlan.dhcp_on)|\(.vlan.external_dhcp|tostring|gsub("^null.*$";"false"))|\(.vlan.relay_vlan|tostring|gsub("^ |