|
| 1 | +#!/bin/bash |
| 2 | +# Migration: Replace udev-based ASUS profile sync with D-Bus approach |
| 3 | +# Removes old udev rule and asus-profile-notify.sh |
| 4 | +# Enables new systemd user service for D-Bus monitoring |
| 5 | + |
| 6 | +echo "Running migration: ASUS Profile Sync - udev to D-Bus migration" |
| 7 | + |
| 8 | +# Check if this is an ASUS system |
| 9 | +if ! sudo dmidecode -s system-manufacturer 2>/dev/null | grep -qi asus; then |
| 10 | + echo "Not an ASUS system, skipping migration" |
| 11 | + exit 0 |
| 12 | +fi |
| 13 | + |
| 14 | +echo "Stopping old udev-based profile sync..." |
| 15 | + |
| 16 | +if [[ -f /etc/udev/rules.d/99-asus-profile-toast.rules ]]; then |
| 17 | + echo "Removing old udev rule: /etc/udev/rules.d/99-asus-profile-toast.rules" |
| 18 | + sudo rm -f /etc/udev/rules.d/99-asus-profile-toast.rules |
| 19 | + sudo udevadm control --reload-rules |
| 20 | + echo "Old udev rule removed" |
| 21 | +else |
| 22 | + echo "Old udev rule not found (already removed or never existed)" |
| 23 | +fi |
| 24 | + |
| 25 | +OLD_SCRIPT="$HOME/.local/bin/asus-profile-notify.sh" |
| 26 | +if [[ -f "$OLD_SCRIPT" ]]; then |
| 27 | + echo "Removing old script: $OLD_SCRIPT" |
| 28 | + rm -f "$OLD_SCRIPT" |
| 29 | + echo "Old script removed" |
| 30 | +else |
| 31 | + echo "Old script not found (already removed or never existed)" |
| 32 | +fi |
| 33 | + |
| 34 | +echo "Cleaning up old lock and state files..." |
| 35 | +rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-notify.lock" |
| 36 | +rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-last-state" |
| 37 | +rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-debounce" |
| 38 | +rm -f "${XDG_RUNTIME_DIR:-/tmp}/asus-profile-timestamp" |
| 39 | +rm -f /tmp/asus-profile-notify.lock |
| 40 | +rm -f /tmp/asus-profile-last-state |
| 41 | +echo "Cleaned up temporary files" |
| 42 | + |
| 43 | +NEW_SCRIPT="$HOME/.local/bin/asus-profile-sync.sh" |
| 44 | +NEW_SERVICE="$HOME/.config/systemd/user/asus-profile-sync.service" |
| 45 | + |
| 46 | +if [[ ! -f "$NEW_SCRIPT" ]] || [[ ! -f "$NEW_SERVICE" ]]; then |
| 47 | + echo "New files not found, attempting to stow 'home' package..." |
| 48 | + |
| 49 | + CONFIGS_DIR="$HOME/Dev/.configs" |
| 50 | + if [[ ! -d "$CONFIGS_DIR" ]]; then |
| 51 | + echo "ERROR: Configs directory not found at $CONFIGS_DIR" |
| 52 | + echo "Please ensure your dotfiles are cloned to $CONFIGS_DIR" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + |
| 56 | + COMMON_HELPERS="$CONFIGS_DIR/unix/fedora/install/helpers/common.sh" |
| 57 | + if [[ -f "$COMMON_HELPERS" ]]; then |
| 58 | + source "$COMMON_HELPERS" |
| 59 | + fi |
| 60 | + |
| 61 | + STOW_SCRIPT="$CONFIGS_DIR/unix/common/dotfiles/stow.sh" |
| 62 | + if [[ ! -f "$STOW_SCRIPT" ]]; then |
| 63 | + echo "ERROR: Stow script not found at $STOW_SCRIPT" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + |
| 67 | + source "$STOW_SCRIPT" |
| 68 | + |
| 69 | + if stow_dotfiles "$CONFIGS_DIR/home" "$HOME" local; then |
| 70 | + echo "Stowed home/local package" |
| 71 | + else |
| 72 | + echo "ERROR: Failed to stow home/local package" |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | + |
| 76 | + if [[ ! -f "$NEW_SCRIPT" ]]; then |
| 77 | + echo "ERROR: $NEW_SCRIPT still not found after stowing" |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + |
| 81 | + if [[ ! -f "$NEW_SERVICE" ]]; then |
| 82 | + echo "ERROR: $NEW_SERVICE still not found after stowing" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | + |
| 86 | + echo "New files successfully deployed" |
| 87 | +else |
| 88 | + echo "New files already exist" |
| 89 | +fi |
| 90 | + |
| 91 | +echo "Reloading systemd user daemon..." |
| 92 | +systemctl --user daemon-reload |
| 93 | + |
| 94 | +echo "Enabling and starting new D-Bus monitoring service..." |
| 95 | +systemctl --user enable asus-profile-sync.service |
| 96 | +systemctl --user restart asus-profile-sync.service |
| 97 | + |
| 98 | +if systemctl --user is-active --quiet asus-profile-sync.service; then |
| 99 | + echo "asus-profile-sync.service is running" |
| 100 | +else |
| 101 | + echo "⚠ WARNING: asus-profile-sync.service failed to start" |
| 102 | + echo "Check status with: systemctl --user status asus-profile-sync.service" |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | + |
| 106 | +echo "" |
| 107 | +echo "Migration completed successfully!" |
| 108 | +echo "" |
| 109 | +echo "Summary of changes:" |
| 110 | +echo " - Removed: /etc/udev/rules.d/99-asus-profile-toast.rules" |
| 111 | +echo " - Removed: ~/.local/bin/asus-profile-notify.sh" |
| 112 | +echo " - Added: ~/.local/bin/asus-profile-sync.sh" |
| 113 | +echo " - Added: ~/.config/systemd/user/asus-profile-sync.service" |
| 114 | +echo " - Enabled: asus-profile-sync.service (D-Bus monitoring)" |
| 115 | +echo "" |
| 116 | +echo "You can now test by pressing Fn+F5 to change power profiles" |
| 117 | +echo "Monitor logs with: journalctl --user -u asus-profile-sync.service -f" |
0 commit comments