-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·241 lines (203 loc) · 8.2 KB
/
install.sh
File metadata and controls
executable file
·241 lines (203 loc) · 8.2 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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Check for root privileges ---
if [ "$EUID" -ne 0 ]; then
echo "This script requires root privileges. Re-running with sudo..."
sudo "$0" "$@"
exit
fi
echo "--- Starting Victus Control Installation ---"
# --- 1. Install Dependencies ---
echo "--> Installing required packages..."
packages=(meson ninja gtk4 git dkms)
declare -A header_packages=()
for module_dir in /usr/lib/modules/*; do
[[ -d "${module_dir}" ]] || continue
pkgbase_path="${module_dir}/pkgbase"
kernel_release=$(basename "${module_dir}")
if [[ -r "${pkgbase_path}" ]]; then
kernel_pkg=$(<"${pkgbase_path}")
kernel_pkg=${kernel_pkg//[[:space:]]/}
header_pkg="${kernel_pkg}-headers"
if pacman -Si "${header_pkg}" > /dev/null 2>&1; then
header_packages["${header_pkg}"]=1
echo "Detected kernel '${kernel_pkg}' (${kernel_release}); queued '${header_pkg}'."
continue
fi
echo "Warning: Unable to find package '${header_pkg}' for kernel '${kernel_pkg}' (${kernel_release})."
else
echo "Warning: Unable to read kernel package info at '${pkgbase_path}'."
fi
header_packages[linux-headers]=1
done
if [[ ${#header_packages[@]} -eq 0 ]]; then
echo "Warning: No kernel headers detected; defaulting to 'linux-headers'."
header_packages[linux-headers]=1
fi
for header_pkg in "${!header_packages[@]}"; do
packages+=("${header_pkg}")
done
pacman -S --needed --noconfirm "${packages[@]}"
# --- 2. Create Users and Groups ---
echo "--> Creating secure users and groups..."
# Ensure the victus group exists as a system group for udev ACLs
if ! getent group victus > /dev/null; then
groupadd --system victus
echo "Group 'victus' created."
else
echo "Group 'victus' already exists."
group_gid=$(getent group victus | cut -d: -f3)
if (( group_gid >= 1000 )); then
echo "Warning: Group 'victus' (GID ${group_gid}) is not a system group; udev rules may ignore it."
echo " Consider recreating it as a system group (sudo groupdel victus; sudo groupadd --system victus)."
fi
fi
# Create the victus-backend group if it doesn't exist
if ! getent group victus-backend > /dev/null; then
groupadd --system victus-backend
echo "Group 'victus-backend' created."
else
echo "Group 'victus-backend' already exists."
fi
# Create the victus-backend user if it doesn't exist
if ! id -u victus-backend > /dev/null 2>&1; then
useradd --system -g victus-backend -s /usr/bin/nologin victus-backend
echo "User 'victus-backend' created."
else
echo "User 'victus-backend' already exists."
fi
# Add victus-backend to the victus group
if ! groups victus-backend | grep -q '\bvictus\b'; then
usermod -aG victus victus-backend
echo "User 'victus-backend' added to the 'victus' group."
else
echo "User 'victus-backend' is already in the 'victus' group."
fi
# Add the user who invoked sudo to the 'victus' group
# SUDO_USER is set by sudo to the username of the original user.
if [ -n "$SUDO_USER" ]; then
if ! groups "$SUDO_USER" | grep -q '\bvictus\b'; then
usermod -aG victus "$SUDO_USER"
echo "User '$SUDO_USER' added to the 'victus' group."
else
echo "User '$SUDO_USER' is already in the 'victus' group."
fi
else
echo "Warning: Could not determine the original user. Please add your user to the 'victus' group manually with: sudo usermod -aG victus \$USER"
fi
# --- 2.5. Configure Sudoers and Scripts ---
echo "--> Installing helper script and configuring sudoers..."
# Install the fan control scripts to /usr/bin
install -m 0755 backend/src/set-fan-speed.sh /usr/bin/set-fan-speed.sh
install -m 0755 backend/src/set-fan-mode.sh /usr/bin/set-fan-mode.sh
# Remove any old sudoers file that may exist
rm -f /etc/sudoers.d/victus-fan-sudoers
# Install the new sudoers file
install -m 0440 victus-control-sudoers /etc/sudoers.d/victus-control-sudoers
echo "Helper script and sudoers file installed."
# --- 3. Install Patched HP-WMI Kernel Module ---
echo "--> Installing patched hp-wmi kernel module..."
wmi_root="wmi-project"
wmi_repo="${wmi_root}/hp-wmi-fan-and-backlight-control"
mkdir -p "${wmi_root}"
if [ -d "${wmi_repo}/.git" ]; then
echo "Kernel module source directory already exists. Updating repository..."
if ! git -C "${wmi_repo}" fetch origin master; then
echo "Warning: Failed to fetch latest hp-wmi-fan-and-backlight-control changes."
else
git -C "${wmi_repo}" reset --hard origin/master || {
echo "Warning: Failed to reset hp-wmi-fan-and-backlight-control repository to origin/master."
echo " Remove the directory manually if the local clone is corrupted."
}
fi
else
git clone https://github.com/Batuhan4/hp-wmi-fan-and-backlight-control.git "${wmi_repo}"
fi
pushd "${wmi_repo}" >/dev/null
# Check if the module is already installed with DKMS
module_name="hp-wmi-fan-and-backlight-control"
module_version="0.0.2"
if dkms status -m "${module_name}" -v "${module_version}" >/dev/null 2>&1; then
echo "Removing existing DKMS registration for ${module_name}/${module_version}..."
dkms remove "${module_name}/${module_version}" --all || true
fi
echo "Registering DKMS module ${module_name}/${module_version}..."
dkms add .
declare -a kernels_needing_install=()
for module_dir in /usr/lib/modules/*; do
[[ -d "${module_dir}" ]] || continue
kernel_release=$(basename "${module_dir}")
kernel_status=$(dkms status -m "${module_name}" -v "${module_version}" -k "${kernel_release}" || true)
if [[ "${kernel_status}" != *"installed"* ]]; then
kernels_needing_install+=("${kernel_release}")
fi
done
if [[ ${#kernels_needing_install[@]} -eq 0 ]]; then
echo "hp-wmi module is already installed via DKMS for all detected kernels."
else
echo "Installing hp-wmi module for kernels: ${kernels_needing_install[*]}"
for kernel_release in "${kernels_needing_install[@]}"; do
dkms install "${module_name}/${module_version}" -k "${kernel_release}"
done
fi
# Ensure the new module is loaded
if lsmod | grep -q "hp_wmi"; then
rmmod hp_wmi
fi
modprobe hp_wmi
popd >/dev/null
echo "Kernel module installed and loaded."
# --- 4. Build and Install victus-control ---
echo "--> Building and installing the application..."
meson setup build --prefix=/usr
ninja -C build
ninja -C build install
echo "Application built and installed."
# --- 5. Enable Backend Service ---
echo "--> Configuring and starting backend service..."
# Ensure the tmpfiles.d config is applied immediately to create the socket directory
systemd-tmpfiles --create || {
echo "Warning: Failed to create tmpfiles, continuing..."
}
systemctl daemon-reload || {
echo "Error: Failed to reload systemd daemon"
exit 1
}
udevadm control --reload-rules && udevadm trigger || {
echo "Warning: Failed to reload udev rules, continuing..."
}
if systemctl list-unit-files | grep -q '^victus-healthcheck.service'; then
echo "--> Running kernel health check..."
systemctl enable --now victus-healthcheck.service || {
echo "Warning: Failed to run victus-healthcheck.service"
}
fi
if systemctl list-unit-files | grep -q '^victus-backend.service'; then
echo "--> Refreshing victus-backend.service state..."
if systemctl is-enabled victus-backend.service >/dev/null 2>&1; then
systemctl restart victus-backend.service || {
echo "Error: Failed to restart victus-backend service"
exit 1
}
echo "Backend service restarted."
else
systemctl enable --now victus-backend.service || {
echo "Error: Failed to enable/start victus-backend service"
exit 1
}
echo "Backend service enabled and started."
fi
else
systemctl enable --now victus-backend.service || {
echo "Error: Failed to enable/start victus-backend service"
exit 1
}
echo "Backend service enabled and started."
fi
echo ""
echo "--- Installation Complete! ---"
echo ""
echo "IMPORTANT: For the group changes to take full effect, please log out and log back in."
echo "After logging back in, you can launch the application from your desktop menu or by running 'victus-control' in the terminal."
echo ""