Skip to content

Instantly share code, notes, and snippets.

@ChrisColeTech
Last active August 17, 2025 18:56
Show Gist options
  • Select an option

  • Save ChrisColeTech/fa65773ebbdd4956678327841a895669 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisColeTech/fa65773ebbdd4956678327841a895669 to your computer and use it in GitHub Desktop.
Test script for toast notification installation - uninstalls and reinstalls both Windows and WSL components
#!/usr/bin/env bash
# Test script for toast notification installation
# This script uninstalls and reinstalls both Windows and WSL toast components
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
echo "=== Toast Notification Test Script ==="
echo
# Detect environment and set Windows mount path
WIN_MOUNT=""
POWERSHELL_PATH=""
if [[ -d "/mnt/c" ]]; then
WIN_MOUNT="/mnt/c"
POWERSHELL_PATH="/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
print_status "Detected: WSL environment"
elif [[ -d "/c" ]] || mount | grep -q "/c"; then
WIN_MOUNT="/c"
# Use PowerShell 7 if available for better module support in MSYS2
if [[ -f "/c/Program Files/PowerShell/7/pwsh.exe" ]]; then
POWERSHELL_PATH="/c/Program Files/PowerShell/7/pwsh.exe"
print_status "Detected: MSYS2/Git Bash environment (using PowerShell 7)"
else
POWERSHELL_PATH="powershell.exe"
print_status "Detected: MSYS2/Git Bash environment (using PowerShell 5.1)"
fi
else
print_error "Neither /mnt/c nor /c Windows mount points found"
print_error "This script requires WSL or MSYS2/Git Bash environment"
exit 1
fi
# Step 1: Uninstall WSL components
print_status "Step 1: Uninstalling WSL toast components..."
print_status "Downloading WSL uninstaller..."
if curl -fsSL 'https://gist.githubusercontent.com/ChrisColeTech/42d5862c4817c269ef6aa42f7ff490ce/raw/wsl_toast_uninstall.sh' -o ~/uninstall_toast_wsl.sh; then
print_status "Running WSL uninstaller..."
bash ~/uninstall_toast_wsl.sh
rm -f ~/uninstall_toast_wsl.sh
print_status "WSL uninstall completed"
else
print_error "Failed to download WSL uninstaller"
exit 1
fi
echo
# Step 2: Uninstall Windows components
print_status "Step 2: Uninstalling Windows toast components..."
print_status "Downloading Windows uninstaller..."
if curl -fsSL 'https://gist.githubusercontent.com/ChrisColeTech/c7c8d4fb8f8e72ac01722cb5d5ce79f9/raw/windows_toast_uninstall.ps1' -o /tmp/windows_uninstall.ps1; then
# Find Windows username - prefer current user if available
print_status "Detecting Windows username..."
WINDOWS_USER=""
# First try to use current user if it exists in Windows Users
current_user="$(whoami)"
if [[ -d "$WIN_MOUNT/Users/$current_user/Documents" ]]; then
WINDOWS_USER="$current_user"
print_status "Using current user: $WINDOWS_USER"
else
# Fall back to searching for valid users, excluding virtual/service accounts
for user_dir in "$WIN_MOUNT/Users/"*/; do
if [[ -d "$user_dir" && ! "$user_dir" =~ (Public|Default|All\ Users|BvSsh_VirtualUsers|sftpuser) ]]; then
username=$(basename "$user_dir")
if [[ -d "$WIN_MOUNT/Users/$username/Documents" ]]; then
WINDOWS_USER="$username"
print_status "Found Windows user: $WINDOWS_USER"
break
fi
fi
done
fi
if [[ -n "$WINDOWS_USER" && -d "$WIN_MOUNT/Users/$WINDOWS_USER" ]]; then
# Try Downloads folder first, fall back to temp if not writable
target_path="$WIN_MOUNT/Users/$WINDOWS_USER/Downloads/windows_uninstall.ps1"
win_target_path="C:\\Users\\$WINDOWS_USER\\Downloads\\windows_uninstall.ps1"
if ! cp /tmp/windows_uninstall.ps1 "$target_path" 2>/dev/null; then
print_warning "Downloads folder not writable, using temp directory"
target_path="$WIN_MOUNT/temp/windows_uninstall.ps1"
win_target_path="C:\\temp\\windows_uninstall.ps1"
mkdir -p "$WIN_MOUNT/temp"
cp /tmp/windows_uninstall.ps1 "$target_path"
fi
print_status "Running Windows uninstaller for user: $WINDOWS_USER"
"$POWERSHELL_PATH" -ExecutionPolicy Bypass -File "$win_target_path" -Force
rm -f "$target_path"
print_status "Windows uninstall completed"
else
print_error "Could not determine Windows username"
exit 1
fi
rm -f /tmp/windows_uninstall.ps1
else
print_error "Failed to download Windows uninstaller"
exit 1
fi
echo
# Step 3: Install both components using WSL installer
print_status "Step 3: Installing toast notifications (both Windows and WSL)..."
print_status "Downloading WSL installer from gist..."
if curl -fsSL 'https://gist.githubusercontent.com/ChrisColeTech/010a3a1f313fa39a10566a328c32424b/raw/wsl_toast_install.sh' -o ~/install_toast_wsl.sh; then
print_status "Downloaded WSL installer successfully"
print_status "File size: $(ls -lh ~/install_toast_wsl.sh | awk '{print $5}')"
print_status "Running WSL installer (with 30 second timeout)..."
timeout 30 bash ~/install_toast_wsl.sh
exit_code=$?
if [[ $exit_code -eq 0 ]]; then
print_status "WSL installer completed successfully"
else
print_error "WSL installer failed with exit code: $exit_code"
fi
rm -f ~/install_toast_wsl.sh
else
print_error "Failed to download WSL installer"
exit 1
fi
echo
# Step 4: Test the installation
print_status "Step 4: Testing toast notification functionality..."
export PATH="$HOME/bin:$PATH"
# Source shell configuration to load toast function
if [[ -f ~/.zshrc ]]; then
source ~/.zshrc
elif [[ -f ~/.bashrc ]]; then
source ~/.bashrc
fi
# Test the toast function
if command -v toast >/dev/null 2>&1; then
toast "Test Complete" "Toast notification system is working correctly!"
print_status "✓ Toast notification test successful!"
else
print_error "Toast command not found after installation"
exit 1
fi
echo
print_status "=== Test Script Complete ==="
print_status "Toast notification system has been successfully uninstalled and reinstalled."
print_status "You should have seen a test notification appear."
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment