Initial import

This commit is contained in:
Arnaud Ysmal 2019-11-09 17:46:25 +01:00
commit 8f09cfff84

186
freebsd-sets-update.sh Normal file
View File

@ -0,0 +1,186 @@
#!/bin/sh
set -e
if [ "$(id -u)" != "0" ]; then
echo "Must be root." >&2
exit 1
fi
WORKDIR="/var/cache/freebsd-sets-update"
ARCH=$(uname -p)
BRANCH="head"
REVISION="latest_tested"
SETS="base kernel"
URL=
DO_DEBUG=
DO_LOCAL=
DO_ETCUPDATE=
usage()
{
echo "Usage: $0 [-b branch] [-l localdir] [-r revision] [-dev]"
echo " -b: branch (head, stable-11 or stable-12)"
echo " -d: add debug sets"
echo " -e: execute etcupdate"
echo " -l: directory where sets are located"
echo " -r: try to find sets for this revision"
echo " -v: show executed commands"
}
while getopts b:del:r:v OPT; do
case ${OPT} in
b)
BRANCH=${OPTARG}
;;
d)
DO_DEBUG="1"
SETS="${SETS} base-dbg kernel-dbg"
;;
e)
DO_ETCUPDATE="1"
;;
l)
DO_LOCAL="1"
WORKDIR=${OPTARG}
;;
r)
REVISION=${OPTARG}
;;
v)
set -x
;;
*)
usage
exit 1
;;
esac
done
shift $((${OPTIND} - 1))
if [ -n "${*}" ]; then
echo "Arguments are not supported" >&2
exit 1
fi
get_url()
{
echo "http://artifacts.ci.freebsd.org/snapshot/${BRANCH}/${1}/${ARCH}/${ARCH}"
}
exit_msg()
{
if [ -n "${1}" ]; then
echo "${1}"
fi
exit 1
}
fetch_sets()
{
url=$(get_url $REVISION)
fetch -o ${WORKDIR}/MANIFEST ${url}/MANIFEST
for set in $SETS; do
fetch -o ${WORKDIR}/${set}.txz ${url}/${set}.txz
done
}
install_kernel()
{
echo -n "Installing ${REVISION} kernel.txz..."
if ! mkdir -p /boot/kernel /boot/kernel.old /usr/lib/debug/boot/kernel /usr/lib/debug/boot/kernel.old; then
exit_msg " failed, mkdir error ${?}"
fi
if ! rm -r /boot/kernel.old /usr/lib/debug/boot/kernel.old; then
exit_msg " failed, rm error ${?}"
fi
if ! mv /boot/kernel /boot/kernel.old; then
exit_msg " failed, mv error ${?}"
fi
if ! mv /usr/lib/debug/boot/kernel /usr/lib/debug/boot/kernel.old; then
exit_msg " failed, mv error ${?}"
fi
if ! tar -C / -xpf ${WORKDIR}/kernel.txz; then
exit_msg " failed, tar error ${?}"
fi
if [ -n "${DO_DEBUG}" ]; then
echo -n " and kernel-dbg.txz..."
if ! tar -C / -xpf ${WORKDIR}/kernel-dbg.txz; then
exit_msg " failed, tar error ${?}"
fi
fi
if ! kldxref /boot/kernel; then
exit_msg " failed, kldxref error ${?}"
fi
echo " done"
}
install_base()
{
NOSCHGDIRS="/bin /sbin /lib /libexec /usr/bin /usr/sbin /usr/lib /var/empty"
echo -n "Installing ${REVISION} base.txz..."
if ! mkdir -p ${NOSCHGDIRS}; then
exit_msg " failed, mkdir error ${?}"
fi
if ! chflags -R noschg ${NOSCHGDIRS}; then
exit_msg " failed, chflags error ${?}"
fi
if ! tar -C / -xpf ${WORKDIR}/base.txz --exclude="^etc" ; then
exit_msg " failed, tar error ${?}"
fi
if [ -n "$DO_ETCUPDATE" ]; then
if ! mkdir ${WORKDIR}/etc; then
exit_msg " failed, mkdir error ${?}"
fi
if ! tar -C ${WORKDIR}/etc --include "^etc" -xpf ${WORKDIR}/base.txz; then
exit_msg " failed, tar error ${?}"
fi
if ! tar -C ${WORKDIR}/etc -cJf ${WORKDIR}/etc.txz .; then
exit_msg " failed, tar error ${?}"
fi
if ! etcupdate -I "/[^e][^t][^c]*" -t ${WORKDIR}/etc.txz ; then
exit_msg " failed, etcupdate error ${?}"
fi
fi
if [ -n "${DO_DEBUG}" ]; then
echo -n " and base-dbg.txz..."
if ! tar -C / -xpf ${WORKDIR}/base-dbg.txz; then
exit_msg " failed, tar error ${?}"
fi
fi
echo " done"
}
if [ -z "$DO_LOCAL" ]; then
REVISION=$(fetch -o - -q "$(get_url ${REVISION})/revision.txt")
WORKDIR="${WORKDIR}/${REVISION}"
if uname -v | grep -q "${REVISION}" ; then
exit_msg "Already at version ${REVISION}"
fi
if [ ! -d "${WORKDIR}" ]; then
if ! mkdir -p ${WORKDIR}; then
exit_msg " failed, mkdir error ${?}"
fi
fetch_sets
fi
fi
install_kernel
install_base
echo "Upgrade done"