--- elwix/config/etc/default/rc.cfg 2017/02/13 16:52:47 1.3 +++ elwix/config/etc/default/rc.cfg 2017/07/13 09:46:29 1.3.2.15 @@ -2,61 +2,80 @@ # # U-boot cfg nand map load/save management script # -# $Id: rc.cfg,v 1.3 2017/02/13 16:52:47 misho Exp $ +# $Id: rc.cfg,v 1.3.2.15 2017/07/13 09:46:29 misho Exp $ CFG_NAND_LIST="/etc/cfg.map" CFG_NAND_MAP="/dev/ada0g" -CFG_NAND_SIZE=262144 +CFG_NAND_SIZE=524288 +ELWIX2="/dev/ufs/elwix2" + UPGRADE_GPIO_PINS="1 2 3" ELWIX_CFG_BACKUP_NAME="elwix_cfg_$(hostname).bin" +PKG2CF="/elwix/cf/pkg" + +die() { echo -n "EXIT: " >&2; echo "$@" >&2; exit 1; } + cd ${2:-/etc} case "$1" in load) + CFG_NAND_MAP=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $3); }'` + CFG_NAND_SIZE=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $2 * 512); }'` + imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \ - gunzip 2>&- | cpio -iud 2>&- || exit 1 + gunzip 2>&- | cpio -iud 2>&- || die "ERROR:: config load" ;; save) - if [ ! -r ${CFG_NAND_LIST} ];then + CFG_NAND_MAP=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $3); }'` + CFG_NAND_SIZE=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $2 * 512); }'` + + if [ ! -r ${CFG_NAND_LIST} ]; then echo "# Auto generated manifest file" >${CFG_NAND_LIST} find . >>${CFG_NAND_LIST} if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then - echo "Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!" - exit 1 + die "ERROR:: Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!" fi fi sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \ cpio -o | gzip -9 | \ - imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || exit 1 + imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config save" ;; erase) - imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || exit 1 + CFG_NAND_MAP=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $3); }'` + CFG_NAND_SIZE=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $2 * 512); }'` + + imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || die "ERROR:: config erase" echo "Config NAND was erased!" ;; restore) + CFG_NAND_MAP=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $3); }'` + CFG_NAND_SIZE=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $2 * 512); }'` + ELWIX_REMOTE_HOST=`cat /etc/myelwix` ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1 if [ $? -ne 0 ]; then - echo "ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!" - exit 1 + die "ERROR:: ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!" fi echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}" fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \ --no-verify-peer --no-verify-hostname \ ${ELWIX_REMOTE_HOST}/${ELWIX_CFG_BACKUP_NAME} | \ - imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || exit 1 + imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config restore" echo "ELWIX restore process complete. Now rebooting system ..." ;; backup) + CFG_NAND_MAP=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $3); }'` + CFG_NAND_SIZE=`gpart show -p | awk '($3 ~ "d[0-9]g" && $4 == "\!0") { printf("%s\n", $2 * 512); }'` + ELWIX_REMOTE_HOST="/tmp/${ELWIX_CFG_BACKUP_NAME}" echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}" - imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || exit 1 + imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || die "ERROR:: config backup" echo "ELWIX backup process complete." ;; upgrade) @@ -68,8 +87,70 @@ case "$1" in done TFTPd -wR ;; + pkg_save) + echo "ELWIX syncing information about installed packages into storage" + cfexec tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save" + if [ $? -eq 127 ]; then + tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save" + fi + echo "ELWIX sync process complete." + ;; + pkg_load) + echo "ELWIX loading information about installed packages from storage" + tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load" + echo "ELWIX load process complete." + ;; + pkg2cf) + echo "ELWIX setup new pkg location on CF at $PKGCF" + if ! mount | grep "/elwix/cf"; then + echo "Skip pkg2cf setup, because CF partition isn't mounted ..." + exit 1 + fi + if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then + mount -uw /elwix/cf + mkdir -p ${PKG2CF}/db + mkdir -p ${PKG2CF}/local + cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db >/dev/null 2>&1 + cp -r /elwix/local/* ${PKG2CF}/local >/dev/null 2>&1 + rm -rf /elwix/local /elwix/altroot/pkg/db + cfexec ln -s ${PKG2CF}/db /elwix/altroot/pkg/db + if [ $? -eq 127 ]; then + ln -s ${PKG2CF}/db /elwix/altroot/pkg/db + fi + cfexec ln -s ${PKG2CF}/local /elwix/local + if [ $? -eq 127 ]; then + ln -s ${PKG2CF}/local /elwix/local + fi + mount -ur /elwix/cf + fi + echo "ELWIX pkg2cf setup complete." + ;; + boot2) + echo "ELWIX setup boot from second image" + if [ -c $ELWIX2 ]; then + cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" -JSs currdev /boot/loader.conf.local "disk0f:" + cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local + if [ $? -eq 127 ]; then + cp /tmp/loader.conf.local.tmp /boot/loader.conf.local + fi + rm -f /tmp/loader.conf.local.tmp + else + die "ERROR:: ELWIX has no second usable image!" + fi + echo "ELWIX boot2 setup complete." + ;; + boot) + echo "ELWIX setup boot from main image" + cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" -JSs currdev /boot/loader.conf.local "disk0a:" + cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local + if [ $? -eq 127 ]; then + cp /tmp/loader.conf.local.tmp /boot/loader.conf.local + fi + rm -f /tmp/loader.conf.local.tmp + echo "ELWIX boot setup complete." + ;; *) - echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade)" + echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade | pkg_load | pkg_save | pkg2cf | boot2 | boot)" ;; esac