#!/bin/sh

for syml in /usr/sbin/sendmail /usr/bin/newaliases /usr/bin/mailq; do
  file=${IPKG_INSTROOT}${syml}
  if [ -f "${file}.old" ]; then
    # update files saved by legacy versions of Postfix postinst script
    mv "${file}.old" "${file}.pre-postfix"
  fi
  if [ -f "${file}" ]; then
    linktarget=$(basename $(readlink "${file}"))
    postfixf=$(basename "${syml}").postfix
    if [ ${linktarget} != ${postfixf} ]; then
      mv "${file}" "${file}.pre-postfix"
      echo "Info: ${file} saved as ${file}.pre-postfix"
    fi
  fi
  if [ ! -f "${file}" ]; then
    ln -s "${syml}.postfix" "${file}"
  fi
done
# fix file/dir ownership in data_directory and queue_directory
if [ -z "${IPKG_INSTROOT}" ]; then
  postfix set-permissions
fi

