Skip to content

Instantly share code, notes, and snippets.

@jsleeio
Created December 24, 2023 04:15
Show Gist options
  • Save jsleeio/1cb29d783cfa806a11da25ba75c72571 to your computer and use it in GitHub Desktop.
Save jsleeio/1cb29d783cfa806a11da25ba75c72571 to your computer and use it in GitHub Desktop.
OpenBSD release, syspatch and snapshot downloader script
#!/bin/ksh
## downloads OpenBSD releases, snapshots and syspatches, and verifies them
## with signify(1). Files are downloaded to /var/www/htdocs/OpenBSD/... per
## the standard mirror layout, so that you can use them as an installurl.
##
## I use this to retrieve sets for building VMs.
##
## upstream mirror is selected from /etc/installurl.
##
## You will probably not have a good time running this on non-OpenBSD hosts
## due to the use of signify(1).
##
## options:
##
## -m specify the architecture, eg. -m amd64 (default: host architecture)
## -r specify a release, eg. -s 7.4 (default: host release)
## -p download syspatches instead
## -s download the latest snapshot instead
set -eu
arch=$(uname -m)
release=$(uname -r)
syspatch=no
while getopts m:pr:s flag ; do
case $flag in
m) arch="$OPTARG" ;;
r) release="$OPTARG" ;;
s) release="snapshots" ;;
p) syspatch=yes ;;
*) echo "USAGE: $0 [-m ARCH] [-r RELEASE]|[-s]|[-p]" >&2 ; exit 1 ;;
esac
done
if [[ "$syspatch" = "yes" ]] ; then
downloadbase="$(cat /etc/installurl)/syspatch/$release/$arch"
releasepath="/var/www/htdocs/pub/OpenBSD/syspatch/$release/$arch"
else
downloadbase="$(cat /etc/installurl)/$release/$arch"
releasepath="/var/www/htdocs/pub/OpenBSD/$release/$arch"
fi
mkdir -p "$releasepath"
cd "$releasepath"
ftp -V "$downloadbase/SHA256.sig"
awk \
-v downloadbase="$downloadbase" \
-F'[() ]+' \
'$1 == "SHA256" { print downloadbase "/" $2 }' \
SHA256.sig \
| xargs -n1 -P10 ftp -V
signify -C -x SHA256.sig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment