Bash · 4401 bytes Raw Blame History
1 #!/bin/bash
2 # Safely swap display managers (e.g., SDDM -> gardm)
3 # This script includes safety checks and rollback instructions
4
5 set -e
6
7 RED='\033[0;31m'
8 GREEN='\033[0;32m'
9 YELLOW='\033[1;33m'
10 BLUE='\033[0;34m'
11 NC='\033[0m'
12
13 log_info() {
14 echo -e "${GREEN}[INFO]${NC} $1"
15 }
16
17 log_warn() {
18 echo -e "${YELLOW}[WARN]${NC} $1"
19 }
20
21 log_error() {
22 echo -e "${RED}[ERROR]${NC} $1"
23 }
24
25 log_step() {
26 echo -e "${BLUE}[STEP]${NC} $1"
27 }
28
29 if [ "$EUID" -ne 0 ]; then
30 log_error "Please run as root (sudo ./swap-dm.sh)"
31 exit 1
32 fi
33
34 echo "============================================"
35 echo " gardm Display Manager Swap Utility"
36 echo "============================================"
37 echo ""
38
39 # Detect current display manager
40 CURRENT_DM=""
41 for dm in sddm gdm gdm3 lightdm lxdm; do
42 if systemctl is-enabled "$dm" >/dev/null 2>&1; then
43 CURRENT_DM="$dm"
44 break
45 fi
46 done
47
48 if [ -z "$CURRENT_DM" ]; then
49 log_warn "Could not detect current display manager"
50 echo "Which display manager are you currently using?"
51 echo " 1) sddm"
52 echo " 2) gdm"
53 echo " 3) lightdm"
54 echo " 4) other"
55 read -p "Selection [1-4]: " choice
56 case $choice in
57 1) CURRENT_DM="sddm" ;;
58 2) CURRENT_DM="gdm" ;;
59 3) CURRENT_DM="lightdm" ;;
60 *)
61 read -p "Enter the service name: " CURRENT_DM
62 ;;
63 esac
64 fi
65
66 log_info "Detected current display manager: $CURRENT_DM"
67 echo ""
68
69 # Pre-flight checks
70 log_step "Running pre-flight checks..."
71
72 # Check gardm is installed
73 if [ ! -x /usr/bin/gardmd ]; then
74 log_error "gardmd not found at /usr/bin/gardmd"
75 log_error "Please run install.sh first"
76 exit 1
77 fi
78
79 if [ ! -x /usr/bin/gardm-greeter ]; then
80 log_error "gardm-greeter not found at /usr/bin/gardm-greeter"
81 log_error "Please run install.sh first"
82 exit 1
83 fi
84
85 # Check systemd service exists
86 if [ ! -f /usr/lib/systemd/system/gardm.service ]; then
87 log_error "gardm.service not found"
88 log_error "Please run install.sh first"
89 exit 1
90 fi
91
92 # Check PAM config
93 if [ ! -f /etc/pam.d/gardm ]; then
94 log_error "PAM configuration not found at /etc/pam.d/gardm"
95 log_error "Please run install.sh first"
96 exit 1
97 fi
98
99 log_info "All pre-flight checks passed"
100 echo ""
101
102 # Safety warnings
103 echo "============================================"
104 echo " IMPORTANT SAFETY INFORMATION"
105 echo "============================================"
106 echo ""
107 log_warn "Swapping display managers can prevent graphical login!"
108 echo ""
109 echo "BEFORE PROCEEDING, ensure you can:"
110 echo " 1. Switch to a TTY (Ctrl+Alt+F2 through F6)"
111 echo " 2. Log in via TTY as your user"
112 echo " 3. Have root/sudo access from TTY"
113 echo ""
114 echo "ROLLBACK PROCEDURE (if gardm fails):"
115 echo " 1. Switch to TTY: Ctrl+Alt+F2"
116 echo " 2. Log in as your user"
117 echo " 3. Run: sudo systemctl disable gardm"
118 echo " 4. Run: sudo systemctl enable $CURRENT_DM"
119 echo " 5. Reboot: sudo reboot"
120 echo ""
121
122 read -p "Have you tested gardm with test-gardm.sh? [y/N]: " tested
123 if [ "$tested" != "y" ] && [ "$tested" != "Y" ]; then
124 log_warn "It's recommended to test gardm first!"
125 log_warn "Run: sudo ./test-gardm.sh"
126 echo ""
127 read -p "Continue anyway? [y/N]: " continue
128 if [ "$continue" != "y" ] && [ "$continue" != "Y" ]; then
129 log_info "Aborted. Please test gardm first."
130 exit 0
131 fi
132 fi
133
134 echo ""
135 read -p "Ready to swap $CURRENT_DM -> gardm? [y/N]: " confirm
136 if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
137 log_info "Aborted by user"
138 exit 0
139 fi
140
141 echo ""
142 log_step "Disabling $CURRENT_DM..."
143 systemctl disable "$CURRENT_DM"
144
145 log_step "Enabling gardm..."
146 systemctl enable gardm
147
148 echo ""
149 log_info "Display manager swap complete!"
150 echo ""
151 echo "============================================"
152 echo " NEXT STEPS"
153 echo "============================================"
154 echo ""
155 echo "1. Reboot your system: sudo reboot"
156 echo "2. gardm should start instead of $CURRENT_DM"
157 echo ""
158 echo "If gardm fails to start:"
159 echo " - Switch to TTY (Ctrl+Alt+F2)"
160 echo " - Run: sudo systemctl disable gardm"
161 echo " - Run: sudo systemctl enable $CURRENT_DM"
162 echo " - Run: sudo reboot"
163 echo ""
164 echo "To check gardm status after reboot:"
165 echo " systemctl status gardm"
166 echo " journalctl -u gardm -b"
167 echo ""
168
169 read -p "Reboot now? [y/N]: " reboot_now
170 if [ "$reboot_now" = "y" ] || [ "$reboot_now" = "Y" ]; then
171 log_info "Rebooting..."
172 reboot
173 fi