Skip to content

Instantly share code, notes, and snippets.

@NiceRath
NiceRath / openvpn_profile_chromeos.sh
Last active June 19, 2024 09:38
OpenVPN Profile for ChromeOS (ONC Format)
#!/bin/bash
# onc file format reference: https://chromium.googlesource.com/chromium/src/+/main/components/onc/docs/onc_spec.md#OpenVPN-connections-and-types
# NOTE: it seems tls-crypt is not supported
# TLSAuth
tlsauth="$(cat tlsauth.key | sed '1,3d' | sed ':a;N;$!ba;s/\n/\\n/g')"
# CA Certificate
ca="$(cat ca.crt | sed '1,1d' | sed '$d' | sed ':a;N;$!ba;s/\n//g')"
@NiceRath
NiceRath / graylog_pipeline_rules.md
Last active May 23, 2024 07:47
Graylog Pipeline Rules to extract fields for some common Services

Graylog menu: Graylog - System - Pipelines - Manage rules

All rules will assume you pre-filter your logs on an application-basis. Else the matching will get horrible.

Use regex101.com for testing expressions. Make sure to escape all the backslashes \\ (and so on..) before adding it as Graylog rule.

GENERIC: Use lookup tables to translate IPs to Hostnames

/*
@NiceRath
NiceRath / recursive_file_checksum.sh
Created April 22, 2024 09:04
Script for recursive checksum over directory content
#!/usr/bin/env bash
# NOTES:
# perfoms md5sum on all files in the directory, sorts them and creates an overall md5sum
# WARNING: the sort order & checksum will change if you do not use the same LANG/LC_ALL!
EXCLUDES=('dir1' 'dir2/*')
set -eo pipefail
@NiceRath
NiceRath / linuxha_cluster_floatingIP.txt
Last active May 13, 2024 14:43
LinuxHA (CRM/Corosync/Pacemaker) - Config for basic service cluster with floating IP
# bash > crm configure
primitive resHAProxy systemd:haproxy \
op monitor interval=5
clone clone_HAProxy resHAProxy
primitive resIP_LB IPaddr2 \
params ip=172.x.x.x nic=ens18 cidr_netmask=32 \
op monitor interval=10s \
meta target-role=Started
location cli-prefer-resIP_LB resIP_LB role=Started inf: node01 # prefer node01 if available
@NiceRath
NiceRath / luks_cryptmount_resize.sh
Created April 18, 2024 11:08
Luks Cryptmount - Resize encrypted LVM volume
#!/bin/bash
set -eE -o pipefail
# to create such a volume - use: https://gist.github.com/NiceRath/c794caa26a28fc90fc628a047648722b
if [ $# -lt 3 ]
then
cat << EOF
You must provide:
@NiceRath
NiceRath / luks_cryptmount_remote_key.sh
Last active April 18, 2024 18:23
Luks Cryptmount - Mount with key from remote host
#!/bin/bash
set -eE -o pipefail
# to create such a volume - use: https://gist.github.com/NiceRath/c794caa26a28fc90fc628a047648722b
# move the created key from <PATH-TO-KEY-DIR> to the remote host and securly delete them (p.e. using 'shred')
# run example: "bash /usr/local/sbin/cryptmount/cryptmount.sh vg0-lv1 crypt-lv1 /data"
ENC_LV_NAME="$1"
DECRYPT_LV_NAME="$2"
@NiceRath
NiceRath / luks_cryptmount_create.sh
Last active April 18, 2024 18:23
Luks Cryptmount - Create encrypted LVM volume
#!/bin/bash
set -eE -o pipefail
# script to encrypt an existing LVM volume
# to move the encryption keys to a remote host - use: https://gist.github.com/NiceRath/65511409c8dbbbbb98ae6f1a668b7d5d
ENC_PATH='<PATH-TO-KEY-DIR>'
KEY_SIZE='8192'
PASS_FILE="${ENC_PATH}/<GPG-PASSPHRASE-FILE>"
@NiceRath
NiceRath / macos_update_notification_jamf.sh
Created April 17, 2024 13:11
MacOS Update Notification (Jamf)
#!/bin/bash
set -euo pipefail
# NOTES:
# as Apple is not able to provide any good option to force updates on managed clients - you might want to notify users to install them
# will be silent if no updates are available
# see also: https://ss64.com/osx/softwareupdate.html
@NiceRath
NiceRath / google_takeout_mail_analysis.sh
Created April 17, 2024 10:52
Script to analyze Google Workspace/Gmail Mailboxes (Mailing Lists, Top Senders)
#!/bin/bash
set -eo pipefail
# NOTES:
# to use on backup files created by Google Takeout: https://support.google.com/accounts/answer/3024190?hl=en
# creates lists of top N mail senders & distribution-lists @ /tmp
# can be used to create Google Vault retentions to clean-up old mails or spam: https://support.google.com/vault/answer/2990828?hl=en
if [-z "$1" ]
@NiceRath
NiceRath / check_for_expired_ocsp.sh
Created March 4, 2024 08:09
OpenSSL scan directory for expired OCSP
#!/usr/bin/env bash
set -eo pipefail
if [ -z "$1" ]
then
echo "You need to supply the path to a certificate-directory to scan"
exit 1
fi