Skip to content

Instantly share code, notes, and snippets.

View ThinGuy's full-sized avatar

craig bender ThinGuy

View GitHub Profile
@ThinGuy
ThinGuy / snap-refresh.sh
Last active October 5, 2018 15:58
Update all snaps in parallel
# This command will refresh all installed snaps in parallel.
# If snap was installed with classic confinment, but snap list
# does not report that fact, just put that snap in the first awk
# if statement (pipe separated)
snap list|awk '/^[a-z]/{if (/classic|charm/) print $1 " --classic";if (!/classic/) print $1}'|xargs -L1 -P0 sudo snap refresh
@ThinGuy
ThinGuy / spacer.sh
Last active October 7, 2018 00:56
small function to create n spaces between words. Useful with utils like sed/awk/cat
sp() { printf "%0.0s " $(seq 1 $1); }
Example:
# Say you need to add two lines near the end of /etc/security/limits.conf
Orig file:
#<domain> <type> <item> <value>
#
#* soft core 0
#root hard core 100000
@ThinGuy
ThinGuy / kbd-backlight.sh
Last active October 7, 2018 07:13
Set keyboard backlight brightness at startup via a systemd service
#!/bin/bash
# This script creates a systemd service to turn up
# the keyboard backlight at startup as it's not
# respecting the last setting
# In order to do this, we have to change the perms,
# then echo a value into the brightness file.
# The latter has to be done via a script as just
# running the echo from systemd does not work.
@ThinGuy
ThinGuy / maas-mass-vlan+sn-add
Last active November 25, 2019 16:42
Adding and deleting maas subnets and vlans in parallel from a csv file
#Consider we have the following csv and we want to use it to create subnets and vlans in MAAS using the cli
VLAN (name+tag),cidr,subnet name
v501,10.183.128.0/24,fa-POD5-v501
v503,10.183.129.0/24,fa-POD5-v503
v505,10.183.130.0/24,fa-POD5-v505
v507,10.183.131.0/24,fa-POD5-v507
v509,10.183.132.0/24,fa-POD5-v509
v511,10.183.133.0/24,fa-POD5-v511
v513,10.183.134.0/24,fa-POD5-v513
@ThinGuy
ThinGuy / lxd-p2c_centos7.sh
Created October 16, 2018 14:58
Build lxd-p2c on CentOS7
#### Run commands as root, not via sudo ####
sudo su -
yum --enablerepo="base" -y install yum-utils
yum install yum-plugin-copr epel-release -y
yum install wget curl sqlite-devel dnsmasq squashfs-tools libacl-devel python-pthreading glibc-utils glibc-devel glibc-headers glibc-static rsync librsync librsync-devel -y
yum groupinstall "Development Tools" "Development Libraries" -y
wget -O go1.11.1.linux-amd64.tar.gz https://dl.google.com/go/go1.11.1.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.11.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
@ThinGuy
ThinGuy / show-maas-boot.sh
Created October 22, 2018 16:28
Determine if MAAS machine booted UEFI or BIOS (Linux)
#!/bin/bash
command -v jq &>/dev/null || sudo apt install jq -yqq
(maas admin machines read|jq -r '.[]|select(.status_name=="Deployed").hostname')| \
xargs -n1 -P0 bash -c 'ssh $0 '"'"'printf "$HOSTNAME: " && [[ -d /sys/firmware/efi ]] && echo UEFI || echo BIOS'"'"''
@ThinGuy
ThinGuy / download_splunk.sh
Last active December 2, 2024 21:41
Download latest Splunk Platform and Universal Forwarder files without having to login
#TODO: Create exclude args for platforms
download-splunk() {
# Where to store the platform and forwarder packages
local SPLUNK_BIN_DIR=/srv/splunk-platform
local SPLUNK_UF_DIR=/srv/splunk-uf
[[ -d ${SPLUNK_BIN_DIR} ]] || mkdir -p ${SPLUNK_BIN_DIR}
[[ -d ${SPLUNK_UF_DIR} ]] || mkdir -p ${SPLUNK_UF_DIR}
CLASS|FLAG|DESC
AMD-EXTENDED|3dnowprefetch|3DNow prefetch instructions
AMD-EXTENDED|abm|Advanced bit manipulation
AMD-EXTENDED|bpext|Data breakpoint extension
AMD-EXTENDED|cmp_legacy|If yes HyperThreading not valid
AMD-EXTENDED|cr8_legacy|CR8 in
AMD-EXTENDED|extapic|Extended APIC space
AMD-EXTENDED|fma4|4 operands MAC instructions
AMD-EXTENDED|ibs|Instruction Based Sampling
AMD-EXTENDED|lahf_lm|LAHF/SAHF in long mode
@ThinGuy
ThinGuy / show-cpu-flags
Last active April 13, 2022 21:08
Display CPU Flags in a nicely formatted table
#Using table here: https://bit.ly/gh-cpu-flags
show-common-cpu-flags() {
declare -ag COL_LEN=($(wget -qO- http://bit.ly/cpu_flags|awk -F\| 'BEGIN { NR==1;getline; H1=$1; H2=$2; H3=$3 } { for (i=1; i<=NF; i++) { max[i] = length($i) > max[i] ? length($i) : max[i] ;ncols = i > ncols ? i : ncols }} END { {print H2":"max[2]"\n"H3":"max[3]"\n"H1":"max[1]"\n"}}'))
export LS='─'
(printf "%s\n" ${COL_LEN[@]%%:*}|paste -sd\| && printf "%s\n" ${COL_LEN[@]##*:}|xargs -n1 bash -c 'eval printf "%.3s" ${LS}{1..${0}};echo'|paste -sd"|"
wget -qO- http://bit.ly/cpu_flags|awk -F\| '/AMD-EXTENDED\||AMD\||INTEL\||V12N\|/{print $2"|"$3"|"$1}')|column -nexts'|'|sed '1,2s/.*$/'$(printf "\e[1m")'&'$(printf "\e[0m")'/'
}
show-all-cpu-flags() {
@ThinGuy
ThinGuy / vzwlshw.xml
Created November 6, 2018 03:57
lshw with GPUs
<?xml version="1.0" standalone="yes" ?>
<!-- generated by lshw-B.02.17 -->
<!-- GCC 5.4.0 20160609 -->
<!-- Linux 4.4.0-138-generic #164-Ubuntu SMP Tue Oct 2 17:16:02 UTC 2018 x86_64 -->
<!-- GNU libc 2 (glibc 2.23) -->
<list>
<node id="node7gpu01" claimed="true" class="system" handle="DMI:0001">
<description>Computer</description>
<product>4008 T4008C_2-EXDXXX</product>
<vendor>Kontron</vendor>