Skip to content
This repository was archived by the owner on Feb 13, 2026. It is now read-only.

Commit aae8799

Browse files
committed
fix: asusctl profile issue
1 parent 4ea7764 commit aae8799

File tree

3 files changed

+156
-65
lines changed

3 files changed

+156
-65
lines changed

home/local/.local/bin/asus-profile-notify.sh

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,21 @@
11
#!/bin/bash
22

3-
# Lock file to prevent concurrent executions and feedback loops
4-
# Use XDG_RUNTIME_DIR (user-writable) instead of /run/lock (root-only)
5-
LOCKFILE="${XDG_RUNTIME_DIR:-/tmp}/asus-profile-notify.lock"
6-
STATEFILE="${XDG_RUNTIME_DIR:-/tmp}/asus-profile-last-state"
7-
DEBOUNCEFILE="${XDG_RUNTIME_DIR:-/tmp}/asus-profile-debounce"
3+
# Shows OSD toast when power profile changes via Fn+F5
84

9-
# Debounce: if script was run within last 0.5s, wait for things to settle
10-
if [[ -f "$DEBOUNCEFILE" ]]; then
11-
last_run=$(cat "$DEBOUNCEFILE")
12-
current_time=$(date +%s%3N) # milliseconds
13-
time_diff=$((current_time - last_run))
5+
# Get current profile from asusctl
6+
current_profile=$(asusctl profile --profile-get 2>/dev/null | grep "Active profile" | awk '{print $4}')
147

15-
if [[ $time_diff -lt 500 ]]; then
16-
# Too soon, let the dust settle
17-
sleep 0.5
18-
fi
19-
fi
20-
21-
# Save current timestamp for debouncing
22-
date +%s%3N > "$DEBOUNCEFILE"
23-
24-
# Try to acquire exclusive lock (non-blocking)
25-
exec 200>"$LOCKFILE"
26-
if ! flock -n 200; then
27-
# Another instance is running, exit silently
28-
exit 0
29-
fi
30-
31-
# Wait for hardware to stabilize after profile change
32-
sleep 0.2
33-
34-
# Get current profile
35-
current_profile=$(asusctl profile --profile-get | grep "Active profile" | awk '{print $4}')
36-
37-
# Check if this is the same profile as last run (prevent feedback loop)
38-
if [[ -f "$STATEFILE" ]]; then
39-
last_profile=$(cat "$STATEFILE")
40-
if [[ "$last_profile" == "$current_profile" ]]; then
41-
# Same profile, this is likely a feedback loop from tuned-adm
42-
exit 0
43-
fi
44-
fi
45-
46-
# Save current profile to state file
47-
echo "$current_profile" > "$STATEFILE"
48-
49-
# Map ASUS profiles to TuneD profiles
8+
# Map ASUS profiles to icons and messages
509
case "$current_profile" in
5110
"Quiet")
52-
/usr/sbin/tuned-adm profile powersave >/dev/null 2>&1
53-
/usr/bin/supergfxctl -m "Integrated" >/dev/null 2>&1
5411
icon="battery-profile-powersave"
5512
message="Profile: Quiet (Power Saver)"
5613
;;
5714
"Balanced")
58-
/usr/sbin/tuned-adm profile balanced-battery >/dev/null 2>&1
59-
/usr/bin/supergfxctl -m "Hybrid" >/dev/null 2>&1
6015
icon="battery-060"
6116
message="Profile: Balanced"
6217
;;
6318
"Performance")
64-
/usr/sbin/tuned-adm profile throughput-performance >/dev/null 2>&1
65-
/usr/bin/supergfxctl -m "Hybrid" >/dev/null 2>&1
6619
icon="battery-profile-performance"
6720
message="Profile: Performance"
6821
;;

unix/fedora/install/config/hardware/asus.sh

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,42 @@ sudo dnf install -y "${packages[@]}"
3333
sudo systemctl enable supergfxd.service || log_warning "Failed to enable supergfxd"
3434
sudo systemctl start asusd || log_warning "Failed to start asusd"
3535

36-
# Configure udev rules for profile notifications
36+
# Fix tuned-ppd platform_profile mapping for ASUS laptops
37+
if [[ -f /sys/firmware/acpi/platform_profile_choices ]]; then
38+
if grep -q "quiet" /sys/firmware/acpi/platform_profile_choices 2>/dev/null; then
39+
log_info "Applying tuned-ppd patch for ASUS 'quiet' platform profile"
40+
41+
# Find the correct Python version
42+
TUNED_CONTROLLER=$(find /usr/lib/python3.*/site-packages/tuned/ppd/controller.py 2>/dev/null | head -1)
43+
44+
if [[ -n "$TUNED_CONTROLLER" ]] && [[ -f "$TUNED_CONTROLLER" ]]; then
45+
# Check if patch is already applied
46+
if ! grep -q '"quiet": PPD_POWER_SAVER' "$TUNED_CONTROLLER"; then
47+
# Backup original
48+
sudo cp "$TUNED_CONTROLLER" "${TUNED_CONTROLLER}.backup"
49+
50+
# Apply patch: add "quiet": PPD_POWER_SAVER to PLATFORM_PROFILE_MAPPING
51+
sudo sed -i '/PLATFORM_PROFILE_MAPPING = {/,/}/s/"low-power": PPD_POWER_SAVER,/"low-power": PPD_POWER_SAVER,\n "quiet": PPD_POWER_SAVER,/' "$TUNED_CONTROLLER"
52+
53+
log_info "tuned-ppd patched successfully"
54+
55+
# Restart tuned-ppd
56+
sudo systemctl restart tuned-ppd
57+
log_info "tuned-ppd restarted"
58+
else
59+
log_info "tuned-ppd patch already applied"
60+
fi
61+
else
62+
log_warning "tuned-ppd controller.py not found, skipping patch"
63+
fi
64+
65+
# Fix SELinux context
66+
if [[ -f /etc/tuned/ppd_base_profile ]]; then
67+
sudo restorecon -v /etc/tuned/ppd_base_profile 2>/dev/null || true
68+
fi
69+
fi
70+
fi
71+
3772
log_info "Setting up ASUS profile change notifications"
3873

3974
# Get the actual user (not root)
@@ -42,6 +77,7 @@ REAL_UID=$(id -u "$REAL_USER")
4277
REAL_HOME=$(eval echo "~$REAL_USER")
4378

4479
sudo tee /etc/udev/rules.d/99-asus-profile-toast.rules > /dev/null <<EOF
80+
# Trigger notification when ASUS platform profile changes (Fn+F5)
4581
KERNEL=="platform-profile-*", \\
4682
SUBSYSTEM=="platform-profile", \\
4783
ACTION=="change", \\
@@ -53,21 +89,9 @@ KERNEL=="platform-profile-*", \\
5389
'"
5490
EOF
5591

56-
# Configure polkit for profile switching
57-
sudo tee /etc/polkit-1/rules.d/49-asus-profile.rules > /dev/null <<'EOF'
58-
// Allow switching TuneD profiles from udev/inactive sessions
59-
polkit.addRule(function(action, subject) {
60-
if (action.id == "com.redhat.tuned.switch_profile") {
61-
return polkit.Result.YES;
62-
}
63-
});
64-
EOF
65-
66-
sudo chmod 644 /etc/polkit-1/rules.d/49-asus-profile.rules
6792
sudo chmod 644 /etc/udev/rules.d/99-asus-profile-toast.rules
6893

69-
# Restart services
70-
sudo systemctl restart polkit
94+
# Reload udev rules
7195
sudo udevadm control --reload-rules
7296

7397
log_success "ASUS system optimizations applied"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
# Migration: Fix ASUS power profile switching
3+
#
4+
# This migration:
5+
# - Removes obsolete polkit rule (profile switching now handled by tuned-ppd)
6+
# - Updates udev rule with proper comment
7+
# - Applies tuned-ppd patch for ASUS "quiet" platform profile support
8+
# - Fixes SELinux contexts
9+
10+
echo "Running migration: Fix ASUS power profile switching"
11+
12+
# Only run on ASUS systems
13+
if ! sudo dmidecode -s system-manufacturer 2>/dev/null | grep -qi asus; then
14+
echo "Not an ASUS system, skipping migration"
15+
exit 0
16+
fi
17+
18+
echo "ASUS system detected, applying migration..."
19+
20+
# 1. Remove obsolete polkit rule
21+
if [[ -f /etc/polkit-1/rules.d/49-asus-profile.rules ]]; then
22+
echo "Removing obsolete polkit rule..."
23+
sudo rm -f /etc/polkit-1/rules.d/49-asus-profile.rules
24+
sudo systemctl restart polkit 2>/dev/null || true
25+
echo "✓ Polkit rule removed"
26+
fi
27+
28+
# 2. Update udev rule with proper comment
29+
echo "Updating udev rule..."
30+
31+
REAL_USER="${SUDO_USER:-$USER}"
32+
REAL_UID=$(id -u "$REAL_USER")
33+
REAL_HOME=$(eval echo "~$REAL_USER")
34+
35+
sudo tee /etc/udev/rules.d/99-asus-profile-toast.rules > /dev/null <<EOF
36+
# Trigger notification when ASUS platform profile changes (Fn+F5)
37+
KERNEL=="platform-profile-*", \\
38+
SUBSYSTEM=="platform-profile", \\
39+
ACTION=="change", \\
40+
RUN+="/bin/bash -c ' \\
41+
DISPLAY=:0 \\
42+
XDG_RUNTIME_DIR=/run/user/$REAL_UID \\
43+
/usr/bin/sudo -u $REAL_USER \\
44+
$REAL_HOME/.local/bin/asus-profile-notify.sh \\
45+
'"
46+
EOF
47+
48+
sudo chmod 644 /etc/udev/rules.d/99-asus-profile-toast.rules
49+
sudo udevadm control --reload-rules
50+
echo "✓ Udev rule updated"
51+
52+
# 3. Apply tuned-ppd patch if system has "quiet" profile
53+
if [[ -f /sys/firmware/acpi/platform_profile_choices ]]; then
54+
if grep -q "quiet" /sys/firmware/acpi/platform_profile_choices 2>/dev/null; then
55+
echo "System has 'quiet' platform profile, applying tuned-ppd patch..."
56+
57+
# Find the correct Python version
58+
TUNED_CONTROLLER=$(find /usr/lib/python3.*/site-packages/tuned/ppd/controller.py 2>/dev/null | head -1)
59+
60+
if [[ -n "$TUNED_CONTROLLER" ]] && [[ -f "$TUNED_CONTROLLER" ]]; then
61+
# Check if patch is already applied
62+
if ! grep -q '"quiet": PPD_POWER_SAVER' "$TUNED_CONTROLLER"; then
63+
# Backup original
64+
sudo cp "$TUNED_CONTROLLER" "${TUNED_CONTROLLER}.backup"
65+
echo " - Created backup: ${TUNED_CONTROLLER}.backup"
66+
67+
# Apply patch
68+
sudo sed -i '/PLATFORM_PROFILE_MAPPING = {/,/}/s/"low-power": PPD_POWER_SAVER,/"low-power": PPD_POWER_SAVER,\n "quiet": PPD_POWER_SAVER,/' "$TUNED_CONTROLLER"
69+
70+
# Verify patch was applied
71+
if grep -q '"quiet": PPD_POWER_SAVER' "$TUNED_CONTROLLER"; then
72+
echo " ✓ Patch applied successfully"
73+
74+
# Restart tuned-ppd
75+
sudo systemctl restart tuned-ppd
76+
echo " ✓ tuned-ppd restarted"
77+
else
78+
echo " ✗ Failed to apply patch"
79+
# Restore from backup
80+
sudo cp "${TUNED_CONTROLLER}.backup" "$TUNED_CONTROLLER"
81+
echo " - Restored from backup"
82+
fi
83+
else
84+
echo " - Patch already applied, skipping"
85+
fi
86+
else
87+
echo " ✗ tuned-ppd controller.py not found at: $TUNED_CONTROLLER"
88+
echo " Skipping patch (tuned-ppd may not be installed)"
89+
fi
90+
91+
# Fix SELinux context
92+
if [[ -f /etc/tuned/ppd_base_profile ]]; then
93+
echo "Fixing SELinux context..."
94+
sudo restorecon -v /etc/tuned/ppd_base_profile 2>/dev/null || true
95+
echo "✓ SELinux context fixed"
96+
fi
97+
else
98+
echo "System does not have 'quiet' platform profile, skipping tuned-ppd patch"
99+
fi
100+
else
101+
echo "/sys/firmware/acpi/platform_profile_choices not found, skipping tuned-ppd patch"
102+
fi
103+
104+
echo ""
105+
echo "Migration completed successfully!"
106+
echo ""
107+
echo "Summary:"
108+
echo " - Removed obsolete polkit rule for manual profile switching"
109+
echo " - Updated udev rule for toast notifications"
110+
echo " - Applied tuned-ppd patch (if applicable)"
111+
echo ""
112+
echo "Power profile switching via Fn+F5 should now work correctly."
113+
echo "Press Fn+F5 to test - you should see toast notifications and"
114+
echo "all three profiles (Quiet/Balanced/Performance) should cycle properly."

0 commit comments

Comments
 (0)