#!/bin/bash
##
# Prepare default storage

set -eu

CONFIGURATION="${FIRSTBOOT_DATA_DIR}/default-storage.conf"

. "/opt/xensource/lib/storage-creation-utils.sh"
UPGRADE="false"
[ -r ${FIRSTBOOT_DATA_DIR}/host.conf ] && . ${FIRSTBOOT_DATA_DIR}/host.conf


start() {
    [ "$UPGRADE" = true ] && return 0
    vgchange -a n || true

    if [ -e "$CONFIGURATION" ]; then
        # the configuration file exists - load it and create storage
        # as required:
        source "$CONFIGURATION"
        case "$TYPE" in
            ext)    mk_ext_sr "$PARTITIONS" ;;
            lvm)    mk_lvm_sr "$PARTITIONS" ;;
        esac
    else
	# CA-13146: upgrade Rio local storage
	uuid=`xe sr-list name-label="Local storage on $(hostname)" | sed -ne 's/^uuid .*: //p'`
	if [ -n "$uuid" ]; then
	    $XE sr-param-set uuid="$uuid" name-label="Local storage"
	    $XE sr-param-set uuid="$uuid" other-config:i18n-key="local-storage"
	    $XE sr-param-set uuid="$uuid" other-config:i18n-original-value-name_label="Local storage"
	fi
    fi
}

case $1 in
    start)  start ;;
esac
