Skip to content

Instantly share code, notes, and snippets.

View afresh1's full-sized avatar

Andrew Hewus Fresh afresh1

View GitHub Profile
@afresh1
afresh1 / vfs-sysctl_hw_sensors-discovery
Created July 22, 2020 00:51
A perl script to convert OpenBSD's `sysctl hw.sensors` output into something that might be useful for Zabbix.
#!/usr/bin/perl -T
use v5.16;
use warnings;
use OpenBSD::Pledge qw< pledge >;
use JSON::PP qw<>;
# Copyright (c) 2020 Andrew Hewus Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
@afresh1
afresh1 / oget
Last active December 13, 2020 01:10
Helper to download OpenBSD dist files (mostly bsd.rd) and verify them with signify.
#!/usr/bin/perl -T
use v5.16;
use warnings;
delete $ENV{PATH};
delete $ENV{ENV};
use OpenBSD::Unveil;
use OpenBSD::Pledge;
@afresh1
afresh1 / make_remote
Last active January 11, 2021 03:34
Helper to generate an /etc/remote file from a template by looking up a serial port from its serial number. If you don't know which `dv=` device to use, specify an `iSerial=$serial` instead.
#!/usr/bin/perl
use v5.30;
use warnings;
%ENV = ();
use OpenBSD::Pledge;
use OpenBSD::Unveil;
# Copyright (c) 2020 Andrew Hewus Fresh <andrew@afresh1.com>
@afresh1
afresh1 / vmctl-ssh
Last active December 22, 2021 22:10
A helper to look up the IP for and ssh into an OpenBSD vmd vm that uses the standard tap interface in a bridge setup. Lots of setups this won't work for, but the one where vmd provides the IP seems to work OK.
#!/usr/bin/perl
use v5.30;
use warnings;
use OpenBSD::Pledge;
use OpenBSD::Unveil;
# Copyright (c) 2021 Andrew Hewus Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
@afresh1
afresh1 / dyndns-matches
Last active January 18, 2021 19:28
Some helpers to set dynamic dns on an OpenBSD firewall on namecheap.com. Usage is `dyndns-matches $interface $host $domain || namecheap-dyndns $host $domain` (with your namecheap dyndns password in /etc/namecheap-dyndns). Should be suitable for putting in cron.
#!/bin/sh
set -e
if=$1
host=$2
domain=$3
lastip="/tmp/dyndns-$host-$domain"
ttl=3600

I thought perhaps you might like to hear my somewhat unique perspective, although definitely not saying anything others haven't already said. My perspective comes from my three hats, as a perl hobbyist and CPAN author, the maintainer of /usr/bin/perl in OpenBSD, and as someone who has written perl professionally for just short of ten years (the fifteen before that I wrote more and more perl as a sysadmin).

Overall, I think the plan is excellent and hope it mostly moves forward. There's only one tiny issue that might keep me from coming along for the ride.

tl;dr: if the default, without concious indication of something else, for bin/perl is anything but a "best effort at perl5" I believe I, and many other people will be stuck on perl5 forever and never be able to use v7, or v8, or anything later.

First, I should probably explain what I mean by a "best effort perl5". It is the thing we have gotten from perl on code without "use v5;" specified, likely since perl 5 was first released. Most things work, s

@afresh1
afresh1 / clean-dupes.pl
Last active December 22, 2021 22:08
A perl duplicate file finder based on size and hash. Uses only core perl modules.
#!/usr/bin/env perl
use v5.16;
use warnings;
#
# Copyright (c) 2021 Andrew Hewus Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
@afresh1
afresh1 / force_rsync.sh
Created August 25, 2021 15:55
A script to use as an SSH ForceCommand that only lets root connect to run rsync in the way FreeNAS/TrueNAS does it.
#!/bin/sh
expect='rsync --server --sender -logDtprze.LsfxC . /'
dir="/${SSH_ORIGINAL_COMMAND#$expect}"
# Try without compression
if [ "$dir" = "/${SSH_ORIGINAL_COMMAND}" ]; then
expect='rsync --server --sender -logDtpre.LsfxC . /'
dir="/${SSH_ORIGINAL_COMMAND#$expect}"
fi
@afresh1
afresh1 / vmctl-ssh
Created May 4, 2022 02:46
Provide a helper to ssh into an OpenBSD vmm vm by name without knowing what IP vmm assigned. It doesn't allow scp or things like that, haven't figured out how yet.
#!/usr/bin/perl
use v5.30;
use warnings;
use OpenBSD::Pledge;
use OpenBSD::Unveil;
# Copyright (c) 2021 Andrew Hewus Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
@afresh1
afresh1 / workaround_vlan_trunk_bug.sh
Created February 26, 2023 20:15
A small shellscript to work around a FreeBSD bug (208910) that requires you to move the vlan onto an epair member of the bridge, not on the physical interface in the bridge.
#!/bin/sh
set -o errexit -o pipefail -o nounset -o noclobber -o noglob
# Copyright (c) 2023 Andrew Hewus Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES