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