171 lines
7.7 KiB
Bash
Executable File
171 lines
7.7 KiB
Bash
Executable File
#!/usr/local/bin/bash
|
|
|
|
# Copyright (c) 2018-2022, diyIT.org
|
|
# All rights reserved.
|
|
#
|
|
# BSD 2-Clause License ("Simplified BSD License" or "FreeBSD License")
|
|
# https://diyit.org/license/
|
|
#
|
|
#
|
|
|
|
SWREL="14.2-RELEASE"
|
|
SWREL_patch="14.2-RELEASE-p3"
|
|
SWRELOLD="14.2-RELEASE"
|
|
SWRELOLD_patch="14.2-RELEASE-p1"
|
|
pkg_jail="pj123"
|
|
pkg_jailOLD="pj123"
|
|
|
|
/root/FreeBSD/scripts/freebsd-update-mirror fetch -d /zroot/pkgp/update --currently-running $SWRELOLD_PATCH -m
|
|
|
|
# LATEST: Decided to use pkgp123 as the repo and pj123 as the jail going forward as all jails run the same SWREL
|
|
# NOTE: first time for new SWREL remember to update pkgp.conf files to new pkg_jail
|
|
# find ./ | grep pkgp.conf | sort
|
|
|
|
update_jail ()
|
|
{
|
|
echo "######## ## JAIL:::: $JAIL ##"
|
|
|
|
## uncomment below to list and remove snapshots
|
|
#zfs list -t snapshot -o name | grep ship/iocage/jails/$JAIL | sort
|
|
#read -p "remove all $JAIL snapshots (y/N)? " RESP
|
|
#if [ ! -z $RESP ] && [ $RESP == "y" ]; then
|
|
# zfs list -t snapshot -o name | grep ship/iocage/jails/$JAIL | sort | xargs -n 1 zfs destroy
|
|
#fi
|
|
|
|
iocage exec $JAIL "freebsd-version -ru"
|
|
# freebsd-version -j 8
|
|
|
|
iocage exec $JAIL "rm -rf /var/db/freebsd-update/install.*"
|
|
iocage exec $JAIL "rm -f /var/db/freebsd-update/*"
|
|
|
|
if [[ $1 == "upgrade" ]]; then
|
|
# FAILING: iocage upgrade -r $SWREL $JAIL
|
|
# freebsd-update -r $SWREL -j 8 upgrade
|
|
# freebsd-update -r $SWREL -j 8 install
|
|
# freebsd-update -r $SWREL -j 8 install
|
|
freebsd-update --currently-running $SWRELOLD -r $SWREL -b /mnt/iocage/jails/$JAIL/root -d /mnt/iocage/jails/$JAIL/root/var/db/freebsd-update -f /mnt/iocage/jails/$JAIL/root/etc/freebsd-update.conf --not-running-from-cron upgrade
|
|
freebsd-update --currently-running $SWRELOLD -r $SWREL -b /mnt/iocage/jails/$JAIL/root -d /mnt/iocage/jails/$JAIL/root/var/db/freebsd-update -f /mnt/iocage/jails/$JAIL/root/etc/freebsd-update.conf --not-running-from-cron install
|
|
iocage stop $JAIL
|
|
sleep 2
|
|
iocage start $JAIL
|
|
# post reboot install, reboot not required in jails
|
|
freebsd-update --currently-running $SWRELOLD -r $SWREL -b /mnt/iocage/jails/$JAIL/root -d /mnt/iocage/jails/$JAIL/root/var/db/freebsd-update -f /mnt/iocage/jails/$JAIL/root/etc/freebsd-update.conf --not-running-from-cron install
|
|
# iocage update fetches update based on string in json which used to get updated as part of the upgrade workflow
|
|
iocage update $JAIL
|
|
|
|
cd /mnt/iocage/jails/$JAIL
|
|
rpl '"release": "'${SWRELOLD_patch}'"' '"release": "'${SWREL_patch}'"' config.json
|
|
|
|
iocage exec $JAIL "[ -f /mnt/config/pkgp.conf ] && cp /mnt/config/pkgp.conf /usr/local/etc/pkg/repos/ || cp /mnt/common/pkgp.conf /usr/local/etc/pkg/repos/"
|
|
iocage exec $JAIL "pkg-static upgrade -f -y"
|
|
iocage exec $JAIL "pkg update -f"
|
|
|
|
# reset MTA back to sendmail - dma does not seem to handle the relay to MX server properly
|
|
# iocage exec $JAIL "cp /usr/share/examples/sendmail/mailer.conf /etc/mail/mailer.conf; cd /etc/mail; make all install; /usr/bin/newaliases; service sendmail start; service sendmail restart"
|
|
else
|
|
echo "freebsd-update --currently-running $SWREL -b /mnt/iocage/jails/$JAIL/root -d /mnt/iocage/jails/$JAIL/root/var/db/freebsd-update -f /mnt/iocage/jails/$JAIL/root/etc/freebsd-update.conf --not-running-from-cron fetch"
|
|
freebsd-update --currently-running $SWREL -b /mnt/iocage/jails/$JAIL/root -d /mnt/iocage/jails/$JAIL/root/var/db/freebsd-update -f /mnt/iocage/jails/$JAIL/root/etc/freebsd-update.conf --not-running-from-cron fetch
|
|
# let iocage finish the patch install
|
|
# read -p "step 1"
|
|
iocage update $JAIL
|
|
# read -p "step 2"
|
|
iocage exec $JAIL "pkg update"
|
|
fi
|
|
|
|
iocage exec $JAIL "pkg autoremove -y"
|
|
iocage exec $JAIL "pkg upgrade -y"
|
|
iocage exec $JAIL "pkg clean -ay"
|
|
|
|
# iocage exec $JAIL "rm -rf /var/tmp/temproot*"
|
|
iocage exec $JAIL "etcupdate resolve"
|
|
iocage exec $JAIL "etcupdate -t /mnt/common/$SWREL.bzip2"
|
|
|
|
iocage exec $JAIL "freebsd-version -ru"
|
|
# freebsd-version -j 8
|
|
|
|
echo "######## ####"
|
|
#read -p "continue, ctrl-c to abort? " RESP
|
|
}
|
|
|
|
read -p "skip initial preparation steps (y/N)? " RESP
|
|
if [ -z $RESP ] || [ $RESP == "n" ] || [ $RESP == "N" ]; then
|
|
|
|
if [[ $1 == "upgrade" ]]; then
|
|
echo "#### fetching new iocage root image $SWREL"
|
|
iocage fetch -NU -r $SWREL
|
|
fi
|
|
|
|
#iocage freebsd-update is failing in jails
|
|
echo "#### updating iocage root image"
|
|
freebsd-update --currently-running $SWREL -b /mnt/iocage/releases/$SWREL/root -d /mnt/iocage/releases/$SWREL/root/var/db/freebsd-update -f /mnt/iocage/releases/$SWREL/root/etc/freebsd-update.conf fetch
|
|
freebsd-update --currently-running $SWREL -b /mnt/iocage/releases/$SWREL/root -d /mnt/iocage/releases/$SWREL/root/var/db/freebsd-update -f /mnt/iocage/releases/$SWREL/root/etc/freebsd-update.conf install
|
|
|
|
echo "#### preparing etcupdate archive"
|
|
etcupdate build -s /mnt/iocage/releases/$SWREL/root/usr/src $SWREL.bzip2
|
|
mv $SWREL.bzip2 /root/FreeBSD/jails/config/common/
|
|
|
|
echo "#### cleaning iocage root image update directory"
|
|
rm -rf /mnt/iocage/releases/$SWREL/root/var/db/freebsd-update
|
|
mkdir -p /mnt/iocage/releases/$SWREL/root/var/db/freebsd-update/files
|
|
|
|
|
|
echo "#### preparing poudriere pkgp jail - okay to delete poudriere build jail when prompted"
|
|
cp -r /mnt/iocage/releases/$SWREL /zroot/pkgp
|
|
if [[ $1 == "upgrade" ]]; then
|
|
JAIL="pkgp"
|
|
update_jail $1
|
|
iocage exec pkgp "poudriere jail -d -j $pkg_jailOLD"
|
|
else
|
|
iocage exec pkgp "poudriere jail -d -j $pkg_jail"
|
|
fi
|
|
iocage exec pkgp "poudriere jail -c -j $pkg_jail -m null -M /mnt/cache/$SWREL/root -v $SWREL" # zroot/pkgp is mounted under /mnt/cache
|
|
iocage exec pkgp "poudriere jail -i -j $pkg_jail"
|
|
# check options are updated in /usr/local/etc/poudriere.d/$pkg_jail-options
|
|
|
|
read -p "update poudriere pkgp jail packages first (y/N)? " RESP
|
|
if [ ! -z $RESP ] && [ $RESP == "y" ]; then
|
|
/root/FreeBSD/jails/jails-update-pkgs.sh pkgp-only
|
|
fi
|
|
fi
|
|
|
|
read -p "process all jails (y/N)? " RESP
|
|
if [ ! -z $RESP ] && [ $RESP == "y" ]; then
|
|
# for JAIL in `iocage list -h | cut -f2`;
|
|
for JAIL in `jls -N | cut -d " " -f 2 | cut -d "-" -f 2- | grep -v JID | sort`;
|
|
do
|
|
if [ $JAIL == "test" ] || [ $JAIL == "debian" ]; then
|
|
continue
|
|
fi
|
|
if [[ $1 == "upgrade" ]]; then
|
|
read -p "upgrade jail $JAIL (Y/n)? " RESP
|
|
if [ ! -z $RESP ] && [ $RESP == "n" ]; then
|
|
continue
|
|
fi
|
|
fi
|
|
update_jail $1
|
|
done
|
|
fi
|
|
|
|
echo "update -OR- upgrade base system by running:"
|
|
echo "rm -rf /var/db/freebsd-update/install.*"
|
|
echo "rm /var/db/freebsd-update/*"
|
|
|
|
echo "freebsd-update fetch -OR- freebsd-update upgrade -r $SWREL"
|
|
echo "freebsd-update install -OPTIONAL- pkg bootstrap -f ; pkg update ; pkg upgrade"
|
|
|
|
# echo "rm -rf /usr/src.old; cp -r /usr/src /usr/src.old; rm -rf /usr/src/*; rm -rf /usr/src/.a* /usr/src/.c* /usr/src/.g*"
|
|
# the reason we can't delete the /usr/src directly is because it is mounted in all the jails
|
|
# echo "git clone --depth 1 --branch releng/14.1 https://git.FreeBSD.org/src.git /usr/src"
|
|
# echo "cd /usr/src/sys/amd64/conf; cp ../../../../src.old/sys/amd64/conf/diyIT ."
|
|
echo "cd /usr/src; git pull; make -j8 buildkernel KERNCONF=diyIT && make installkernel KERNCONF=diyIT"
|
|
echo "reboot"
|
|
|
|
echo "pkg-static upgrade -f; pkg update -f; pkg upgrade; pkg clean -a"
|
|
|
|
#echo "rm -rf /var/tmp/temproot*"
|
|
echo "etcupdate"
|
|
|
|
echo "/root/FreeBSD/scripts/zfs-prune-snapshots -vn -p 'ioc_update' 1d | grep removing"
|
|
|
|
echo "bectl list | grep 14.1-RELEASE-p3 | cut -d" " -f1 | xargs -n 1 bectl destroy"
|