Skip to content

Instantly share code, notes, and snippets.

@withakay
withakay / timemachine-backups-using-usb-passthrough-and-proxmox.md
Last active October 6, 2024 15:03
A quick guide to setting up Time Machine backups with an Ubuntu VM on Proxmox with USB Passthrough

Setting up Time Machine Backups Using Proxmox (v8.2) and Ubuntu (24.04)

This guide assumes you already have a basic Ubuntu 24.04 VM running on Proxmox. If not, you should set that up first. The VM can be fairly minimal; for example, 8GB of storage and 1GB of RAM should suffice.

It also assumes you have a USB Storage device that you want to use for Time Machine backups

Mapping a USB Drive to the Ubuntu VM Using Virtio in Proxmox

Mapping a USB drive via the Proxmox GUI is quick and easy, but the performance may be suboptimal because the driver is emulated. For better performance, it's recommended to use the virtio driver, which is paravirtualized. Paravirtualization allows the guest VM to interact more directly with the hardware, improving I/O performance compared to emulated devices.

@withakay
withakay / ssh-init-host.sh
Last active October 5, 2024 14:11
Bash script to harden SSH a new Debian/Ubuntu install
# Lots of VM hosts create new VMs with just a root user and password login,
# or maybe you just forgot to setup cloud-init, eitherway this script is for
# those times.
#
# IMPORTANT NOTE!
# This script will make changes to remote SSH config. If it goes wrong that
# could result in you being unable to login to your server!
# If you even a little bit concerned by that thought then do not proceed!
#
#
@withakay
withakay / README.md
Last active July 19, 2024 11:05
Run amd64/x64 PowerShell via docker on ARM based systems (e.g. Apple Silicon)

pwsh64.sh - PowerShell amd64/x64 Docker Runner

This bash script allows you to run PowerShell commands and scripts in an x64 environment using Docker. It's particularly useful for those using Apple Silicon (or other ARM based systems) who need to run x64-only PowerShell tools.

Prerequisites

  • Docker installed and running on your system

Usage

@withakay
withakay / gist:2314d35ce44e9f9f92b80f8ff8014c89
Created January 29, 2024 12:06
pre-commit_commit-to-main-guard.sh
#!/bin/bash
# Setup:
# Assuming you don't alread have a global githooks dir
#
# mkdir -p ~/.githooks/
#
# Save this script to the above path.
# Make a shell script called `pre-commit` in the above path (touch ~/.githooks/pre-commit).
# Edit pre-commit script sp it calls this script from it e.g.
@withakay
withakay / azs.sh
Last active November 6, 2023 08:46
azs - An Azure subscription switcher bash script
#!/bin/bash
# A bash script to switch Azure subscriptions
# save this script as `azs` somewhere in your path and make it executable
# then you can run `azs` to see a list subscriptions and easily switch between them
show_help() {
echo "Usage: $0 [options]"
echo ""
echo "Options:"
@withakay
withakay / no-standard-secuyrity-groups.sh
Created July 5, 2023 08:54
AWS CLI: Get security groups that allow 0.0.0.0/0 on non standard ports (22, 80, 443 etc)
aws ec2 describe-security-groups --region "eu-west-1" \
--query 'SecurityGroups[?((IpPermissions.IpRanges.CidrIp == "0.0.0.0/0") || (IpPermissions.Ipv6Ranges.CidrIpv6 == "::/0"))]' \
--output json\
| jq '.[] | select(.IpPermissions[].FromPort | IN(3, 22, 80, 443) | not)'
@withakay
withakay / csvquery.sh
Last active June 23, 2023 10:48
Query CSV files with SQL from the command line easily, using SQLite
#!/bin/bash
set -eou pipefail
# Function to display usage instructions
display_usage() {
echo "This script uses SQLite3 to load a CSV file into memory and then query it with SQL, printing the results to stdout."
echo "The table name will be 'csv', so use that in your queries."
echo ""
echo "Usage: $0 -f|--file <file_path> [-q|--query <query>] [-p|--print-header] [-h|--header-fix]"
@withakay
withakay / git-cod
Created June 20, 2023 08:21
Git checkout default branch and pull. Optionally create a new working branch
#!/bin/bash
# Place this script in your path and make it executable
# Display the script's usage
display_usage() {
echo "Git Checkout Default Script"
echo "This git script will check out the default HEAD branch"
echo "and pull the latest from the remote. Optionally it will"
echo "create a new branch ready for you to work on."
@withakay
withakay / tf-module-version-pin.sh
Last active May 31, 2023 09:38
Terraform module version pin - search and replace
#!/bin/bash
# A script to search for all terraform files in a directory and replace
# the source attribute of any module references with a specific git ref tag/commit.
# This is useful for pinning a specific version of a module in a terraform project.
#
# Note:
# this script was tested on MacOS and may need to be modified for other platforms
# as the sed command may differ.
#
@withakay
withakay / .envrc
Created May 8, 2023 08:28
Direnv .envrc defaults for python
### My current .envrc defaults for defaults for a python project
# I use asdf to manage runtimes.
# Using asdf with direnv like this removes the
# annoying shims, which for me is more reliable
# less confusing and slightly faster
use asdf
unset PYTHONHOME