#!/bin/bash
# firstboot_085_dlna-server-accesss
# this file should be removed as soon as ldconfig happens in a base package
##
PKG=${PKG:-"dlna-server-access"}
logtag="[`basename $0`] `date -u +"%D %T"`"
logger -s -t "${logtag}" "( $@ ) begin"

. /etc/system.conf
. /etc/nas/config/${PKG}.conf 2>/dev/null

# boot type and pkg version
boot="${1}"
pkg_version="${2}"

update_dlna_device_description()
{
    # there is new data in dms_descr.xml; regenerate it from the prototype
    # BEFORE it is copied to the new root file system
    cp /etc/wdcomp.d/dlna-server-access/saved_settings/usr/local/dlna-access/xml/dms_descr.xml \
      /usr/local/dlna-access/xml/dms_descr.xml
    /usr/local/sbin/modDlnaDeviceDescription.sh
}

updateboot ()
{

    # remove this when firstboot_000_wd-nas is added to ap2nc AND when
    # firstboot runs before the user services
    /sbin/ldconfig

    update_dlna_device_description
}

freshboot ()
{
    ## re-save any 'twonky binaries' after factory-restore
    [ -f /etc/wdcomp.d/upgrade/upgrade-patch_twonkymediaserver-hollow ] && \
    /etc/wdcomp.d/upgrade/upgrade-patch_twonkymediaserver-hollow '/'
    
    # remove this when firstboot_000_wd-nas is added to ap2nc AND when
    # firstboot runs before the user services
    /sbin/ldconfig

    update_dlna_device_description
}

systemboot ()
{
    return 0
}
 
case "${boot}" in
    boot-update ) updateboot ;;
    boot-fresh  ) freshboot  ;;
    boot-system ) systemboot ;;    
    *           ) ;;
esac

logger -s -t "${logtag}" "done"
