#!/bin/bash
# postinst-patch_apnc
echo "postinst-patch_apnc: $@"
PKG=${1}
upgradePath=${2:-"/"}

. ${upgradePath}/etc/system.conf 2>/dev/null

## handle orphaned resources ##
if [ -n "${upgradeDevice}" ]; then
    # can these be moved into a component postinst?
    cp -v /etc/.eula_accepted ${upgradeMountPath}/etc/.eula_accepted  
    cp -a /var/local/nas_file_tally ${upgradeMountPath}/var/local
    cp -av /etc/resolv.conf ${upgradeMountPath}/etc/resolv.conf
    echo "Copy saved logs (except sshd.log)..."
    rm -v /var/log/sshd.log
    cp -a /var/log ${upgradeMountPath}/var/
fi

## save cached debs accross factory-restore
if [ -d ${pkg_upgrades_dir} ]; then
    mkdir -p ${upgradePath}/usr/local/nas/upgrade
    rm -rf ${upgradePath}/usr/local/nas/upgrade/*
    cp -rpvf ${pkg_upgrades_dir}/* ${upgradePath}/usr/local/nas/upgrade
fi

exit 0
