#!/bin/sh
# 4014-migrate-to-Pt-storage.sh
# 
#  Copyright: ©2011, Güralp Systems Ltd.
#  Author: Laurence Withers <lwithers@guralp.com>
#  License: GPLv3
#

OLDCF="/etc/rdisk/rdisk.local"
NEWCF="/etc/Pt-storage/Pt-storage.local"
TPL="/etc/Pt-storage/Pt-storage.tpl"

[ -e "${OLDCF}" ] || exit 0

echo " * Migrating from rdisk to Pt-storage"

# normally the template would be instantiated by a later script, but since we
# need to edit the instance here we must short-circuit this process
if [ ! -e "${NEWCF}" ]
then
	cp "${TPL}" "${NEWCF}" || exit 1
fi

# copy salient user settings from rdisk.local
dest="`gcs_rwvar 'gcs_get_varcf2' 'destination' "${OLDCF}" ''`"
[ -n "${dest}" ] && gcs_rwvar 'gcs_set_varcf2' 'destination' "${NEWCF}" "${dest}" ''

if gcs_rwvar 'gcs_is_true_varcf2' 'continuous_power' "${OLDCF}" ''
then
	gcs_rwvar 'gcs_set_varcf2' 'continuous_power' "${NEWCF}" 'true' ''
fi
