Annotation of elwix/config/etc/default/rc.cfg, revision 1.3.2.17
1.2 misho 1: #!/bin/sh
2: #
3: # U-boot cfg nand map load/save management script
4: #
1.3.2.17! misho 5: # $Id: rc.cfg,v 1.3.2.16 2017/10/08 00:05:37 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.4 misho 94: cfexec tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save"
1.3.2.14 misho 95: if [ $? -eq 127 ]; then
96: tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save"
97: fi
1.3.2.1 misho 98: echo "ELWIX sync process complete."
1.3.2.2 misho 99: ;;
100: pkg_load)
101: echo "ELWIX loading information about installed packages from storage"
1.3.2.4 misho 102: tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load"
1.3.2.2 misho 103: echo "ELWIX load process complete."
1.3.2.1 misho 104: ;;
1.3.2.7 misho 105: pkg2cf)
106: echo "ELWIX setup new pkg location on CF at $PKGCF"
1.3.2.17! misho 107: if ! mount | grep "${CFDIR}" >/dev/null 2>&1; then
1.3.2.7 misho 108: echo "Skip pkg2cf setup, because CF partition isn't mounted ..."
109: exit 1
110: fi
111: if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then
1.3.2.16 misho 112: mount -uw ${CFDIR}
1.3.2.7 misho 113: mkdir -p ${PKG2CF}/db
114: mkdir -p ${PKG2CF}/local
1.3.2.16 misho 115:
116: if [ ! -L /elwix/altroot/pkg/db ]; then
117: cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db >/dev/null 2>&1
118: cfexec rm -rf /elwix/altroot/pkg/db
119: if [ $? -eq 127 ]; then
120: rm -rf /elwix/altroot/pkg/db
121: fi
122: cfexec ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
123: if [ $? -eq 127 ]; then
124: ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
125: fi
1.3.2.13 misho 126: fi
1.3.2.16 misho 127: if [ ! -L /elwix/local ]; then
128: cp -r /elwix/local/* ${PKG2CF}/local >/dev/null 2>&1
129: cfexec rm -rf /elwix/local
130: if [ $? -eq 127 ]; then
131: rm -rf /elwix/local
132: fi
133: cfexec ln -s ${PKG2CF}/local /elwix/local
134: if [ $? -eq 127 ]; then
135: ln -s ${PKG2CF}/local /elwix/local
136: fi
1.3.2.13 misho 137: fi
1.3.2.16 misho 138:
139: mount -ur ${CFDIR}
1.3.2.7 misho 140: fi
141: echo "ELWIX pkg2cf setup complete."
142: ;;
1.3.2.9 misho 143: boot2)
1.3.2.8 misho 144: echo "ELWIX setup boot from second image"
1.3.2.9 misho 145: if [ -c $ELWIX2 ]; then
1.3.2.17! misho 146: if mount | grep "${ELWIX2} " >/dev/null 2>&1; then
! 147: die "You already booted from backup image! Skip changing image ..."
! 148: fi
! 149:
1.3.2.16 misho 150: cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" \
151: -JSs currdev /boot/loader.conf.local "\"disk0f:\""
1.3.2.10 misho 152: cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
1.3.2.14 misho 153: if [ $? -eq 127 ]; then
154: cp /tmp/loader.conf.local.tmp /boot/loader.conf.local
155: fi
1.3.2.10 misho 156: rm -f /tmp/loader.conf.local.tmp
1.3.2.9 misho 157: else
158: die "ERROR:: ELWIX has no second usable image!"
1.3.2.8 misho 159: fi
1.3.2.9 misho 160: echo "ELWIX boot2 setup complete."
161: ;;
162: boot)
163: echo "ELWIX setup boot from main image"
1.3.2.17! misho 164: if mount | grep "${ELWIX2} " >/dev/null 2>&1; then
! 165: mount ${ELWIX} /mnt
! 166:
! 167: cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" \
! 168: -JSs currdev /mnt/boot/loader.conf.local "\"disk0a:\""
! 169: cp /tmp/loader.conf.local.tmp /mnt/boot/loader.conf.local
! 170: rm -f /tmp/loader.conf.local.tmp
! 171:
! 172: umount /mnt
! 173: else
! 174: die "You already booted from main image! Skip changing image ..."
1.3.2.14 misho 175: fi
1.3.2.9 misho 176: echo "ELWIX boot setup complete."
1.3.2.8 misho 177: ;;
1.2 misho 178: *)
1.3.2.17! misho 179: echo "Missing parameter - available options are (load | save | erase | \
! 180: backup | restore | upgrade | pkg_load | pkg_save | pkg2cf | boot2 | boot)"
1.2 misho 181: ;;
182: esac
183:
184: cd -
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>