#!/bin/bash
logger -s "## postinst_header ##"

DPKG=${DPKG_MAINTSCRIPT_PACKAGE}
DSCRIPT=${DPKG_MAINTSCRIPT_NAME}
dpkgParam=( `echo ${@}` )
action=${dpkgParam[0]:-"none"}
# extract package name and container names
pkg_name=${DPKG}
pkg_id=${pkg_name%%-*}
pkg_gtype=${pkg_name#*-}
pkg_gtype=${pkg_gtype%%-*}; [ "$pkg_gtype" == "$pkg_id" ] && pkg_gtype=""
pkg_ctype=${pkg_name##*-};  [ "$pkg_ctype" == "$pkg_id" ] && pkg_ctype=""
isImage="true"
[ -n "$pkg_gtype" ] && [ -n "$pkg_ctype" ] && isImage="false"
echo "postinst: isImage=${isImage}"
echo "postinst: Master package name: ${pkg_id}"
[ -n "${pkg_gtype}" ] && echo "postinst: Group-container    : ${pkg_gtype}"
[ -n "${pkg_ctype}" ] && echo "postinst: Component-container: ${pkg_ctype}"
echo "postinst: ${DPKG}-${DSCRIPT}: action=${action}"
[ "${action}" == "install" ] && [ -f /tmp/fresh_install ] && echo "${DPKG}-${DSCRIPT}: host-install in progress, skipping" && exit 0
upgradeDevice=`cat /tmp/upgrade_device` 2>/dev/null
currentRootDevice=`cat /tmp/currentRootDevice` 2>/dev/null
upgradePart=`cat /tmp/upgrade_part`
upgradePart=${upgradePart:-""}
upgradePath=`cat /tmp/upgrade_path`
upgradePath=${upgradePath:-"/"}
echo "postinst: currentRootDevice=${currentRootDevice}"
echo "postinst: upgradeDevice=${upgradeDevice}"
echo "postinst: upgradePart=${upgradePart}"
echo "postinst: upgradePath=${upgradePath}"

## Configuration files
source "/etc/system.conf" 2>/dev/null
##
datVolumeFormat=${dataVolumeFormat:-"ext4"}
pkg_upgrades_dir=${pkg_upgrades_dir:-"/CacheVolume/upgrade"}
postinst_masterpkg="${pkg_upgrades_dir}/postinst_${pkg_id}"
postinst_all="${pkg_upgrades_dir}/postinst_all"
postinst_header="${pkg_upgrades_dir}/postinst_header"
postinst_footer="${pkg_upgrades_dir}/postinst_footer"
postinst_image="${pkg_upgrades_dir}/postinst_image"
postinst_container="${pkg_upgrades_dir}/postinst_container"
