Skip to content

Instantly share code, notes, and snippets.

View xenithorb's full-sized avatar

Michael Goodwin xenithorb

View GitHub Profile
@xenithorb
xenithorb / gist:0114200c02a8bc9952d829b99623f9f7
Created January 17, 2019 17:39
HIBP API curl one-liner for keepassXC CSV output to check for circulated passwords
while read -r line; do hash=$( awk -F'","' '{printf "%s", $4}' <<< "$line" | sha1sum | cut -d' ' -f1 ); hash=${hash^^}; if (curl -s "https://api.pwnedpasswords.com/range/${hash:0:5}" | grep -q "${hash:5}" ); then echo "$line"; fi; sleep 1; done < <( { tr -d '\n' < output.csv | sed -r -e 's|"(xenith_keepass)|\n"\1|g' -e 's|,,|,"",|g'; echo; } | tail -n+2)
@xenithorb
xenithorb / ansible-ssh-README.md
Last active April 27, 2018 15:40
Use ansible's inventory to ssh into hosts quickly, with bash completion!
curl https://gist.githubusercontent.com/xenithorb/c50fd8b22b0d0a852d4f08b40c2fccf/ansible-ssh.sh  >> ~/.bashrc
. ~/.bashrc # Or open a new shell

Then, move to a directory with an inventory defined in ansible.cfg (most projects will have you define that per-project)

Basically, ansible-inventory --list needs to output vars when you're in your playbook directory for this to work

If it does you can now:

@xenithorb
xenithorb / 11_linux_dup.sh
Last active February 10, 2018 20:17
Add redundant menuentries in GRUB with extra cmdline paramaters
# IMPORTANT: Add the following to /etc/default/grub first!
#
# export GRUB_CMDLINE_LINUX_APPEND='<your_extra_cmdline_params>'
# export GRUB_OS_NAME_APPEND='<your_appended_id>'
#
# Note: ^ The export at the beginning is imperative unlike the rest
#
# Also maybe of interest (to save the selection):
#
# GRUB_DEFAULT=saved
@xenithorb
xenithorb / json-yaml-tools.sh
Last active December 7, 2018 14:16
Bashrc-style functions for json2yaml and yaml2json
# Please place these in ~/.bashrc or equivalent
yaml2json() {
python3 < "${1:-/dev/stdin}" <(
cat <<-EOF
import sys, yaml, json
json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)
EOF
)
}
@xenithorb
xenithorb / docker-dind.sh
Last active January 28, 2018 18:11
Bashrc-style function/alias for running a container within a container
# Typically just stick this in ~/.bashrc
# call it with `docker-dind` or `dind` like you would `docker`
if command -v docker &>/dev/null; then
dind () { docker-dind "$@"; }
dind-deactivate() { unset DOCKER_HOST; }
dind-activate () { unset DOCKER_HOST; dind-info; export DOCKER_HOST="$DOCKER_DIND_HOST" DOCKER_DIND_PORTS; }
dind-info () {
local info host_info dind_info tmpfile
info="{{.Name}}, {{.ServerVersion}}, {{.OperatingSystem}}"
host_info=$(DOCKER_HOST='' docker info -f "$info")
#!/bin/bash
#
# Usage:
#
# ./purge-file.sh <snapshot_path> "<file_or_relative_path>"
#
# Example:
#
# ./purge-file.sh /mnt/btrfs/snapshots/home "Downloads/*.iso"
#
@xenithorb
xenithorb / run_pihole_docker.sh
Last active August 16, 2019 07:21
My preferred way of running a standalone pihole on an atomic host instance.
NAME=pihole
TERM=xterm-256color
TAG='latest'
TZ="America/New_York"
DNS1=10.0.0.1
DNS2=10.0.0.1
IP=10.0.0.14
docker pull diginc/pi-hole:${TAG} &&
docker rm -f ${NAME}
#!/bin/bash
sudo sh <<EEOOFF
cat <<EOF > /etc/modprobe.d/amdgpu.conf
blacklist radeon
# enable CIK support (experimental) for R9 290 cards
options amdgpu cik_support=1
options radeon cik_support=0
EOF
@xenithorb
xenithorb / paradd.sh
Created October 11, 2017 18:11
Parallel dd to test multiple file writes and multiple device reads using simple `dd` methods
#!/bin/bash
declare MBYTES=2048
declare -a BLK_DEVS FILES
#set -x
_usage() {
cat <<EOF
Usage:
@xenithorb
xenithorb / ext1_handler.sh
Last active October 10, 2017 20:36
A bash script to quickly unmount my layered external block device
#!/bin/bash
# A script to quickly unmount an external USB drive I have that I am using
# multiple block device layers with, like bcache, lvm, luks, etc.
# Assumptions here are that the aforementioned relevant crypttab and fstab
# entries are present. If they are, systemd should take care of the rest.
# If it works correctly, the last thing the mounting command should do is
# ask you for the unlocking password.
#
# Author: Michael Goodwin
# Date: 2017-10-10