#!/bin/bash # ============================================================================= # Linux-BF: Bangla Font Uninstaller for Linux # Author: @abusayed0206 # Website: https://banglafont.pages.dev # GitHub: https://github.com/abusayed0206/linux-bf # Description: Universal uninstaller for Bangla fonts on all major Linux distros # ============================================================================= set -euo pipefail # Exit on error, undefined vars, pipe failures # Colors and formatting RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' MAGENTA='\033[0;35m' CYAN='\033[0;36m' WHITE='\033[1;37m' NC='\033[0m' # No Color BOLD='\033[1m' # Configuration SCRIPT_NAME="Linux-BF Uninstaller" VERSION="2.0.0" USER_FONTS_DIR="$HOME/.local/share/fonts/bangla-fonts" SYSTEM_FONTS_DIR="/usr/share/fonts/bangla-fonts" LOG_FILE="/tmp/linux-bf-uninstall.log" # Default options UNINSTALL_MODE="user" # user, system, or all FORCE_UNINSTALL=false DRY_RUN=false VERBOSE=false # ============================================================================= # Utility Functions # ============================================================================= log() { echo "$(date '+%Y-%m-%d %H:%M:%S'): $*" >> "$LOG_FILE" } print_header() { clear echo -e "${CYAN}${BOLD}" echo "┌─────────────────────────────────────────────────────────────┐" echo "│ 🇧🇩 Linux-BF v$VERSION │" echo "│ Bangla Font Uninstaller for Linux │" echo "│ │" echo "│ Author: @abusayed0206 │" echo "│ Website: https://banglafont.pages.dev │" echo "└─────────────────────────────────────────────────────────────┘" echo -e "${NC}" } print_success() { echo -e "${GREEN}✓${NC} $1" log "SUCCESS: $1" } print_error() { echo -e "${RED}✗${NC} $1" >&2 log "ERROR: $1" } print_warning() { echo -e "${YELLOW}⚠${NC} $1" log "WARNING: $1" } print_info() { echo -e "${BLUE}ℹ${NC} $1" log "INFO: $1" } print_step() { echo -e "${MAGENTA}▶${NC} ${BOLD}$1${NC}" log "STEP: $1" } # ============================================================================= # Font Detection and Removal Functions # ============================================================================= check_installed_fonts() { local user_count=0 local system_count=0 local user_fonts=() local system_fonts=() # Check user fonts if [[ -d "$USER_FONTS_DIR" ]]; then while IFS= read -r -d '' font; do user_fonts+=("$font") user_count=$((user_count + 1)) done < <(find "$USER_FONTS_DIR" -name "*.ttf" -print0 2>/dev/null) fi # Check system fonts if [[ -d "$SYSTEM_FONTS_DIR" ]]; then while IFS= read -r -d '' font; do system_fonts+=("$font") system_count=$((system_count + 1)) done < <(find "$SYSTEM_FONTS_DIR" -name "*.ttf" -print0 2>/dev/null) fi # Display findings echo -e "${BOLD}${CYAN}Installed Bangla Fonts Status:${NC}\n" if [[ $user_count -gt 0 ]]; then echo -e "${GREEN}User Fonts Found:${NC} $user_count fonts in $USER_FONTS_DIR" if [[ $VERBOSE == true ]]; then for font in "${user_fonts[@]}"; do echo " - $(basename "$font")" done fi else echo -e "${YELLOW}User Fonts:${NC} None found" fi echo "" if [[ $system_count -gt 0 ]]; then echo -e "${GREEN}System Fonts Found:${NC} $system_count fonts in $SYSTEM_FONTS_DIR" if [[ $VERBOSE == true ]]; then for font in "${system_fonts[@]}"; do echo " - $(basename "$font")" done fi else echo -e "${YELLOW}System Fonts:${NC} None found" fi echo "" # Set globals for later use USER_FONT_COUNT=$user_count SYSTEM_FONT_COUNT=$system_count return 0 } get_uninstall_mode() { if [[ "$UNINSTALL_MODE" != "user" ]]; then return # Mode already set via command line fi # Auto-determine based on what's installed if [[ $USER_FONT_COUNT -gt 0 && $SYSTEM_FONT_COUNT -gt 0 ]]; then echo -e "${BOLD}Uninstall Options:${NC}" echo "1. Remove user fonts only ($USER_FONT_COUNT fonts)" echo "2. Remove system fonts only ($SYSTEM_FONT_COUNT fonts, requires sudo)" echo "3. Remove all fonts (both user and system)" echo "4. Exit" echo "" while true; do read -p "Choose an option (1-4): " choice case $choice in 1) UNINSTALL_MODE="user" break ;; 2) UNINSTALL_MODE="system" break ;; 3) UNINSTALL_MODE="all" break ;; 4) print_info "Uninstallation cancelled by user" exit 0 ;; *) print_error "Invalid option. Please choose 1, 2, 3, or 4." ;; esac done elif [[ $USER_FONT_COUNT -gt 0 ]]; then print_info "Only user fonts found. Will remove user fonts." UNINSTALL_MODE="user" elif [[ $SYSTEM_FONT_COUNT -gt 0 ]]; then print_info "Only system fonts found. Will remove system fonts." UNINSTALL_MODE="system" else print_warning "No Bangla fonts found to uninstall" echo "" echo -e "${CYAN}Checked locations:${NC}" echo " - User: $USER_FONTS_DIR" echo " - System: $SYSTEM_FONTS_DIR" echo "" print_info "Nothing to uninstall. Exiting." exit 0 fi } check_permissions() { if [[ "$UNINSTALL_MODE" == "system" || "$UNINSTALL_MODE" == "all" ]]; then if [[ $EUID -ne 0 ]]; then if command -v sudo >/dev/null 2>&1; then print_info "System font removal requires sudo privileges" if ! sudo -n true 2>/dev/null; then print_warning "You will be prompted for your password" fi else print_error "System font removal requires root privileges, but sudo is not available" exit 1 fi fi fi } remove_user_fonts() { if [[ $USER_FONT_COUNT -eq 0 ]]; then print_warning "No user fonts to remove" return 0 fi print_step "Removing user fonts..." if [[ "$DRY_RUN" == true ]]; then print_warning "DRY RUN MODE - User fonts would be removed from: $USER_FONTS_DIR" return 0 fi if [[ -d "$USER_FONTS_DIR" ]]; then local removed_count=0 # Remove individual font files while IFS= read -r -d '' font; do if rm "$font" 2>/dev/null; then removed_count=$((removed_count + 1)) [[ $VERBOSE == true ]] && print_success "Removed $(basename "$font")" else [[ $VERBOSE == true ]] && print_warning "Failed to remove $(basename "$font")" fi done < <(find "$USER_FONTS_DIR" -name "*.ttf" -print0 2>/dev/null) # Remove directory if empty if [[ -d "$USER_FONTS_DIR" ]]; then if rmdir "$USER_FONTS_DIR" 2>/dev/null; then [[ $VERBOSE == true ]] && print_success "Removed empty directory: $USER_FONTS_DIR" elif [[ $(find "$USER_FONTS_DIR" -type f | wc -l) -eq 0 ]]; then # Directory exists but is empty (might contain subdirs) [[ $VERBOSE == true ]] && print_info "Directory $USER_FONTS_DIR is empty but not removed (may contain subdirectories)" fi fi print_success "Removed $removed_count user font(s)" else print_warning "User fonts directory not found: $USER_FONTS_DIR" fi } remove_system_fonts() { if [[ $SYSTEM_FONT_COUNT -eq 0 ]]; then print_warning "No system fonts to remove" return 0 fi print_step "Removing system fonts..." if [[ "$DRY_RUN" == true ]]; then print_warning "DRY RUN MODE - System fonts would be removed from: $SYSTEM_FONTS_DIR" return 0 fi if [[ -d "$SYSTEM_FONTS_DIR" ]]; then local removed_count=0 # Remove individual font files while IFS= read -r -d '' font; do local remove_cmd="rm '$font'" if [[ $EUID -ne 0 ]]; then remove_cmd="sudo $remove_cmd" fi if eval "$remove_cmd" 2>/dev/null; then removed_count=$((removed_count + 1)) [[ $VERBOSE == true ]] && print_success "Removed $(basename "$font")" else [[ $VERBOSE == true ]] && print_warning "Failed to remove $(basename "$font")" fi done < <(find "$SYSTEM_FONTS_DIR" -name "*.ttf" -print0 2>/dev/null) # Remove directory if empty if [[ -d "$SYSTEM_FONTS_DIR" ]]; then local rmdir_cmd="rmdir '$SYSTEM_FONTS_DIR'" if [[ $EUID -ne 0 ]]; then rmdir_cmd="sudo $rmdir_cmd" fi if eval "$rmdir_cmd" 2>/dev/null; then [[ $VERBOSE == true ]] && print_success "Removed empty directory: $SYSTEM_FONTS_DIR" elif [[ $(find "$SYSTEM_FONTS_DIR" -type f | wc -l) -eq 0 ]]; then [[ $VERBOSE == true ]] && print_info "Directory $SYSTEM_FONTS_DIR is empty but not removed (may contain subdirectories)" fi fi print_success "Removed $removed_count system font(s)" else print_warning "System fonts directory not found: $SYSTEM_FONTS_DIR" fi } refresh_font_cache() { print_step "Refreshing font cache..." if [[ "$DRY_RUN" == true ]]; then print_warning "DRY RUN MODE - Font cache would be refreshed" return 0 fi # Refresh font cache if command -v fc-cache >/dev/null 2>&1; then # User font cache fc-cache -f 2>/dev/null || true # System font cache (if we removed system fonts) if [[ "$UNINSTALL_MODE" == "system" || "$UNINSTALL_MODE" == "all" ]]; then if [[ $EUID -ne 0 ]]; then sudo fc-cache -fv >/dev/null 2>&1 || true else fc-cache -fv >/dev/null 2>&1 || true fi fi print_success "Font cache refreshed" else print_warning "fc-cache not found, font cache not refreshed" fi } # ============================================================================= # Help and Usage # ============================================================================= show_help() { cat << EOF ${BOLD}Linux-BF: Bangla Font Uninstaller v$VERSION${NC} ${BOLD}USAGE:${NC} $0 [OPTIONS] ${BOLD}OPTIONS:${NC} -h, --help Show this help message -v, --version Show version information --verbose Enable verbose output --user Remove user fonts only (default) --system Remove system fonts only (requires sudo) --all Remove both user and system fonts --dry-run Preview what would be removed without making changes --force Remove without confirmation prompts --status Check installation status and exit ${BOLD}EXAMPLES:${NC} $0 # Interactive removal (auto-detect what's installed) $0 --user # Remove user fonts only $0 --system # Remove system fonts only $0 --all # Remove all fonts (both user and system) $0 --dry-run # Preview what would be removed $0 --status # Check what fonts are currently installed ${BOLD}REMOTE UNINSTALLATION:${NC} curl -sSL https://banglafont.pages.dev/uninstall.sh | bash curl -sSL https://banglafont.pages.dev/uninstall.sh | bash -s -- --all ${BOLD}PATHS:${NC} User fonts: $USER_FONTS_DIR System fonts: $SYSTEM_FONTS_DIR Log file: $LOG_FILE ${BOLD}SUPPORT:${NC} Website: https://banglafont.pages.dev GitHub: https://github.com/abusayed0206/linux-bf Issues: https://github.com/abusayed0206/linux-bf/issues EOF } # ============================================================================= # Main Function # ============================================================================= main() { # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in -h|--help) show_help exit 0 ;; -v|--version) echo "Linux-BF Uninstaller v$VERSION" exit 0 ;; --verbose) VERBOSE=true shift ;; --user) UNINSTALL_MODE="user" shift ;; --system) UNINSTALL_MODE="system" shift ;; --all) UNINSTALL_MODE="all" shift ;; --dry-run) DRY_RUN=true shift ;; --force) FORCE_UNINSTALL=true shift ;; --status) print_header log "=== Linux-BF Status Check Started ===" check_installed_fonts echo -e "${CYAN}Font installation status checked.${NC}" echo -e "${CYAN}Log file: $LOG_FILE${NC}" exit 0 ;; *) print_error "Unknown option: $1" echo "Use --help for usage information" exit 1 ;; esac done # Initialize print_header log "=== Linux-BF Uninstallation Started ===" log "Version: $VERSION" log "Uninstall mode: $UNINSTALL_MODE" log "PID: $$" # Check what's installed check_installed_fonts # Determine uninstall mode get_uninstall_mode check_permissions # Confirmation if [[ "$FORCE_UNINSTALL" != true && "$DRY_RUN" != true ]]; then echo -e "\n${YELLOW}Uninstallation Summary:${NC}" echo " Mode: $UNINSTALL_MODE" case "$UNINSTALL_MODE" in user) echo " Target: User fonts ($USER_FONT_COUNT fonts)" echo " Path: $USER_FONTS_DIR" ;; system) echo " Target: System fonts ($SYSTEM_FONT_COUNT fonts)" echo " Path: $SYSTEM_FONTS_DIR" ;; all) echo " Target: All fonts ($((USER_FONT_COUNT + SYSTEM_FONT_COUNT)) fonts total)" echo " Paths: $USER_FONTS_DIR" echo " $SYSTEM_FONTS_DIR" ;; esac echo "" read -p "Proceed with uninstallation? (y/N): " confirm case $confirm in [Yy]|[Yy][Ee][Ss]) echo "" ;; *) print_info "Uninstallation cancelled by user" exit 0 ;; esac fi # Remove fonts case "$UNINSTALL_MODE" in user) remove_user_fonts ;; system) remove_system_fonts ;; all) remove_user_fonts remove_system_fonts ;; esac # Refresh font cache refresh_font_cache # Final message if [[ "$DRY_RUN" != true ]]; then echo "" print_success "Uninstallation completed successfully!" echo "" echo -e "${BOLD}${GREEN}🎉 Bangla fonts have been removed from your system!${NC}" echo "" echo -e "${CYAN}Next steps:${NC}" echo " 1. Restart your applications to update font lists" echo " 2. The font cache has been automatically refreshed" echo " 3. You can reinstall fonts anytime from https://banglafont.pages.dev" echo "" echo -e "${CYAN}Troubleshooting:${NC}" echo " • If fonts still appear, try logging out and back in" echo " • Check the log file for details: $LOG_FILE" echo " • Report issues: https://github.com/abusayed0206/linux-bf/issues" echo "" echo -e "${BOLD}Thank you for using Linux-BF! 🇧🇩${NC}" else print_info "Dry run completed. No changes were made." fi log "=== Linux-BF Uninstallation Completed ===" } # ============================================================================= # Script Entry Point # ============================================================================= # Check if script is being executed directly (not sourced) # Handle case where BASH_SOURCE might not be available (e.g., when piped from curl) if [[ "${BASH_SOURCE[0]:-$0}" == "${0}" ]]; then main "$@" fi