version 1.3, 2017/02/13 16:52:47
|
version 1.3.2.13, 2017/07/13 08:49:31
|
Line 6
|
Line 6
|
|
|
CFG_NAND_LIST="/etc/cfg.map" |
CFG_NAND_LIST="/etc/cfg.map" |
CFG_NAND_MAP="/dev/ada0g" |
CFG_NAND_MAP="/dev/ada0g" |
CFG_NAND_SIZE=262144 | CFG_NAND_SIZE=524288 |
|
|
|
ELWIX2="/dev/ufs/elwix2" |
|
|
UPGRADE_GPIO_PINS="1 2 3" |
UPGRADE_GPIO_PINS="1 2 3" |
|
|
ELWIX_CFG_BACKUP_NAME="elwix_cfg_$(hostname).bin" |
ELWIX_CFG_BACKUP_NAME="elwix_cfg_$(hostname).bin" |
|
|
|
PKG2CF="/elwix/cf/pkg" |
|
|
|
die() { echo -n "EXIT: " >&2; echo "$@" >&2; exit 1; } |
|
|
cd ${2:-/etc} |
cd ${2:-/etc} |
|
|
case "$1" in |
case "$1" in |
load) |
load) |
imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \ |
imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} | \ |
gunzip 2>&- | cpio -iud 2>&- || exit 1 | gunzip 2>&- | cpio -iud 2>&- || die "ERROR:: config load" |
;; |
;; |
save) |
save) |
if [ ! -r ${CFG_NAND_LIST} ];then | if [ ! -r ${CFG_NAND_LIST} ]; then |
echo "# Auto generated manifest file" >${CFG_NAND_LIST} |
echo "# Auto generated manifest file" >${CFG_NAND_LIST} |
find . >>${CFG_NAND_LIST} |
find . >>${CFG_NAND_LIST} |
if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then |
if [ $? -ne 0 -o ! -r ${CFG_NAND_LIST} ]; then |
echo "Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!" | die "ERROR:: Manifest cfg nand map - file '${CFG_NAND_LIST}' not found!" |
exit 1 | |
fi |
fi |
fi |
fi |
|
|
sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \ |
sed -nE -e 's/^ *([^ #]+) */\1/p' < ${CFG_NAND_LIST} | xargs find | \ |
cpio -o | gzip -9 | \ |
cpio -o | gzip -9 | \ |
imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || exit 1 | imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config save" |
;; |
;; |
erase) |
erase) |
imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || exit 1 | imgupd -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} /dev/zero || die "ERROR:: config erase" |
echo "Config NAND was erased!" |
echo "Config NAND was erased!" |
;; |
;; |
restore) |
restore) |
ELWIX_REMOTE_HOST=`cat /etc/myelwix` |
ELWIX_REMOTE_HOST=`cat /etc/myelwix` |
ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1 |
ping -c1 $(echo ${ELWIX_REMOTE_HOST} | cut -f3 -d '/' | cut -f2 -d '@') >/dev/null 2>&1 |
if [ $? -ne 0 ]; then |
if [ $? -ne 0 ]; then |
echo "ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!" | die "ERROR:: ELWIX restore from host ${ELWIX_REMOTE_HOST} failed!!!" |
exit 1 | |
fi |
fi |
|
|
echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}" |
echo "ELWIX starting restore process from ${ELWIX_REMOTE_HOST}" |
fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \ |
fetch -q -o- --user-agent=ELWIX_Restore --allow-sslv2 \ |
--no-verify-peer --no-verify-hostname \ |
--no-verify-peer --no-verify-hostname \ |
${ELWIX_REMOTE_HOST}/${ELWIX_CFG_BACKUP_NAME} | \ |
${ELWIX_REMOTE_HOST}/${ELWIX_CFG_BACKUP_NAME} | \ |
imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || exit 1 | imgupd -R -is ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} || die "ERROR:: config restore" |
echo "ELWIX restore process complete. Now rebooting system ..." |
echo "ELWIX restore process complete. Now rebooting system ..." |
;; |
;; |
backup) |
backup) |
ELWIX_REMOTE_HOST="/tmp/${ELWIX_CFG_BACKUP_NAME}" |
ELWIX_REMOTE_HOST="/tmp/${ELWIX_CFG_BACKUP_NAME}" |
|
|
echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}" |
echo "ELWIX starting backup process to ${ELWIX_REMOTE_HOST}" |
imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || exit 1 | imgupd -gs ${CFG_NAND_SIZE} -f ${CFG_NAND_MAP} ${ELWIX_REMOTE_HOST} || die "ERROR:: config backup" |
echo "ELWIX backup process complete." |
echo "ELWIX backup process complete." |
;; |
;; |
upgrade) |
upgrade) |
Line 68 case "$1" in
|
Line 72 case "$1" in
|
done |
done |
TFTPd -wR |
TFTPd -wR |
;; |
;; |
|
pkg_save) |
|
echo "ELWIX syncing information about installed packages into storage" |
|
cfexec tar -czvf /elwix/altroot/pkg/db/pkgz.tar.gz /var/db/pkg/* || die "ERROR:: package save" |
|
echo "ELWIX sync process complete." |
|
;; |
|
pkg_load) |
|
echo "ELWIX loading information about installed packages from storage" |
|
tar -xzvpf /elwix/altroot/pkg/db/pkgz.tar.gz -C / || die "ERROR:: package load" |
|
echo "ELWIX load process complete." |
|
;; |
|
pkg2cf) |
|
echo "ELWIX setup new pkg location on CF at $PKGCF" |
|
if ! mount | grep "/elwix/cf"; then |
|
echo "Skip pkg2cf setup, because CF partition isn't mounted ..." |
|
exit 1 |
|
fi |
|
if [ ! -L /elwix/local -a ! -L /elwix/altroot/pkg/db ]; then |
|
mount -uw /elwix/cf |
|
mkdir -p ${PKG2CF}/db |
|
mkdir -p ${PKG2CF}/local |
|
cp -r /elwix/altroot/pkg/db/* ${PKG2CF}/db >/dev/null 2>&1 |
|
cp -r /elwix/local/* ${PKG2CF}/local >/dev/null 2>&1 |
|
rm -rf /elwix/local /elwix/altroot/pkg/db |
|
cfexec ln -s ${PKG2CF}/db /elwix/altroot/pkg/db |
|
if [ $? -eq 127 ]; then |
|
ln -s ${PKG2CF}/db /elwix/altroot/pkg/db |
|
fi |
|
cfexec ln -s ${PKG2CF}/local /elwix/local |
|
if [ $? -eq 127 ]; then |
|
ln -s ${PKG2CF}/local /elwix/local |
|
fi |
|
mount -ur /elwix/cf |
|
fi |
|
echo "ELWIX pkg2cf setup complete." |
|
;; |
|
boot2) |
|
echo "ELWIX setup boot from second image" |
|
if [ -c $ELWIX2 ]; then |
|
cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" -JSs currdev /boot/loader.conf.local "disk0f:" |
|
cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local |
|
rm -f /tmp/loader.conf.local.tmp |
|
else |
|
die "ERROR:: ELWIX has no second usable image!" |
|
fi |
|
echo "ELWIX boot2 setup complete." |
|
;; |
|
boot) |
|
echo "ELWIX setup boot from main image" |
|
cfger -o /tmp/loader.conf.local.tmp -c "Edit by /etc/rc.cfg" -JSs currdev /boot/loader.conf.local "disk0a:" |
|
cfexec cp /tmp/loader.conf.local.tmp /boot/loader.conf.local |
|
rm -f /tmp/loader.conf.local.tmp |
|
echo "ELWIX boot setup complete." |
|
;; |
*) |
*) |
echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade)" | echo "Missing parameter - available options are (load | save | erase | backup | restore | upgrade | pkg_load | pkg_save | pkg2cf | boot2 | boot)" |
;; |
;; |
esac |
esac |
|
|