blob: d153c32387047ba5b493444d1c307ed88fa33f00 (
plain)
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
|
#!/bin/sh
set -e
GROUP_NAME="defguard"
SERVICE_NAME="defguard-service"
RESOLVED_SERVICE_NAME="systemd-resolved.service"
post_install() {
# Create the group if it doesn't exist
if ! getent group "$GROUP_NAME" >/dev/null; then
/usr/bin/groupadd --system "$GROUP_NAME"
echo "Created group $GROUP_NAME"
fi
# Determine target user
TARGET_USER=""
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
TARGET_USER="$SUDO_USER"
elif [ -n "$USER" ] && [ "$USER" != "root" ]; then
TARGET_USER="$USER"
fi
# Add user to group if we found a valid target
if [ -n "$TARGET_USER" ]; then
if getent passwd "$TARGET_USER" >/dev/null; then
# Try to add user to group and check if it succeeded
if usermod -a -G "$GROUP_NAME" "$TARGET_USER"; then
echo "Added user $TARGET_USER to group $GROUP_NAME"
# Only show reboot message if user was actually added
echo "================================================"
echo " IMPORTANT: Reboot or Re-login Required"
echo "================================================"
echo "The user has been added to the defguard group."
echo "Please reboot or log out and back in for the"
echo "group membership changes to take effect."
echo "================================================"
else
echo "Warning: Failed to add user $TARGET_USER to group $GROUP_NAME"
exit 1
fi
fi
fi
# Handle systemd services
if [ -d /run/systemd/system ]; then
# Reload systemd to recognize new service file
systemctl daemon-reload
# Enable resolved service
systemctl enable "$RESOLVED_SERVICE_NAME"
# Start the resolved service now
systemctl start "$RESOLVED_SERVICE_NAME"
# Enable service to start on boot
systemctl enable "$SERVICE_NAME"
# Start the service now
systemctl start "$SERVICE_NAME"
fi
gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
update-desktop-database -q
}
post_upgrade() {
post_install
}
pre_remove() {
# Service file still exists, just disable it
if [ -d /run/systemd/system ]; then
systemctl stop $SERVICE_NAME
fi
if getent group "$GROUP_NAME" >/dev/null; then
groupdel "$GROUP_NAME" || true
fi
}
post_remove() {
# Service file still exists, just disable it
if [ -d /run/systemd/system ]; then
systemctl disable "$SERVICE_NAME" || true
systemctl daemon-reload
fi
gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
update-desktop-database -q
}
|