post_install() {
  if ! getent group tor &>/dev/null; then
    groupadd -g 43 tor >/dev/null
  fi
  if ! getent passwd tor &>/dev/null; then
    useradd -u 43 -g tor -d /var/lib/tor -s /bin/nologin tor >/dev/null
  fi
  tor_shell=$(getent passwd tor | cut -d: -f7)
  if [ "$tor_shell" != '/bin/nologin' ]; then
    chsh -s /bin/nologin tor &>/dev/null
  fi
}

post_upgrade() {
  post_install
}

post_remove() {
  if getent passwd tor &>/dev/null; then
    userdel tor >/dev/null
  fi
  if getent group tor &>/dev/null; then
    groupdel tor >/dev/null
  fi
}
