#!/bin/sh
#
# Update ELWIX OS flash images
#
# $Id: rc.flash,v 1.2 2021/03/11 13:59:50 misho Exp $
die() { echo -n "ERROR:: " >&2; echo "$@" >&2; exit 1; }
restoreing()
{
case "$1" in
primary|first|main|A|1)
CFG_NAND_MAP=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"a") { printf("/dev/%s", $3); }'`
CFG_NAND_SIZE=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"a") { printf("%s", $2 * 512); }'`
sysctl -w kern.geom.debugflags=16
imgupd -is $CFG_NAND_SIZE -f $CFG_NAND_MAP || die "Failed update primary image ..."
tunefs -L elwix $CFG_NAND_MAP
/etc/rc.cfg boot
reboot
;;
secondary|second|backup|B|2)
CFG_NAND_MAP=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"f") { printf("/dev/%s", $3); }'`
CFG_NAND_SIZE=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"f") { printf("%s", $2 * 512); }'`
imgupd -is $CFG_NAND_SIZE -f $CFG_NAND_MAP || die "Failed update secondary image ..."
tunefs -L elwix2 $CFG_NAND_MAP
/etc/rc.cfg boot2
reboot
;;
configuration|config|cfg|C|0)
CFG_NAND_MAP=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"g") { printf("/dev/%s", $3); }'`
CFG_NAND_SIZE=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"g") { printf("%s", $2 * 512); }'`
imgupd -is $CFG_NAND_SIZE -f $CFG_NAND_MAP || die "Failed update cfg image ..."
reboot
;;
*)
die "Unknown $1 image for restore ..."
;;
esac
}
dumping()
{
case "$1" in
primary|first|main|A|1)
CFG_NAND_MAP=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"a") { printf("/dev/%s", $3); }'`
CFG_NAND_SIZE=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"a") { printf("%s", $2 * 512); }'`
;;
secondary|second|backup|B|2)
CFG_NAND_MAP=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"f") { printf("/dev/%s", $3); }'`
CFG_NAND_SIZE=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"f") { printf("%s", $2 * 512); }'`
;;
configuration|config|cfg|C|0)
CFG_NAND_MAP=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"g") { printf("/dev/%s", $3); }'`
CFG_NAND_SIZE=`gpart show -p | awk '(NR == 1) { disk = $4; } ($3 == disk"g") { printf("%s", $2 * 512); }'`
;;
*)
die "Unknown $1 image for dump ..."
;;
esac
echo imgupd -gs $CFG_NAND_SIZE -f $CFG_NAND_MAP
}
#
## main()
#
case "$1" in
dump|get|read|fetch)
dumping $2
;;
restore|put|write|update)
restoring $2
;;
*)
echo "/etc/rc.flash <dump|restore> <primary|secondary|config>"
echo
die "Unknown command $1 ..."
;;
esac
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>