Created
July 26, 2024 04:11
-
-
Save christian-taillon/39646329340ef6efe4b2511df82d4dba to your computer and use it in GitHub Desktop.
Disable and reenable GUI and other options for a desktop that is used as a server. Applies to Gnome.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to disable GUI and power management | |
disable_gui_power() { | |
echo "Disabling GUI and power management..." | |
# Disable sleep and hibernate | |
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target | |
# Disable GNOME power management | |
mkdir -p /etc/dconf/db/local.d/ | |
cat << EOF > /etc/dconf/db/local.d/00-power | |
[org/gnome/settings-daemon/plugins/power] | |
sleep-inactive-ac-type='nothing' | |
sleep-inactive-battery-type='nothing' | |
EOF | |
dconf update | |
# Disable GNOME screen blanking | |
su - $SUDO_USER -c "gsettings set org.gnome.desktop.session idle-delay 0" | |
# Disable power management in NetworkManager | |
cat << EOF > /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf | |
[connection] | |
wifi.powersave = 2 | |
EOF | |
# Switch to multi-user target | |
systemctl set-default multi-user.target | |
# Disable GDM | |
systemctl disable gdm | |
# Mask graphical-session-pre.target | |
systemctl mask graphical-session-pre.target | |
echo "GUI and power management features have been disabled. The system will boot to text mode after reboot." | |
} | |
# Function to enable GUI and power management | |
enable_gui_power() { | |
echo "Enabling GUI and power management..." | |
# Re-enable sleep and hibernate | |
systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target | |
# Remove GNOME power management settings | |
rm -f /etc/dconf/db/local.d/00-power | |
dconf update | |
# Re-enable GNOME screen blanking (set to 300 seconds / 5 minutes) | |
su - $SUDO_USER -c "gsettings set org.gnome.desktop.session idle-delay 300" | |
# Remove NetworkManager power management settings | |
rm -f /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf | |
# Switch back to graphical target | |
systemctl set-default graphical.target | |
# Enable GDM | |
systemctl enable gdm | |
# Unmask graphical-session-pre.target | |
systemctl unmask graphical-session-pre.target | |
echo "GUI and power management features have been re-enabled. The system will boot to graphical mode after reboot." | |
} | |
# Check if script is run with sudo | |
if [ "$EUID" -ne 0 ]; then | |
echo "Please run this script with sudo" | |
exit 1 | |
fi | |
# Main menu | |
while true; do | |
echo "Choose an option:" | |
echo "1) Disable GUI and power management" | |
echo "2) Enable GUI and power management" | |
echo "3) Exit" | |
read -p "Enter your choice (1-3): " choice | |
case $choice in | |
1) | |
disable_gui_power | |
break | |
;; | |
2) | |
enable_gui_power | |
break | |
;; | |
3) | |
echo "Exiting..." | |
exit 0 | |
;; | |
*) | |
echo "Invalid option. Please try again." | |
;; | |
esac | |
done | |
echo "Reboot the system to apply changes." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment