Skip to content

Instantly share code, notes, and snippets.

@haxwithaxe
haxwithaxe / debian-oneshot.sh
Last active May 1, 2024 11:17
A script to bootstrap ansible, run ansible-pull, and cleanup after
#!/bin/bash
REPO="$1"
shift
BRANCH="${1:-main}" # Or commit or tag
shift
DEBIAN_NONINTERACTIVE=true
apt update -y
apt install --no-install-recommends --no-install-suggests -q -y python3-pip python3-venv git
@haxwithaxe
haxwithaxe / Healthcheck for stock promtail container.md
Created November 13, 2023 20:57
Pure bash healthcheck for stock promtail container

There's no wget and no curl (at least in the version I'm using at the moment). Here's a pure bash HTTP GET to /ready.

bash -c 'exec 3<>/dev/tcp/localhost/9080; \
echo -e GET /ready HTTP/1.1\\r\\nHost: localhost\\r\\n >&3; \
read line <&3; \
echo $line | grep -q "HTTP/1.1 200 OK"'
@haxwithaxe
haxwithaxe / cpu-governor-performance.py
Created November 9, 2023 19:52
Using this with my gaming VM to set the CPU governor to performance on my potato
#!/usr/bin/env python3
# /// pyproject
# [run]
# requires-python = '>=3.11'
# dependencies = [
# "proxmoxer",
# "requests"
# ]
# [tool.black]
@haxwithaxe
haxwithaxe / docker-service-exec
Created October 29, 2023 02:14
Run commands on docker swarm services regardless of which node it's on.
#!/bin/bash
# Run docker exec on service tasks on any host in a docker swarm.
#
# The first argument must be the service name all subsequent arguments are
# passed to that service task.
#
# The script looks for a docker context named ``node.<node hostname>``. If it
# doesn't exist the script will create a context by that name set to connect
# over ssh with the current local user as the username and the node name as the
@haxwithaxe
haxwithaxe / random-num
Created October 26, 2023 04:10
A fancy random number script that also prints random port and UID/GID numbers in base10, hex, and octal.
#!/usr/bin/env python3
"""Random number generator.
Prints a random number within given constraints.
* Arbitrary numbers
* Port numbers - safe ranges, system, all
* UID/GID - safe ranges, system, all
* Within a range
* On an interval
* In base10
@haxwithaxe
haxwithaxe / proxmox-certdeployer.py
Last active October 21, 2023 23:08
A certdeploy compatible script to update certs in a proxmox cluster.
#!/usr/bin/env python3
"""A command line tool to update TLS certificates on Proxmox clusters.
Note:
When running for the first time or after the certificates have expired set
`verify_tls` in the config to `false`.
The default config locations are:
- ``/cerdeploy/scripts/proxmox_certupdater.toml``
- ``/etc/proxmox_certupdater.toml``
@haxwithaxe
haxwithaxe / README.md
Last active October 10, 2023 12:07
Get a list of images from ghcr.io for a given project.

Get a list of images from ghcr.io for a given project. See https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#list-package-versions-for-a-package-owned-by-an-organization or https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#list-packages-for-a-user for the URL to use for other people's container images. See https://docs.github.com/en/rest/packages/packages?apiVersion=2022-11-28#list-package-versions-for-a-package-owned-by-the-authenticated-user for your own container images. Requires the credential github_access_token. The token needs the read:package permission.

@haxwithaxe
haxwithaxe / mbox-forward.py
Created October 7, 2023 14:54
This is the script I use to forward system mail (mbox) as a digest to a regular email account.
#!/usr/bin/env python3
"""This forwards mail from the given mbox style mailboxes to a real email.
It borrows the ``haxmail.ini`` config file.
"""
from dataclasses import dataclass, field
from typing import Annotated, List
import configparser
"""Random wire antenna length calculator.
Usage: python3 rw.py [--check <length in feet>] <band> [<band> ...]
Example:
* Check if 33ft is a good length for use with 80m-40m
python3 rw.py 80m 60m 40m --check 33
* List the gaps between harmonics for 80m-40m
python3 rw.py 80m 60m 40m
* List the gaps between harmonics for 80m-40m out to the 10th harmonics
@haxwithaxe
haxwithaxe / example-haxmail.ini
Last active September 17, 2023 18:50
A sendmail-like script without a mail daemon required.
[mail]
sender-email = haxmail <mailbot@example.com>
subject = Default subject
to = default_destination@example.com
smtp-username = mailbot@example.com
smtp-password = <mailbot smtp password>
smtp-server = smtp.example.com
smtp-port = 587