#!/bin/bash
clear
echo "========================================================"
echo "      Mac Classroom Software Detector"
echo "========================================================"
echo ""

# Initialize flags
AB_FOUND=0
LAN_FOUND=0
NET_FOUND=0
GO_FOUND=0
IMP_FOUND=0

# ---------------------------------------------------------
# 1. SCANNING FOR AB TUTOR
# ---------------------------------------------------------
if [ -d "/Applications/AB Tutor Student.app" ]; then
    AB_FOUND=1
fi
# Check process
if pgrep -x "ABClient" >/dev/null; then
    AB_FOUND=1
fi

if [ $AB_FOUND -eq 1 ]; then
    echo "[DETECTED] AB Tutor Student"
fi

# ---------------------------------------------------------
# 2. SCANNING FOR LANSCHOOL
# ---------------------------------------------------------
if [ -d "/Applications/LanSchool Student.app" ]; then
    LAN_FOUND=1
fi
if pgrep -f "LanSchool" >/dev/null; then
    LAN_FOUND=1
fi

if [ $LAN_FOUND -eq 1 ]; then
    echo "[DETECTED] LanSchool Student"
fi

# ---------------------------------------------------------
# 3. SCANNING FOR NETSUPPORT SCHOOL
# ---------------------------------------------------------
if [ -d "/Applications/NetSupport/NetSupport Student.app" ]; then
    NET_FOUND=1
fi

if [ $NET_FOUND -eq 1 ]; then
    echo "[DETECTED] NetSupport School"
fi

# ---------------------------------------------------------
# 4. SCANNING FOR GO GUARDIAN / CHROME
# ---------------------------------------------------------
# GoGuardian is usually a Chrome Extension.
# We check if Google Chrome is installed and running.
if pgrep -x "Google Chrome" >/dev/null; then
    GO_FOUND=1
fi

if [ $GO_FOUND -eq 1 ]; then
    echo "[DETECTED] Google Chrome is running (Potential GoGuardian)"
fi

# ---------------------------------------------------------
# 5. SCANNING FOR IMPERO
# ---------------------------------------------------------
if [ -d "/Applications/ImperoClient.app" ]; then
    IMP_FOUND=1
fi

if [ $IMP_FOUND -eq 1 ]; then
    echo "[DETECTED] Impero Client"
fi

echo ""
echo "Scan Complete. Generating instructions..."
echo "========================================================"
echo ""

# ---------------------------------------------------------
# INSTRUCTIONS
# ---------------------------------------------------------

if [ $AB_FOUND -eq 1 ]; then
    echo "--- INSTRUCTIONS FOR AB TUTOR ---"
    echo "1. Open Finder and go to the 'Applications' folder."
    echo "2. Look for 'AB Tutor Student'."
    echo "3. Drag it to the Trash bin."
    echo "4. Empty the Trash."
    echo "NOTE: If it reappears or asks for a password, it is managed by MDM."
    echo "---------------------------------"
    echo ""
fi

if [ $LAN_FOUND -eq 1 ]; then
    echo "--- INSTRUCTIONS FOR LANSCHOOL ---"
    echo "1. LanSchool on Mac is very sticky."
    echo "2. Open Finder > Applications."
    echo "3. Look for 'LanSchool Student'."
    echo "4. Right-click and Move to Trash."
    echo "5. Restart your Mac."
    echo "TRICK: Turning off Wi-Fi stops it from connecting to the teacher."
    echo "----------------------------------"
    echo ""
fi

if [ $NET_FOUND -eq 1 ]; then
    echo "--- INSTRUCTIONS FOR NETSUPPORT ---"
    echo "1. Open Finder > Applications > NetSupport."
    echo "2. Run the 'NetSupport Uninstaller' if it exists."
    echo "3. If not, drag the whole NetSupport folder to Trash."
    echo "-----------------------------------"
    echo ""
fi

if [ $GO_FOUND -eq 1 ]; then
    echo "--- INSTRUCTIONS FOR GO GUARDIAN (Chrome) ---"
    echo "1. GoGuardian is inside Chrome, not the Mac itself."
    echo "2. Open Chrome."
    echo "3. Type 'chrome://extensions' in the address bar."
    echo "4. Look for GoGuardian."
    echo "5. If the 'Remove' button is missing or there is a building icon,"
    echo "   it is 'Managed by your organization' and cannot be deleted."
    echo "WORKAROUND: Use Safari or Firefox instead of Chrome."
    echo "---------------------------------------------"
    echo ""
fi

if [ $AB_FOUND -eq 0 ] && [ $LAN_FOUND -eq 0 ] && [ $NET_FOUND -eq 0 ] && [ $GO_FOUND -eq 0 ] && [ $IMP_FOUND -eq 0 ]; then
    echo "No specific monitoring apps found in the standard Applications folder."
    echo "Check 'System Settings > Privacy & Security > Profiles' to see if your Mac is managed."
fi