#!/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="12.4-RELEASE" SWRELOLD="12.3-RELEASE" SWRELOLD_patch="12.3-RELEASE-p8" pkg_jail="pj124" pkg_jailOLD="pj123" # 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" # freebsd-version -j 8 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 # 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 cd /mnt/iocage/jails/$JAIL rpl '"release": "${SWRELOLD_patch}"' '"release": "${SWREL}"' config.json iocage update $JAIL 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" else 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 iocage update $JAIL iocage exec $JAIL "pkg update" fi iocage exec $JAIL "pkg autoremove -y" iocage exec $JAIL "pkg upgrade -y" # iocage exec $JAIL "pkg upgrade -f -y" iocage exec $JAIL "pkg clean -ay" # iocage exec $JAIL "rm -rf /var/tmp/temproot*" # iocage exec $JAIL "mergemaster -a" iocage exec $JAIL "etcupdate -t /mnt/common/$SWREL.bzip2" iocage exec $JAIL "freebsd-version" # 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 "#### update of $SWREL called" iocage fetch -NU -r $SWREL fi #iocage freebsd-update is failing in jails echo "#### iocage root - updating" 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 $SWREL.bzip2 -s /mnt/iocage/releases/$SWREL/root/usr/src mv $SWREL.bzip2 /root/FreeBSD/jails/config/common/ echo "#### iocage root - cleaning 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 jail - okay to delete poudriere build jail when prompted" cp -r /mnt/iocage/releases/$SWREL /zroot/pkgp if [[ $1 == "upgrade" ]]; then 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 pkgp packages first (y/N)? " RESP if [ ! -z $RESP ] && [ $RESP == "y" ]; then if [[ $1 == "upgrade" ]]; then JAIL="pkgp" read -p "upgrade jail $JAIL (y/N)? " RESP if [ $RESP == "y" ] || [ $RESP == "Y" ]; then update_jail $1 fi fi /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 "freebsd-update fetch -OR- freebsd-update upgrade -r $SWREL" echo "freebsd-update install -OR- pkg bootstrap -f ; pkg update ; pkg upgrade" # echo "rm -rf /usr/src.old; cp -r /usr/src /usr/src.old; rm -rf /usr/src/*" # echo "git clone --depth 1 --branch releng/12.3 https://git.FreeBSD.org/src.git /usr/src" # echo "cd /usr/src; cp ../../../../src.old/sys/amd64/conf/diyIT ." echo "cd /usr/src; git pull; make -j8 buildkernel KERNCONF=diyIT && make -j8 installkernel KERNCONF=diyIT" echo "reboot" echo "pkg-static upgrade -f" #echo "rm -rf /var/tmp/temproot*" #echo "mergemaster -a" echo "etcupdate" echo "/root/FreeBSD/scripts/zfs-prune-snapshots -vn -p 'ioc_update' 1d | grep removing"