Annotation of elwix/config/etc/default/rc.cfg, revision 1.3.2.14
1.2 misho 1: #!/bin/sh
2: #
3: # U-boot cfg nand map load/save management script
4: #
1.3.2.14! misho 5: # $Id: rc.cfg,v 1.3.2.13 2017/07/13 08:49:31 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.14! misho 78: if [ $? -eq 127 ]; then
! 79: tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save"
! 80: fi
1.3.2.1 misho 81: echo "ELWIX sync process complete."
1.3.2.2 misho 82: ;;
83: pkg_load)
84: echo "ELWIX loading information about installed packages from storage"
1.3.2.4 misho 85: tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load"
1.3.2.2 misho 86: echo "ELWIX load process complete."
1.3.2.1 misho 87: ;;
1.3.2.7 misho 88: pkg2cf)
89: echo "ELWIX setup new pkg location on CF at $PKGCF"
90: if ! mount | grep "/elwix/cf"; then
91: echo "Skip pkg2cf setup, because CF partition isn't mounted ..."
92: exit 1
93: fi
94: if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then
1.3.2.13 misho 95: mount -uw /elwix/cf
1.3.2.7 misho 96: mkdir -p ${PKG2CF}/db
97: mkdir -p ${PKG2CF}/local
1.3.2.12 misho 98: cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db >/dev/null 2>&1
99: cp -r /elwix/local/* ${PKG2CF}/local >/dev/null 2>&1
1.3.2.7 misho 100: rm -rf /elwix/local /elwix/altroot/pkg/db
1.3.2.13 misho 101: cfexec ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
102: if [ $? -eq 127 ]; then
103: ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
104: fi
105: cfexec ln -s ${PKG2CF}/local /elwix/local
106: if [ $? -eq 127 ]; then
107: ln -s ${PKG2CF}/local /elwix/local
108: fi
109: mount -ur /elwix/cf
1.3.2.7 misho 110: fi
111: echo "ELWIX pkg2cf setup complete."
112: ;;
1.3.2.9 misho 113: boot2)
1.3.2.8 misho 114: echo "ELWIX setup boot from second image"
1.3.2.9 misho 115: if [ -c $ELWIX2 ]; then
1.3.2.11 misho 116: 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 117: cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
1.3.2.14! misho 118: if [ $? -eq 127 ]; then
! 119: cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
! 120: fi
1.3.2.10 misho 121: rm -f /tmp/loader.conf.local.tmp
1.3.2.9 misho 122: else
123: die "ERROR:: ELWIX has no second usable image!"
1.3.2.8 misho 124: fi
1.3.2.9 misho 125: echo "ELWIX boot2 setup complete."
126: ;;
127: boot)
128: echo "ELWIX setup boot from main image"
1.3.2.11 misho 129: 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 130: cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
1.3.2.14! misho 131: if [ $? -eq 127 ]; then
! 132: cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
! 133: fi
1.3.2.10 misho 134: rm -f /tmp/loader.conf.local.tmp
1.3.2.9 misho 135: echo "ELWIX boot setup complete."
1.3.2.8 misho 136: ;;
1.2 misho 137: *)
1.3.2.9 misho 138: echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade | pkg_load | pkg_save | pkg2cf | boot2 | boot)"
1.2 misho 139: ;;
140: esac
141:
142: cd -
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>