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