-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall_dragon_service.sh
More file actions
executable file
·355 lines (306 loc) · 11.4 KB
/
install_dragon_service.sh
File metadata and controls
executable file
·355 lines (306 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/bash
# Ensure script is run as root
if [ "$(id -u)" -ne 0 ]; then
echo "❌ Error: Please run this script as root or with sudo."
exit 1
fi
# Ensure required packages are installed
DEPS=(whiptail git x11-xserver-utils)
MISSING=()
for pkg in "${DEPS[@]}"; do
if ! dpkg -s "$pkg" &>/dev/null; then
MISSING+=("$pkg")
fi
done
if [ "${#MISSING[@]}" -ne 0 ]; then
echo "🔄 Installing missing dependencies: ${MISSING[*]}"
apt update
apt install -y "${MISSING[@]}"
fi
# Ensure whiptail is available for modern ASCII UI
if ! command -v whiptail &>/dev/null; then
echo "❌ Error: 'whiptail' is still not installed. Please install it (e.g., 'apt install whiptail') and retry."
exit 1
fi
SERVICE_NAME="dragon-service.service"
SERVICE_PATH="/etc/systemd/system/$SERVICE_NAME"
# Install only the systemd service
install_service() {
whiptail --title "Dragon Service Setup 🐉" --msgbox \
"This wizard will help you configure and install the Dragon systemd service.\n\nIt requires:\n • Path to Dragon binary\n • Working directory\n • GUI environment variables for the desktop user." 15 60
# Prompt for binary path
BINARY_PATH=$(whiptail --inputbox \
"Enter the full path to the Dragon binary:" 8 60 "/usr/local/lib/dragoncenter/dragon" 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && exit 1
# Prompt for working directory
WORKING_DIR=$(whiptail --inputbox \
"Enter the full path to the working directory:" 8 60 "/usr/local/lib/dragoncenter/" 3>&1 1>&2 2>&3)
[ $? -ne 0 ] && exit 1
# Validate binary exists
if [ ! -f "$BINARY_PATH" ]; then
whiptail --title "Invalid Path" --msgbox \
"Error: The binary path you provided does not exist:\n$BINARY_PATH" 10 60
exit 1
fi
# Detect desktop user and GUI env
ORIGINAL_USER=${SUDO_USER:-$(logname)}
USER_HOME=$(eval echo "~$ORIGINAL_USER")
USER_DISPLAY=$(sudo -u $ORIGINAL_USER echo $DISPLAY)
USER_XAUTHORITY=$(sudo -u $ORIGINAL_USER echo ${XAUTHORITY:-$USER_HOME/.Xauthority})
# Confirm configuration
CONFIRM_MSG="Please confirm the following settings:\n\n"
CONFIRM_MSG+=" • Dragon binary: $BINARY_PATH\n"
CONFIRM_MSG+=" • Working directory: $WORKING_DIR\n"
CONFIRM_MSG+=" • Run as user: root\n"
CONFIRM_MSG+=" • GUI user: $ORIGINAL_USER\n"
CONFIRM_MSG+=" • DISPLAY: $USER_DISPLAY\n"
CONFIRM_MSG+=" • XAUTHORITY: $USER_XAUTHORITY"
whiptail --title "Confirm Configuration ⚙️" --yesno "$CONFIRM_MSG" 20 60
[ $? -ne 0 ] && {
whiptail --title "Cancelled" --msgbox \
"Installation cancelled.\nPlease rerun with correct values." 8 60
exit 0
}
# Create service file
cat <<EOF > "$SERVICE_PATH"
[Unit]
Description=Flutter Binary Service for Dragon
After=display-manager.service
Wants=display-manager.service
[Service]
Type=simple
# Run as root so the app has sudo privileges
User=root
# allow root to talk to the X session
ExecStartPre=/bin/bash -lc "xhost +SI:localuser:root"
# Optional delay to let everything settle
ExecStartPre=/bin/sleep 10
ExecStart=$BINARY_PATH
WorkingDirectory=$WORKING_DIR
Restart=always
RestartSec=5
Environment=DISPLAY=$USER_DISPLAY
Environment=XAUTHORITY=$USER_XAUTHORITY
ExecStop=/bin/kill -s SIGTERM \$MAINPID
[Install]
WantedBy=graphical.target
EOF
# Reload, enable, and start
systemctl daemon-reload
systemctl enable "$SERVICE_NAME"
systemctl start "$SERVICE_NAME"
# Show service status
systemctl status "$SERVICE_NAME" --no-pager > /tmp/dragon_status.txt
whiptail --title "Service Status 📊" --textbox /tmp/dragon_status.txt 20 70
whiptail --title "Success ✅" --msgbox \
"Dragon service installed and started successfully!" 8 50
}
# Install only the Debian package
install_deb_only() {
whiptail --title "Dragon Package Install 📦" --msgbox \
"This will install only the Dragon Center Debian package.\n\nThe ACPI EC driver and systemd service will not be configured." 12 60
# Check if .deb package exists
DEB_PATH="debian/packages/dragoncenter_1.0.1_amd64.deb"
if [ ! -f "$DEB_PATH" ]; then
whiptail --title "Package Not Found" --msgbox \
"Error: .deb package not found at $DEB_PATH\n\nPlease ensure the package exists and retry." 10 60
exit 1
fi
# Install the package
whiptail --title "Installing Package..." --infobox \
"Installing Dragon Center package...\nPlease wait." 8 50
if dpkg -i "$DEB_PATH"; then
whiptail --title "Success ✅" --msgbox \
"Dragon Center package installed successfully!\n\nNote: You may still need to configure the ACPI EC driver and service manually for full functionality." 12 60
else
whiptail --title "Installation Failed ❌" --msgbox \
"Failed to install the Dragon Center package.\n\nPlease check the package integrity and try again." 10 60
exit 1
fi
}
# Install only the ACPI EC driver
install_driver_only() {
whiptail --title "ACPI EC Driver Installation 🔌" --msgbox \
"This will install only the ACPI EC driver, which is required for hardware access.\n\nThe Dragon Center application and service will not be installed." 12 60
# Clone the repository if it doesn't exist
if [ ! -d "acpi_ec" ]; then
whiptail --title "Cloning Repository" --infobox \
"Cloning ACPI EC driver repository...\nPlease wait." 8 50
if ! git clone https://github.com/agnath18K/acpi_ec.git; then
whiptail --title "Error ❌" --msgbox \
"Failed to clone acpi_ec repository.\n\nPlease check your internet connection and try again." 10 60
exit 1
fi
fi
# Install dependencies and build the driver
whiptail --title "Installing Dependencies" --infobox \
"Installing build dependencies...\nPlease wait." 8 50
cd acpi_ec || exit 1
apt update
if ! apt install -y build-essential linux-headers-$(uname -r); then
whiptail --title "Error ❌" --msgbox \
"Failed to install build dependencies.\n\nPlease check your system and try again." 10 60
cd ..
exit 1
fi
# Run the installation script
whiptail --title "Installing Driver" --infobox \
"Installing ACPI EC driver...\nPlease wait." 8 50
if ! ./install.sh; then
whiptail --title "Error ❌" --msgbox \
"ACPI EC driver installation failed.\n\nPlease check the output for errors and try again." 10 60
cd ..
exit 1
fi
# Add user to ec group
ORIGINAL_USER=${SUDO_USER:-$(logname)}
if ! grep -q "^ec:" /etc/group; then
groupadd ec
fi
if ! groups "$ORIGINAL_USER" | grep -q "\bec\b"; then
if ! usermod -a -G ec "$ORIGINAL_USER"; then
whiptail --title "Warning ⚠️" --msgbox \
"Failed to add $ORIGINAL_USER to 'ec' group.\n\nYou may need to manually add your user to the 'ec' group." 10 60
fi
fi
cd ..
# Cleanup
whiptail --title "Cleanup" --yesno \
"Do you want to remove the temporary driver source files?" 8 60
if [ $? -eq 0 ]; then
rm -rf acpi_ec
fi
whiptail --title "Success ✅" --msgbox \
"ACPI EC driver installed successfully!\n\nYou may need to reboot your system for the driver to take effect." 10 60
}
# Full install: driver, .deb, then service
full_install() {
whiptail --title "Dragon Full Installer 🐉" --msgbox \
"This will:\n 1) Install the ACPI EC driver\n 2) Add your user to 'ec' group\n 3) Install .deb package (if found)\n 4) Configure and start the Dragon service\n\nFollow the prompts to complete." 15 60
# Step 1: ACPI EC driver
whiptail --title "ACPI EC Driver" --msgbox \
"Cloning and installing the ACPI EC driver from source." 10 50
if [ ! -d "acpi_ec" ]; then
git clone https://github.com/agnath18K/acpi_ec.git || {
whiptail --title "Error" --msgbox \
"Failed to clone acpi_ec repository." 8 50
exit 1
}
fi
cd acpi_ec || exit 1
apt update
apt install -y build-essential linux-headers-$(uname -r)
./install.sh || {
whiptail --title "Error" --msgbox \
"ACPI EC driver installation failed." 8 50
exit 1
}
# Add user to ec group
ORIGINAL_USER=${SUDO_USER:-$(logname)}
if ! grep -q "^ec:" /etc/group; then
groupadd ec
fi
if ! groups "$ORIGINAL_USER" | grep -q "\bec\b"; then
usermod -a -G ec "$ORIGINAL_USER" || {
whiptail --title "Error" --msgbox \
"Failed to add $ORIGINAL_USER to 'ec' group." 8 50
exit 1
}
fi
cd ..
# Step 2: .deb package
DEB_PATH="debian/packages/dragoncenter_1.0.1_amd64.deb"
if [ -f "$DEB_PATH" ]; then
dpkg -i "$DEB_PATH" || {
whiptail --title "Error" --msgbox \
"Failed to install .deb package." 8 50
exit 1
}
else
whiptail --title "Package Not Found" --yesno \
".deb not found at $DEB_PATH. Skip package installation?" 10 60
[ $? -ne 0 ] && {
whiptail --title "Aborting" --msgbox \
"Please ensure the .deb package exists and retry." 8 50
exit 1
}
fi
# Step 3: Service
install_service
# Cleanup
rm -rf acpi_ec
whiptail --title "Cleanup" --msgbox \
"Temporary files and repositories have been removed." 8 50
}
# Uninstall everything
uninstall_dragon() {
whiptail --title "Uninstall Dragon 🐉" --yesno \
"This will stop and remove:
• Dragon systemd service
• ACPI EC driver
• (optionally) /usr/local/lib/dragoncenter
Are you sure?" 15 60
[ $? -ne 0 ] && {
whiptail --title "Cancelled" --msgbox \
"Uninstallation cancelled." 8 50
exit 0
}
# Stop & disable service
if [ -f "$ERVICE_PATH" ]; then
systemctl stop "$SERVICE_NAME"
systemctl disable "$SERVICE_NAME"
rm -f "$SERVICE_PATH"
fi
systemctl daemon-reexec
systemctl daemon-reload
# Uninstall driver
TEMP_DIR=$(mktemp -d)
cd "$TEMP_DIR" || exit 1
git clone https://github.com/agnath18K/acpi_ec.git && cd acpi_ec
if [ -f './uninstall.sh' ]; then
chmod +x ./uninstall.sh
./uninstall.sh
fi
cd / && rm -rf "$TEMP_DIR"
# Optional app directory cleanup
whiptail --title "Remove App Files?" --yesno \
"Do you want to delete /usr/local/lib/dragoncenter as well?" 10 60
[ $? -eq 0 ] && rm -rf /usr/local/lib/dragoncenter
# Final cleanup
rm -rf acpi_ec
whiptail --title "Done" --msgbox \
"Uninstallation completed successfully." 8 50
}
# Main menu
CHOICE=$(whiptail --title "Dragon Installer Main Menu" --menu \
"Select an option:" 15 60 6 \
"install" "Full install (driver + .deb + service)" \
"install-driver" "Install only the ACPI EC driver" \
"install-deb" "Install only the .deb package" \
"install-service" "Service-only install" \
"uninstall" "Uninstall everything" \
"exit" "Exit script" 3>&1 1>&2 2>&3)
case "$CHOICE" in
install)
full_install
;;
install-driver)
install_driver_only
;;
install-deb)
install_deb_only
;;
install-service)
install_service
;;
uninstall)
uninstall_dragon
;;
exit)
exit 0
;;
*)
exit 1
;;
esac
exit 0