post_install() {
  cd /usr/lib/sage

  # add sagemath user for the daemon
  useradd -r -c 'Sage daemon' -d /usr/lib/sage -s /bin/false sagemath

  # Update LaTeX db to point to SageTeX
  if [ -f /usr/bin/texhash ]; then
    /usr/bin/texhash /usr/share/texmf
  else
    echo 'Warning: could not find /usr/bin/texhash'
    echo 'SageTeX has been installed but you need to run:'
    echo '# texhash /usr/share/texmf'
    echo 'So that LaTeX will be able to find it.'
  fi

echo '
 ___                       
/ (_)        o            |
\__   _  _      __        |
/    / |/ |  | /  \_|   | |
\___/  |  |_/|/\__/  \_/|/o
            /|         /|  
            \|         \|  
 ________________________________ 
< sagemath, I mean, MOO! >
 -------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
'

}

post_upgrade() {
  post_install $1
  echo "There is now a user session unit included to run a sage notebook as your user."
  echo "The wiki includes a guide on starting systemd user sessions"
}

post_remove() {
  # Update LaTeX db to remove SageTeX entries
  if [ -f /usr/bin/texhash ]; then
    /usr/bin/texhash /usr/share/texmf
  fi

  # remove the sagemath daemon user
  userdel sagemath

  # clean up left overs
  rm -rf /usr/lib/sage
}
