#!/bin/sh if [ -r /etc/flashsite ]; then . /etc/flashsite else echo $0: cannot read /etc/flashsite exit 1 fi set `sed -En -e '/^#/d' -e 's,^(/dev/[ad][ad].)s([12])a.*$,\1 \2,p' /etc/fstab` >/dev/null if [ "$2" = 1 ]; then new=2 elif [ "$2" = 2 ]; then new=1 else echo $0: cannot parse root partition name in /etc/fstab exit 1 fi drive=$1 newpart=$1s$new export FTP_USER FTP_PASSWORD HTTP_AUTH echo Downloading image to $newpart... rm -f /tmp/.updated #sysctl kern.geom.debugflags=16 if ( fetch -v -o - $url && touch /tmp/.updated ) | bunzip2 2>/dev/null | \ dd obs=64k of=$newpart then [ -e /tmp/.updated ] || exit 1 echo Correcting fstab... mount ${newpart}a /mnt || exit 1 sed -i.bak s,$1s$2,$newpart, /mnt/etc/fstab /mnt/conf/base/etc/fstab echo Correcting loader.conf... # sed -E -i.bak s/\(vfs.root.mountfrom=\"ufs:\).*/\\1${newpart#/dev/}a\"/ /mnt/boot/loader.conf mount -u -o rw / sed -E -i.bak s/\(vfs.root.mountfrom=\"ufs:\).*/\\1${newpart#/dev/}a\"/ /mnt/boot/loader.conf /boot/loader.conf umount /mnt mount -u -o ro / echo Correcting boot0... # boot0cfg -s $new $1 # sysctl kern.geom.debugflags=0 gpart set -a active -i $new $drive fi echo Finished