Annotation of elwix/config/etc/default/rc.cfg, revision 1.3.2.8
1.2 misho 1: #!/bin/sh
2: #
3: # U-boot cfg nand map load/save management script
4: #
1.3.2.8 ! misho 5: # $Id: rc.cfg,v 1.3.2.7 2017/06/23 08:56:48 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 misho 11: UPGRADE_GPIO_PINS="1 2 3"
12:
13: ELWIX_CFG_BACKUP_NAME="elwix_cfg_$(hostname).bin"
1.2 misho 14:
1.3.2.7 misho 15: PKG2CF="/elwix/cf/pkg"
16:
1.3.2.4 misho 17: die() { echo -n "EXIT: " >&2; echo "$@" >&2; exit 1; }
18:
1.2 misho 19: cd ${2:-/etc}
20:
21: case "$1" in
22: load)
23: imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \
1.3.2.4 misho 24: gunzip 2>&- | cpio -iud 2>&- || die "ERROR:: config load"
1.2 misho 25: ;;
26: save)
1.3.2.4 misho 27: if [ ! -r ${CFG_NAND_LIST} ]; then
1.2 misho 28: echo "# Auto generated manifest file" >${CFG_NAND_LIST}
29: find . >>${CFG_NAND_LIST}
30: if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then
1.3.2.4 misho 31: die "ERROR:: Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!"
1.2 misho 32: fi
33: fi
34:
35: sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \
36: cpio -o | gzip -9 | \
1.3.2.4 misho 37: imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config save"
1.2 misho 38: ;;
39: erase)
1.3.2.4 misho 40: imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || die "ERROR:: config erase"
1.2 misho 41: echo "Config NAND was erased!"
42: ;;
43: restore)
44: ELWIX_REMOTE_HOST=`cat /etc/myelwix`
45: ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1
46: if [ $? -ne 0 ]; then
1.3.2.4 misho 47: die "ERROR:: ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!"
1.2 misho 48: fi
49:
50: echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}"
51: fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \
1.3 misho 52: --no-verify-peer --no-verify-hostname \
53: ${ELWIX_REMOTE_HOST}/${ELWIX_CFG_BACKUP_NAME} | \
1.3.2.4 misho 54: imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config restore"
1.2 misho 55: echo "ELWIX restore process complete. Now rebooting system ..."
56: ;;
57: backup)
1.3 misho 58: ELWIX_REMOTE_HOST="/tmp/${ELWIX_CFG_BACKUP_NAME}"
1.2 misho 59:
60: echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}"
1.3.2.4 misho 61: imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || die "ERROR:: config backup"
1.2 misho 62: echo "ELWIX backup process complete."
63: ;;
64: upgrade)
65: echo "ELWIX switch to upgrade mode. Starting TFTPd ..."
66: echo " You can upload now elwix_firmware.bin image to device with \"firmware\" name!!!"
67: echo " Example: put elwix_firmware.bin firmware"
68: for i in ${UPGRADE_GPIO_PINS}; do
1.3 misho 69: gpioctl $i 1 >/dev/null 2>&1 || pceng "$i=0" >/dev/null 2>&1
1.2 misho 70: done
71: TFTPd -wR
72: ;;
1.3.2.2 misho 73: pkg_save)
1.3.2.1 misho 74: echo "ELWIX syncing information about installed packages into storage"
1.3.2.4 misho 75: cfexec tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save"
1.3.2.1 misho 76: echo "ELWIX sync process complete."
1.3.2.2 misho 77: ;;
78: pkg_load)
79: echo "ELWIX loading information about installed packages from storage"
1.3.2.4 misho 80: tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load"
1.3.2.2 misho 81: echo "ELWIX load process complete."
1.3.2.1 misho 82: ;;
1.3.2.7 misho 83: pkg2cf)
84: echo "ELWIX setup new pkg location on CF at $PKGCF"
85: if ! mount | grep "/elwix/cf"; then
86: echo "Skip pkg2cf setup, because CF partition isn't mounted ..."
87: exit 1
88: fi
89: if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then
90: mkdir -p ${PKG2CF}/db
91: mkdir -p ${PKG2CF}/local
92: cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db
93: cp -r /elwix/local/* ${PKG2CF}/local
94: rm -rf /elwix/local /elwix/altroot/pkg/db
95: ln -s ${PKG2CF}/db /elwix/altroot/pkg/db
96: ln -s ${PKG2CF}/local /elwix/local
97: fi
98: echo "ELWIX pkg2cf setup complete."
99: ;;
1.3.2.8 ! misho 100: boot2nd)
! 101: echo "ELWIX setup boot from second image"
! 102: if []; then
! 103: tunefs -L ''
! 104: fi
! 105: echo "ELWIX boot2nd setup complete."
! 106: ;;
1.2 misho 107: *)
1.3.2.8 ! misho 108: echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade | pkg_load | pkg_save | pkg2cf | boot2nd)"
1.2 misho 109: ;;
110: esac
111:
112: cd -
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>