Commit b7006fa846dd

Vincent Demeester <vincent@sbr.pm>
2026-07-30 09:31:13
chore: add power management to fedora bootstrap scripts
Added setup_power phase with powertop auto-tune systemd service and tuned balanced-battery profile for both aomi and kyushu.
1 parent b605ebd
Changed files (2)
imperative
imperative/aomi/bootstrap.sh
@@ -344,6 +344,43 @@ setup_home_manager() {
 
 # --- Phase 6: WireGuard key ---
 
+setup_power() {
+	log_info "Configuring power management..."
+
+	# Powertop auto-tune service
+	if [[ ! -f /etc/systemd/system/powertop.service ]]; then
+		log_info "Creating powertop auto-tune service..."
+		sudo tee /etc/systemd/system/powertop.service >/dev/null <<-'EOF'
+			[Unit]
+			Description=PowerTOP auto-tune
+			After=multi-user.target
+
+			[Service]
+			Type=oneshot
+			ExecStart=/usr/sbin/powertop --auto-tune
+
+			[Install]
+			WantedBy=multi-user.target
+		EOF
+		sudo systemctl daemon-reload
+		sudo systemctl enable --now powertop.service
+	else
+		log_info "powertop service already exists"
+	fi
+
+	# Set tuned profile for battery life
+	if command -v tuned-adm &>/dev/null; then
+		local current
+		current=$(tuned-adm active 2>/dev/null | sed 's/.*: //')
+		if [[ "$current" != "balanced-battery" ]]; then
+			log_info "Setting tuned profile to balanced-battery (was: $current)..."
+			sudo tuned-adm profile balanced-battery
+		else
+			log_info "tuned profile already balanced-battery"
+		fi
+	fi
+}
+
 setup_wireguard() {
 	# Use Fedora-native wg-quick service (proper SELinux context)
 	# Config file is managed by fedoraConfigs in /etc/wireguard/wg0.conf
@@ -516,6 +553,7 @@ main() {
 	setup_luks_fido2
 	setup_lid
 	setup_unscd
+	setup_power
 	setup_wireguard
 	setup_yubikey_sudo
 	setup_shell
imperative/kyushu/bootstrap.sh
@@ -354,6 +354,43 @@ setup_unscd() {
 
 # --- Phase 8: WireGuard ---
 
+setup_power() {
+	log_info "Configuring power management..."
+
+	# Powertop auto-tune service
+	if [[ ! -f /etc/systemd/system/powertop.service ]]; then
+		log_info "Creating powertop auto-tune service..."
+		sudo tee /etc/systemd/system/powertop.service >/dev/null <<-'EOF'
+			[Unit]
+			Description=PowerTOP auto-tune
+			After=multi-user.target
+
+			[Service]
+			Type=oneshot
+			ExecStart=/usr/sbin/powertop --auto-tune
+
+			[Install]
+			WantedBy=multi-user.target
+		EOF
+		sudo systemctl daemon-reload
+		sudo systemctl enable --now powertop.service
+	else
+		log_info "powertop service already exists"
+	fi
+
+	# Set tuned profile for battery life
+	if command -v tuned-adm &>/dev/null; then
+		local current
+		current=$(tuned-adm active 2>/dev/null | sed 's/.*: //')
+		if [[ "$current" != "balanced-battery" ]]; then
+			log_info "Setting tuned profile to balanced-battery (was: $current)..."
+			sudo tuned-adm profile balanced-battery
+		else
+			log_info "tuned profile already balanced-battery"
+		fi
+	fi
+}
+
 setup_wireguard() {
 	# Use Fedora-native wg-quick service (proper SELinux context)
 	# Config file is managed by system-manager in /etc/wireguard/wg0.conf
@@ -461,6 +498,7 @@ main() {
 	setup_luks_fido2
 	setup_unscd
 	setup_system_configs
+	setup_power
 	setup_wireguard
 	setup_yubikey_sudo
 	setup_shell