Skip to content

Instantly share code, notes, and snippets.

View PhrozenByte's full-sized avatar

Daniel Rudolf PhrozenByte

View GitHub Profile
@PhrozenByte
PhrozenByte / config-helper.sh
Created May 27, 2025 09:58
Safely source sh-based config files with `bwrap`.
##
# Safely source sh-based config files with `bwrap`
#
# This function allows script developers to safely include sh-based config
# files, especially if the config file isn't owned by the running user. Most
# notably this function allows one to source config files owned by unprivileged
# users as root, without practically giving said unprivileged user root access.
# The file is sourced within an unprivileged bwrap container with read-only
# access to /usr and nothing else. The sh-based config file can thus do
# anything a sourced Bash file normally could (e.g. do complex calculations
@PhrozenByte
PhrozenByte / nm-systemd-dispatcher.sh
Created May 7, 2025 14:19
NetworkManager dispatcher script to start/stop a Systemd unit when a connection's status changes.
#!/bin/bash
# nm-systemd-dispatcher.sh
# Starts/stops a Systemd unit when a connection's status changes to up/down.
#
# Install this script to `/etc/NetworkManager/dispatcher.d/60-systemd.sh` and
# add the following section to your NetworkManager connection config in
# `/etc/NetworkManager/system-connections/*.nmconnection`:
# [user]
# systemd.unit=myservice.service
#
@PhrozenByte
PhrozenByte / mkarchiso-gnome.sh
Created February 22, 2025 00:00
Creates a live ISO of Arch Linux with GNOME.
#!/bin/bash
# mkarchiso-gnome
# Creates a live ISO of Arch Linux with GNOME
#
# This script was created to ease creating live ISOs of Arch Linux with GNOME
# installed. It's highly customized to my personal preferences, thus it's
# likely not very useful as-is for most people, but it could be a good
# starting point for others to create their own custom live ISO.
#
# More about `mkarchiso`: https://wiki.archlinux.org/title/Archiso
@PhrozenByte
PhrozenByte / systemd-calendar-run.sh
Last active July 6, 2023 15:40
Runs a command if a Systemd calendar specification is due.
#!/bin/bash
# systemd-calendar-run.sh
# Runs a command if a Systemd calendar specification is due
#
# This script checks whether a given Systemd calendar specification (pass the
# '--on-calendar SPEC' option) relative to either the current, or a given time
# (pass the '--base-time TIMESTAMP' option) yields a past elapse time and runs
# the given command (pass as arguments: 'COMMAND [ARGUMENT]'). Otherwise the
# script exits with return code 254. When an invalid option is given, the
# script exits with return code 255.
@PhrozenByte
PhrozenByte / rdiff-backup-to-borg.sh
Created January 15, 2023 15:01
Converts rdiff-backup backups to Borg Backup.
#!/bin/bash
# rdiff-backup-to-borg
# Converts rdiff-backup backups to Borg Backup
#
# This script was created to ease switching from `rdiff-backup` to `borg`. It
# restores all increments of a rdiff-backup repository and backs it up using
# Borg Backup.
#
# More info about Borg Backup: <https://borgbackup.readthedocs.io>
# More info about rdiff-backup: <https://rdiff-backup.net/>
@PhrozenByte
PhrozenByte / btrfs-snapshot-run.sh
Last active September 29, 2023 21:02
Creates snapshots of a btrfs filesytem and runs a given command.
#!/bin/bash
# btrfs-snapshot-run
# Creates snapshots of a btrfs filesytem and runs a given command
#
# This script was created to ease backing up a btrfs filesystem. It expects
# Snapper's subvolume layout, with subvolumes directly below in the hierarchy
# of the top level subvolume (ID 5), all prefixed by '@'. Other subvolumes are
# being ignored.
#
# This script will create readonly snapshots for either all, or the provided
@PhrozenByte
PhrozenByte / systemd-wait-unit-active.sh
Created November 26, 2021 21:56
Waits until a systemd system or user unit is active.
#!/bin/bash
# systemd-wait-unit-active.sh
# Waits until a systemd system or user unit is active.
#
# Notice: When using this script with user units you must ensure that `sudo`
# can call `systemctl` proberly. This often fails due to `systemctl` not
# finding the user's D-Bus socket. Ensure that the user runs a D-Bus daemon
# and that the '$XDG_RUNTIME_DIR' environment variable is defined.
#
# Copyright (C) 2021 Daniel Rudolf (<https://www.daniel-rudolf.de>)
@PhrozenByte
PhrozenByte / coverage-badge.sh
Created January 28, 2021 01:32
Creates a coverage.svg badge from a clover.xml.
#!/bin/bash
# coverage-badge.sh - Creates a coverage.svg badge from a clover.xml.
#
# Copyright (C) 2021 Daniel Rudolf (<https://www.daniel-rudolf.de>)
# License: The MIT License <http://opensource.org/licenses/MIT>
#
# SPDX-License-Identifier: MIT
function print_usage {
echo "Usage:"
@PhrozenByte
PhrozenByte / PicoRedirect.php
Last active February 19, 2025 22:33
A simple Pico plugin to create redirection pages to arbitrary URLs.
<?php
/**
* Pico redirect plugin
*
* Adds a `Redirect` meta header to redirect to other URLs. The meta header
* supports URL substitution variables, namely %base_url%, %plugins_url%,
* %themes_url%, %assets_url% and %theme_url%.
*
* Example:
@PhrozenByte
PhrozenByte / 6to4-daemon
Created April 22, 2020 12:06
Establishing an IPv6 tunnel using 6to4
#!/bin/bash
# 6to4-daemon - Establishing an IPv6 tunnel using 6to4
# Copyright (C) 2011 Daniel Rudolf <http://www.daniel-rudolf.de/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,