Skip to content

Instantly share code, notes, and snippets.

@nbari
Created August 18, 2023 13:07
Show Gist options
  • Save nbari/b711d63ea9e789248f83f188dc59eb96 to your computer and use it in GitHub Desktop.
Save nbari/b711d63ea9e789248f83f188dc59eb96 to your computer and use it in GitHub Desktop.
update freebsd
#!/bin/sh
FREEBSD_VERSION=13
NUMBER_OF_CORES=`sysctl -n hw.ncpu`
ZPOOL="zroot"
START=$(date +%s)
if [ `sysctl -n kern.securelevel` -gt 0 ]; then
sysrc kern_securelevel_enable="NO"
echo "need to reboot with securelevel 0"
exit
fi
write() {
echo -e '\e[0;32m'
echo \#----------------------------------------------------------------------------
echo \# $1
echo -e \#----------------------------------------------------------------------------'\e[0m'
}
cd /usr/src
write "Checking out and updating sources FreeBSD: ${FREEBSD_VERSION}"
git pull
# Exit immediately if a command exits with a non-zero exit status
set -e
write "building world"
make -j${NUMBER_OF_CORES} buildworld
write "building kernel"
make -j${NUMBER_OF_CORES} kernel
zfs set exec=on ${ZPOOL}/tmp
write "installing world"
make installworld
write "making distribution"
cp -R /etc /etc.old && cd /usr/src && make distribution DESTDIR=/
write "backup /etc"
(cd /etc.old && cp group passwd master.passwd /etc && pwd_mkdb /etc/master.passwd)
cp /etc.old/ssh/sshd_config /etc/ssh/
write "deleting old"
make -DBATCH_DELETE_OLD_FILES delete-old
END=$(date +%s)
DIFF=$(echo "$END - $START" | bc)
ELAPSED=$(printf '%02dh:%02dm:%02ds\n' $(($DIFF/3600)) $(($DIFF%3600/60)) $(($DIFF%60)))
write "Done in: $ELAPSED, rebot and then \"yes | make delete-old-libs\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment