#!/bin/sh -e
umask 022
if ./command/install-post
then
   echo 'OK: Set owners and permissions on executables.'
else
   echo 'FATAL: Post-install failed.'
   exit -1
fi

if ./command/install-cleanq
then
  echo 'OK: Installed scanner queue and cleanq app.'
else
  echo 'FATAL: Installation of cleanq failed.'
  exit -1
fi

CT="`which crontab`"
U="`head -1 ./src/conf-users`"
S="`head -1 ./src/conf-spool`"
if setuidgid "$U" "$CT" "$S"/root/crontab
then
  echo 'OK: Installed crontab for' "$U"
else
  echo "WARNING: Don't forget to install $S/root/crontab for $U"
fi

test -d /service || ( echo 'FATAL: Forgot to install daemontools.'; exit 1 )
D="`basename \"$S\"`"
if test -h /service/"$D"
then
  echo 'OK: Cleanq service apparently already installed'
elif ln -s "$S" /service/
then
  echo 'OK: Installed cleanq service.'
else
  echo "WARNING: Couldn't link" "$S to /service/"
fi

# Last reminder.
echo 'NOTE: Don'\''t forget to run ./command/install-wrap!'
