#!/bin/bash
# Harfsoz terilma: takes the layout out of both places it can be (for all users and for this user) and puts it
# into the Trash (it can be restored from there), then forgets the installer's receipt. Also loose
# Harfsoz.keylayout/.icns files from test versions. Nothing is deleted for good.
# Double-click it in Finder, or: bash harfsoz-terilma-uninstall.command
echo "Harfsoz terilma öçirilmoqda…"
echo "Avval terilmani röyxatdan olib taşlang: System Settings → Keyboard → Text Input → Edit… → −"
STAMP="$(date +%Y%m%d-%H%M%S)"
TRASH="$HOME/.Trash"
mkdir -p "$TRASH"
FILES="Harfsoz.bundle Harfsoz.keylayout Harfsoz.icns"
for f in $FILES; do
  U="$HOME/Library/Keyboard Layouts/$f"
  [ -e "$U" ] && mv "$U" "$TRASH/Harfsoz-$STAMP-user-$f" && echo "✓ $U"
done
SYS=""
for f in $FILES; do [ -e "/Library/Keyboard Layouts/$f" ] && SYS=1; done
if [ -n "$SYS" ]; then
  echo "Administrator paroli söraladi:"
  for f in $FILES; do
    S="/Library/Keyboard Layouts/$f"
    [ -e "$S" ] || continue
    sudo mv "$S" "$TRASH/Harfsoz-$STAMP-$f" && sudo chown -R "$(id -u):$(id -g)" "$TRASH/Harfsoz-$STAMP-$f" && echo "✓ $S"
  done
  sudo /usr/sbin/pkgutil --forget uz.harfsoz.keyboardlayout >/dev/null 2>&1
  sudo /usr/bin/touch "/Library/Keyboard Layouts"
fi
echo "Tayyor. Özgariş töliq körinişi uçun tizimdan çiqib qayta kiring."
