# boot_migrate
# MPG
#
# general purpose migrate file.  
# gets source by /init.d/boot.local once NFCMS complete and before runlevels start.
# boot.local deletes this file once complete

HD0=/media/hd0
FOLDER_LIST="rdy media dvc dvc list osd shd schmi mvl"
DPI_DOLDER_LIST="rdy schins verins"
SYS_FOLDER_LIST="log .meta"

OSD_LIST="jpeg jpg bmp png"
LIST_TYPE=smil
DVC_TYPE=dvc
MLF_MVL="mvl mlf"


if [ ! -e $HD0 ]; then   # large banner, no logger?
   logger -s -t "[MIGRATE]" -p user.warn "WARNING: No mounted drive found!"
   logger -s -t "[MIGRATE]" -p user.warn "WARNING: No mounted drive found!"
   logger -s -t "[MIGRATE]" -p user.warn "WARNING: No mounted drive found!"
   logger -s -t "[MIGRATE]" -p user.warn "WARNING: No mounted drive found!"
   exit 1
fi

# make folders if not exist
for FOLD in $FOLDER_LIST; do
  if [ ! -e ${HD0}/${FOLD} ]; then
    mkdir ${HD0}/${FOLD}
  fi
  chown adtec:users ${HD0}/${FOLD}
  chmod g+s ${HD0}/${FOLD}
done
logger -s -t "[MIGRATE]" -p user.info "Checked main folders in ${HD0}"

# make system folders
for FOLD in $SYS_FOLDER_LIST; do
  if [ ! -e ${HD0}/${FOLD} ]; then
    mkdir ${HD0}/${FOLD}
    chown root:root ${HD0}/${FOLD}
  	 chmod 755 ${HD0}/${FOLD}
    logger -s -t "[MIGRATE]" -p user.info "Checked system folders in ${HD0}"
  fi
done

# make dpi folders
. etc/env.global
if [ "$PRODUCT" == "dpi" ]; then
	for FOLD in $DPI_FOLDER_LIST; do
	  if [ ! -d ${HD0}/${FOLD} ]; then
	     mkdir ${HD0}/${FOLD}
	  fi
	  chown adtec:users ${HD0}/${FOLD}
	  chmod g+s ${HD0}/${FOLD}
	done
	logger -s -t "[MIGRATE]" -p user.info "Created dpi folders in ${HD0}" 
fi


# update services file for syslog to use port 1514
# we put this here since services got migrated and an update has to be after it here.
# MPG - commenting since this will overwrite what was migrated.  Installers have to manually
# set the proper port.  We could test out for an unmodified file (setting at 514), but if 
# someone wants to use 514 we would be overwriting it each upgrade.
#/bin/sed -i "s/\(^syslog[[:space:]]\{1,\}\)[0-9]*\(\/udp$\)/\11514\2/" /etc/services

# get the HIP and set the BARK server.  After this, mirror will maintain it
BARK_SRV=$(/usr/local/bin/mirror HOSTIPADDRESS)
/usr/local/bin/bark -h $BARK_SRV

# update syslog.conf with BARK SRV
COUNT=$(grep -c daemon.notice /etc/syslog.conf)  # get count of daemon.notice
if [ $COUNT -eq 0 ]; then
   sed -i -e 's/\([.*]\)\( *-\/var\/log\/all\)/\1;daemon.!notice\2/' /etc/syslog.conf
   sed -i -e 's/\(local1.notice\)\(.*\)/\1;daemon.notice\2/' /etc/syslog.conf
fi

# add the error pipe
COUNT=$(grep -c '/var/log/error' /etc/syslog.conf)  # get count of var/log/error
if [ $COUNT -eq 0 ]; then
   echo -e "\ndaemon.error          |/var/log/error" >> /etc/syslog.conf
fi
