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