Skip to content

Instantly share code, notes, and snippets.

@pacohope
Forked from thefloweringash/fix-freebsd-update.sh
Created March 6, 2018 15:00
Show Gist options
  • Save pacohope/0b2fca7bcada4f98d7c71ab568aa0a89 to your computer and use it in GitHub Desktop.
Save pacohope/0b2fca7bcada4f98d7c71ab568aa0a89 to your computer and use it in GitHub Desktop.
There I "fixed" freebsd-update.
#!/bin/sh
# Fork of https://gist.github.com/thefloweringash/8729473
#
# freebsd-update is a clever script that downloads a lot of bsdiff
# patches and whole files when patches are not suitable. The result of
# this process is a collection of files in
# /var/db/freebsd-update/files. If the files already exist, it will
# not fetch them again.
#
# This script provides the entire contents of a given distribution in
# the hashed/gzip'd format that freebsd-update expects, and can
# replace a 4 hour fetch with a 2 minute fetch + 3 minute expand.
#
# Run this before starting the upgrade to the new version.
#
# Paco modified to fetch sources that are missing. I also mount the
# freebsd-update folder on my various VMs so that I only do this whole
# fetch-and-extract once, and then each VM can share this repository.
# I parameterised the source and the release version so that I can
# reuse this.
mkdir -p named
BASEDIR=${1:-${PWD}}
RELEASE="11.1-RELEASE"
SOURCE="ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/${RELEASE}/"
PARTS="base kernel doc ports"
NAMEDDIR="${BASEDIR}/named"
FILESDIR="${BASEDIR}/files"
### --- probably don't need to change anything below here --- ###
# Make some standard directories we will need
for DIR in "${NAMEDDIR}" "${FILESDIR}"
do
if [ ! -d "${NAMEDIR}" ]
then
echo "==> ${BASEDIR}/named not found. Creating."
mkdir -p "${BASEDIR}/named"
fi
done
echo "==> Extracting all parts"
for p in $PARTS; do
FULL_PATH="${BASEDIR}/${p}.txz"
if [ ! -r "${FULL_PATH}" ]; then
echo -n "Missing file ${FULL_PATH}. Fetching: "
curl -o "${FULL_PATH}" "${SOURCE}/${p}.txz"
fi
echo " => $p"
tar -C named -xf "${FULL_PATH}"
done
echo "==> supplying files to freebsd-update"
find "${NAMEDDIR}" -type f | while read f; do
if [ -x "/sbin/sha256" ]
then
# we're on FreeBSD
HASH=$(/sbin/sha256 -q "$f")
elif [ -x "/bin/sha256sum" ]
# I end up running this on my synology, which has a slightly different sha256sum command.
SHASUM=$(/bin/sha256sum "$f")
HASH="${SHASUM%% *}"
else
echo "Don't know how to get a sha256sum, sorry"
exit 1
fi
TARGET="${FILESDIR}/${HASH}.gz"
if [ ! -f "${TARGET}" ]; then
gzip < "$f" > "${TARGET}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment