#!/usr/bin/python3
# Executed on deinstallation
# Completely remove howdy from the system

# Import required modules
import subprocess
import sys
import os

# Only run when we actually want to remove
if "remove" not in sys.argv and "purge" not in sys.argv:
	sys.exit(0)

# Don't try running this if it's already gome
if not os.path.exists("/lib/security/howdy/cli"):
	sys.exit(0)

# Remove files and symlinks
try:
	subprocess.call(["rm /usr/local/bin/howdy"], shell=True)
except e:
	print("Can't remove executable")
try:
	subprocess.call(["rm /usr/share/bash-completion/completions/howdy"], shell=True)
except e:
	print("Can't remove autocompletion script")

# Refresh and remove howdy from pam-config
try:
	subprocess.call(["pam-auth-update --package"], shell=True)
	subprocess.call(["rm /usr/share/pam-configs/howdy"], shell=True)
	subprocess.call(["pam-auth-update --package"], shell=True)
except e:
	print("Can't remove pam module")

# Remove full installation folder, just to be sure
try:
	subprocess.call(["rm -rf /lib/security/howdy"], shell=True)
except e:
	# This error is normal
	pass

# Remove face_recognition and dlib
subprocess.call(["pip3 uninstall face_recognition face_recognition_models dlib -y --no-cache-dir"], shell=True)
