#!/bin/bash

# TigerOS script for the removal of unwanted major-specific packages
# Author: Tim Zabel <tjz8659@rit.edu>

# Check to see if the current user is root
if [ $EUID != 0 ]
then
    echo "Please run this script as root (sudo $@$0)."
    exit
fi
echo
echo -e "Welcome to the TigerOS package removal script.\n
This script will remove all files and packages installed for a specific major."
echo
PS3='Please enter a number: '
options=("CS" "IT/WMC" "NSSA/CIT" "SE" "Quit")
select opt in "${options[@]}"
do
    # all dnf commands here are done with the -y flag. Individual removals do not ask the user for permission beforehand
    case $opt in
        "CS")
            echo -e "Welcome to the TigerOS CS package removal script.\n
This script will remove Intellij idea, PyCharm, prolog, racket, and JFLAP from your machine."
            echo
            while true; do
                read -p "Do you wish to continue? [y/n] " yn
                case $yn in
                    [Yy]* ) break;;
                    [Nn]* ) exit;;
                esac
            done
            bash /usr/local/bin/cs/idea.sh --remove       # removes Intellij IDEA
            bash /usr/local/bin/cs/logisim.sh --remove    # removes logisim
            bash /usr/local/bin/cs/jflap.sh --remove      # removes JFLAP
            dnf remove -y pycharm-community
            rm /etc/yum.repos.d/_copr_phracek-PyCharm.repo
            echo "Removal finished."
            exit
            ;;
        "IT/WMC")
            echo -e "Welcome to the TigerOS IT/WMC package removal script.\n
This script will remove mysql, mongodb, subversion, filezilla, and nodejs from your machine."
            echo
            while true; do
                read -p "Do you wish to continue? [y/n] " yn
                case $yn in
                    [Yy]* ) break;;
                    [Nn]* ) exit;;
                esac
            done
            sudo dnf -y remove mongodb subversion filezilla nodejs php mysql-repo.rpm mysql-community-server
            semanage port -d -t mongod_port_t -p tcp 27017
            echo "Removal finished."
            exit
            ;;
        "NSSA/CIT")
            echo -e "Welcome to the TigerOS NSSA/CIT package removal script.\n
This script will remove wireshark, python 2.7, and python 3 from your machine."
            echo
            while true; do
                read -p "Do you wish to continue [y/n] " yn
                case $yn in
                    [Yy]* ) break;;
                    [Nn]* ) exit;;
                esac
            done
            sudo dnf -y remove wireshark --ignore-missing
            echo "Removal finished."
            exit
            ;;
        "SE" )
            echo -e "Welcome to the TigerOS Software Engineering removal script.\n
This script will remove ruby, eclipse, Spin, sqlite3 and MIT Alloy from your machine."
            echo
            while true; do
                read -p "Do you wish to continue? [y/n] " yn
                case $yn in
                    [Yy]* ) break;;
                    [Nn]* ) exit;;
                esac
            done
            sudo dnf -y remove eclipse-jdt ruby sqlite gitk plantuml --ignore-missing
            bash /usr/local/bin/se/spin.sh --remove       
            bash /usr/local/bin/se/alloy.sh --remove
            echo "Removal finished."
            exit
            ;;
        "Quit")
            break
            ;;
        *)
            echo "Invalid Option."
            ;;
    esac
done
