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