Annotation of elwix/config/etc/default/rc.cfg, revision 1.3.2.12
1.2 misho 1: #!/bin/sh
2: #
3: # U-boot cfg nand map load/save management script
4: #
1.3.2.12! misho 5: # $Id: rc.cfg,v 1.3.2.11 2017/06/30 08:39:57 misho Exp $
1.2 misho 6:
7: CFG_NAND_LIST="/etc/cfg.map"
8: CFG_NAND_MAP="/dev/ada0g"
1.3.2.6 misho 9: CFG_NAND_SIZE=524288
1.2 misho 10:
1.3.2.9 misho 11: ELWIX2="/dev/ufs/elwix2"
12:
1.3 misho 13: UPGRADE_GPIO_PINS="1 2 3"
14:
15: ELWIX_CFG_BACKUP_NAME="elwix_cfg_$(hostname).bin"
1.2 misho 16:
1.3.2.7 misho 17: PKG2CF="/elwix/cf/pkg"
18:
1.3.2.4 misho 19: die() { echo -n "EXIT: " >&2; echo "$@" >&2; exit 1; }
20:
1.2 misho 21: cd ${2:-/etc}
22:
23: case "$1" in
24: load)
25: imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \
1.3.2.4 misho 26: gunzip 2>&- | cpio -iud 2>&- || die "ERROR:: config load"
1.2 misho 27: ;;
28: save)
1.3.2.4 misho 29: if [ ! -r ${CFG_NAND_LIST} ]; then
1.2 misho 30: echo "# Auto generated manifest file" >${CFG_NAND_LIST}
31: find . >>${CFG_NAND_LIST}
32: if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then
1.3.2.4 misho 33: die "ERROR:: Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!"
1.2 misho 34: fi
35: fi
36:
37: sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \
38: cpio -o | gzip -9 | \
1.3.2.4 misho 39: imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config save"
1.2 misho 40: ;;
41: erase)
1.3.2.4 misho 42: imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || die "ERROR:: config erase"
1.2 misho 43: echo "Config NAND was erased!"
44: ;;
45: restore)
46: ELWIX_REMOTE_HOST=`cat /etc/myelwix`
47: ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1
48: if [ $? -ne 0 ]; then
1.3.2.4 misho 49: die "ERROR:: ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!"
1.2 misho 50: fi
51:
52: echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}"
53: fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \
1.3 misho 54: --no-verify-peer --no-verify-hostname \
55: ${ELWIX_REMOTE_HOST}/${ELWIX_CFG_BACKUP_NAME} | \
1.3.2.4 misho 56: imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config restore"
1.2 misho 57: echo "ELWIX restore process complete. Now rebooting system ..."
58: ;;
59: backup)
1.3 misho 60: ELWIX_REMOTE_HOST="/tmp/${ELWIX_CFG_BACKUP_NAME}"
1.2 misho 61:
62: echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}"
1.3.2.4 misho 63: imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || die "ERROR:: config backup"
1.2 misho 64: echo "ELWIX backup process complete."
65: ;;
66: upgrade)
67: echo "ELWIX switch to upgrade mode. Starting TFTPd ..."
68: echo " You can upload now elwix_firmware.bin image to device with \"firmware\" name!!!"
69: echo " Example: put elwix_firmware.bin firmware"
70: for i in ${UPGRADE_GPIO_PINS}; do
1.3 misho 71: gpioctl $i 1 >/dev/null 2>&1 || pceng "$i=0" >/dev/null 2>&1
1.2 misho 72: done
73: TFTPd -wR
74: ;;
1.3.2.2 misho 75: pkg_save)
1.3.2.1 misho 76: echo "ELWIX syncing information about installed packages into storage"
1.3.2.4 misho 77: cfexec tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save"
1.3.2.1 misho 78: echo "ELWIX sync process complete."
1.3.2.2 misho 79: ;;
80: pkg_load)
81: echo "ELWIX loading information about installed packages from storage"
1.3.2.4 misho 82: tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load"
1.3.2.2 misho 83: echo "ELWIX load process complete."
1.3.2.1 misho 84: ;;
1.3.2.7 misho 85: pkg2cf)
86: echo "ELWIX setup new pkg location on CF at $PKGCF"
87: if ! mount | grep "/elwix/cf"; then
88: echo "Skip pkg2cf setup, because CF partition isn't mounted ..."
89: exit 1
90: fi
91: if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then
92: mkdir -p ${PKG2CF}/db
93: mkdir -p ${PKG2CF}/local
1.3.2.12! misho 94: cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db >/dev/null 2>&1
! 95: cp -r /elwix/local/* ${PKG2CF}/local >/dev/null 2>&1
1.3.2.7 misho 96: rm -rf /elwix/local /elwix/altroot/pkg/db
97: ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
98: ln -s ${PKG2CF}/local /elwix/local
99: fi
100: echo "ELWIX pkg2cf setup complete."
101: ;;
1.3.2.9 misho 102: boot2)
1.3.2.8 misho 103: echo "ELWIX setup boot from second image"
1.3.2.9 misho 104: if [ -c $ELWIX2 ]; then
1.3.2.11 misho 105: cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" -JSs currdev /boot/loader.conf.local "disk0f:"
1.3.2.10 misho 106: cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
107: rm -f /tmp/loader.conf.local.tmp
1.3.2.9 misho 108: else
109: die "ERROR:: ELWIX has no second usable image!"
1.3.2.8 misho 110: fi
1.3.2.9 misho 111: echo "ELWIX boot2 setup complete."
112: ;;
113: boot)
114: echo "ELWIX setup boot from main image"
1.3.2.11 misho 115: cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" -JSs currdev /boot/loader.conf.local "disk0a:"
1.3.2.10 misho 116: cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
117: rm -f /tmp/loader.conf.local.tmp
1.3.2.9 misho 118: echo "ELWIX boot setup complete."
1.3.2.8 misho 119: ;;
1.2 misho 120: *)
1.3.2.9 misho 121: echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade | pkg_load | pkg_save | pkg2cf | boot2 | boot)"
1.2 misho 122: ;;
123: esac
124:
125: cd -
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>