Skip to content

Commit

Permalink
Uninstallation script
Browse files Browse the repository at this point in the history
  • Loading branch information
Sterbweise committed Dec 10, 2024
1 parent 58bd51c commit 8929382
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 53 deletions.
107 changes: 55 additions & 52 deletions .config/utility/confirmUninstall.sh
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
# Function to confirm uninstallation
# This provides a safety check before proceeding with uninstallation
confirmUninstall() {
stty sane
local uninstallDotnet=false
local uninstallWine=false
local disable_32bit=false
local uninstallFirewall=false
local uninstallGameBinaries =false
local uninstallGameBinaries=false

while true; do
printf "${COLORS[YELLOW]}$(getMessage "uninstall_options")${COLORS[RESET]}\n"
printf "[1] $(getMessage "uninstallDotnet") [%s]\n" "$(if $uninstallDotnet; then echo "Y"; else echo "N"; fi)"
printf "[2] $(getMessage "uninstallWine") [%s]\n" "$(if $uninstallWine; then echo "Y"; else echo "N"; fi)"
printf "[3] $(getMessage "disable_32bit") [%s]\n" "$(if $disable_32bit; then echo "Y"; else echo "N"; fi)"
printf "[4] $(getMessage "uninstallFirewall") [%s]\n" "$(if $uninstallFirewall; then echo "Y"; else echo "N"; fi)"
printf "[5] $(getMessage "uninstallGameBinaries ") [%s]\n" "$(if $uninstallGameBinaries ; then echo "Y"; else echo "N"; fi)"
printf "${COLORS[RED]}[6] $(getMessage "uninstall_selected")${COLORS[RESET]}\n"
printf "[0] $(getMessage "cancel")\n\n"
printf "$(getMessage "select_option") "
read -r option
echo # New line after input
case $option in
1)
uninstallDotnet=!$uninstallDotnet
;;
2)
uninstallWine=!$uninstallWine
;;
3)
disable_32bit=!$disable_32bit
;;
4)
uninstallFirewall=!$uninstallFirewall
;;
5)
uninstallGameBinaries =!$uninstallGameBinaries
;;
6)
printf "${COLORS[RED]}$(getMessage "confirmUninstall_selected")${COLORS[RESET]}\n"
printf "$(getMessage "confirm_prompt") "
read -n 1 -r confirm
echo # New line after input
if [[ "$confirm" =~ ^[yYoO]$ ]]; then
if $uninstallDotnet; then uninstallDotnet; fi
if $uninstallWine; then uninstallWine; fi
if $disable_32bit; then disable_32bit; fi
if $uninstallFirewall; then uninstallFirewall; fi
if $uninstallGameBinaries ; then uninstallGameBinaries ; fi
break
fi
;;
0)
printf "${COLORS[YELLOW]}$(getMessage "uninstall_cancelled")${COLORS[RESET]}\n"
exit 0
;;
*)
echo "$(getMessage "invalid_input")"
;;
esac
done
# Display warning message
printf "\n${COLORS[RED]}WARNING: This will completely remove T6 Server and its dependencies.${COLORS[RESET]}\n"
printf "${COLORS[YELLOW]}Are you sure you want to continue? (y/N): ${COLORS[RESET]}"

read -r confirm

# Convert input to lowercase for case-insensitive comparison
confirm=$(echo "$confirm" | tr '[:upper:]' '[:lower:]')

if [[ "$confirm" != "y" && "$confirm" != "yes" ]]; then
printf "\n${COLORS[GREEN]}Uninstallation cancelled.${COLORS[RESET]}\n"
exit 0
fi

# Prompt for specific component uninstallation
printf "\n${COLORS[CYAN]}Select components to uninstall:${COLORS[RESET]}\n"

# Dotnet uninstallation
printf "Uninstall .NET Framework? [y/N]: "
read -r dotnet_choice
dotnet_choice=$(echo "$dotnet_choice" | tr '[:upper:]' '[:lower:]')
[[ "$dotnet_choice" == "y" || "$dotnet_choice" == "yes" ]] && uninstallDotnet=true

# Wine uninstallation
printf "Uninstall Wine? [y/N]: "
read -r wine_choice
wine_choice=$(echo "$wine_choice" | tr '[:upper:]' '[:lower:]')
[[ "$wine_choice" == "y" || "$wine_choice" == "yes" ]] && uninstallWine=true

# Firewall uninstallation
printf "Remove firewall configuration? [y/N]: "
read -r firewall_choice
firewall_choice=$(echo "$firewall_choice" | tr '[:upper:]' '[:lower:]')
[[ "$firewall_choice" == "y" || "$firewall_choice" == "yes" ]] && uninstallFirewall=true

# Game binaries uninstallation
printf "Remove game binaries? [y/N]: "
read -r binaries_choice
binaries_choice=$(echo "$binaries_choice" | tr '[:upper:]' '[:lower:]')
[[ "$binaries_choice" == "y" || "$binaries_choice" == "yes" ]] && uninstallGameBinaries=true

# Disable 32-bit packages
printf "Disable 32-bit packages? [y/N]: "
read -r bit_choice
bit_choice=$(echo "$bit_choice" | tr '[:upper:]' '[:lower:]')
[[ "$bit_choice" == "y" || "$bit_choice" == "yes" ]] && disable_32bit=true

# Export variables for use in other scripts
export uninstallDotnet
export uninstallWine
export disable_32bit
export uninstallFirewall
export uninstallGameBinaries
}
66 changes: 66 additions & 0 deletions .config/utility/finishUninstallation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Description:
# This script contains the finishUninstallation function, which is used to display
# a summary of the server uninstallation.

# Usage:
# This script is used to display a summary of the server uninstallation.

# Note:
# This script should be called after the server uninstallation is complete.

finishUninstallation() {
showLogo
printf "\n${COLORS[GREEN]}%s${COLORS[RESET]}\n" "$(getMessage "finish")"
printf "\n${COLORS[YELLOW]}%s${COLORS[RESET]}\n" "$(getMessage "quit")"

# Display summary of uninstalled components
printf "\n${COLORS[CYAN]} Uninstallation Summary:${COLORS[RESET]}\n"

if ! command -v ufw &> /dev/null ; then
printf " - ${COLORS[GREEN]}${COLORS[RESET]} Firewall uninstalled\n"
else
printf " - ${COLORS[RED]}${COLORS[RESET]} Firewall still present\n"
fi

if ! command -v dotnet &> /dev/null ; then
printf " - ${COLORS[GREEN]}${COLORS[RESET]} .NET Framework uninstalled\n"
else
printf " - ${COLORS[RED]}${COLORS[RESET]} .NET Framework still present\n"
fi

if ! command -v wine &> /dev/null ; then
printf " - ${COLORS[GREEN]}${COLORS[RESET]} Wine uninstalled\n"
else
printf " - ${COLORS[RED]}${COLORS[RESET]} Wine still present\n"
fi

# Check if game directory exists
if [ ! -d "${WORKDIR:-/opt/T6Server}" ]; then
printf " - ${COLORS[GREEN]}${COLORS[RESET]} Game binaries removed\n"
else
printf " - ${COLORS[RED]}${COLORS[RESET]} Game binaries still present\n"
fi

# System cleanup information
printf "\n${COLORS[CYAN]} Cleanup Information:${COLORS[RESET]}\n"
printf " - Previous Installation Directory: %s\n" "${WORKDIR:-/opt/T6Server}"
printf " - Operating System: %s %s\n" "${DISTRO^}" "$VERSION"

# System Resources After Cleanup
printf "\n${COLORS[CYAN]} System Resources After Cleanup:${COLORS[RESET]}\n"
checkAndInstallCommand "free" "procps"
TOTAL_RAM=$(free -h | awk '/^Mem:/ {print $2}')
FREE_RAM=$(free -h | awk '/^Mem:/ {print $4}')
DISK_SPACE=$(df -h "${WORKDIR:-/opt/T6Server}" | awk 'NR==2 {print $4}')

printf " - Total RAM: %s\n" "$TOTAL_RAM"
printf " - Available RAM: %s\n" "$FREE_RAM"
printf " - Available Disk Space: %s\n" "$DISK_SPACE"

# Wait for user acknowledgment
printf "\n${COLORS[YELLOW]}Press any key to exit...${COLORS[RESET]}"
stty sane
read -r
echo
exit 0
}
2 changes: 1 addition & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ showProgressIndicator "$(getMessage "cleanup")"

# Display completion message
# Informs the user that the uninstallation process is complete
finishInstallation
finishUninstallation

# Reset terminal settings and exit
# Ensures the terminal is left in a clean state after script execution
Expand Down

0 comments on commit 8929382

Please sign in to comment.