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


def col(id):
    """Add color escape sequences"""
    if id == 1: return "\033[32m"
    if id == 2: return "\033[33m"
    if id == 3: return "\033[31m"
    return "\033[0m"


# 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/hi"):
    sys.exit(0)

# Remove files and symlinks
try:
    subprocess.call(["rm /usr/local/bin/hi"], shell=True)
except e:
    print("Can't remove executable")
try:
    subprocess.call(["rm /usr/share/bash-completion/completions/hi"], shell=True)
except e:
    print("Can't remove autocompletion script")
try:
    subprocess.call(["rm -rf /lib/security/hi"], shell=True)
except e:
    # This error is normal
    pass

# Print a tearbending message
print(col(2) + """
There are still lines in /etc/pam.d/common-auth that can't be removed automatically
Run "nano /etc/pam.d/common-auth" to remove them by hand\
""" + col(0))
