#!/bin/sh

set -e

if test "$DEBUG_CUSTOM_ACTIONS" = "1" -o                   \
        -r /tmp/INFINIDAT_DEBUG_CUSTOM_ACTIONS; then
    set -xv
else
    exec > /dev/null 2>&1
fi

if test "$NO_CUSTOM_ACTIONS" = "1" -o                      \
        -r /tmp/INFINIDAT_NO_CUSTOM_ACTIONS; then
    exit 0
fi

echo "Start {{ package }} {{ version }} post-install script: $0 $@"

if test ! -d "{{ prefix }}"; then
    exit 0
fi

export ODMDIR=/etc/objrepos

echo "Cleaning up old Infinidat ODM definitions..."
sh "{{ prefix }}/infinidat_clean_odm"

echo "Importing Infinidat ODM definitions..."
odmadd "{{ prefix }}/infinidat.odm"

echo "Rebuilding the boot image with bosboot on rootvg disks to apply the new attributes..."
lsvg -M rootvg | awk -F: '/:/{print $1}' | sort | uniq | xargs -n 1 bosboot -ad

echo "Generating NFINIDAT message catalog..."
gencat /etc/methods/NFINIDAT.cat "{{ prefix }}/NFINIDAT.msg"

exit 0
