Skip to content

Commit 3be722e

Browse files
committed
feat: switch to systemd instantiated service template
- Replace single service with instantiated template (@.service.in) - Allow multiple mode instances (0,1,2,4,5) via systemd parameter - Update CMakeLists.txt to handle version and new service file - Bump PKGBUILD version to 0.1.1 and pass PROJECT_VERSION - Improve install/uninstall scripts for instantiated units - Update README with new usage examples and uninstall note - Add pkg/ to .gitignore
1 parent c9111db commit 3be722e

7 files changed

Lines changed: 65 additions & 30 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.*
2-
build*
2+
build*
3+
pkg/**

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(my_msi_coreliquid_driver C)
2+
3+
if(NOT PROJECT_VERSION)
4+
set(PROJECT_VERSION "0.1.0")
5+
endif()
6+
7+
project(my_msi_coreliquid_driver
8+
VERSION ${PROJECT_VERSION}
9+
LANGUAGES C)
310

411
set(CMAKE_C_STANDARD 11)
512
set(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
@@ -37,13 +44,13 @@ target_link_libraries(my_msi_coreliquid_driver
3744
)
3845

3946
configure_file(
40-
"${CMAKE_CURRENT_SOURCE_DIR}/service/my_msi_coreliquid_driver.service.in"
41-
"${CMAKE_CURRENT_BINARY_DIR}/my_msi_coreliquid_driver.service"
47+
"${CMAKE_CURRENT_SOURCE_DIR}/service/my_msi_coreliquid_driver@.service.in"
48+
"${CMAKE_CURRENT_BINARY_DIR}/my_msi_coreliquid_driver@.service"
4249
@ONLY
4350
)
4451

4552
install(TARGETS my_msi_coreliquid_driver DESTINATION bin)
46-
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/my_msi_coreliquid_driver.service"
53+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/my_msi_coreliquid_driver@.service"
4754
DESTINATION "/usr/lib/systemd/system/")
4855
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/service/my_msi_coreliquid_driver_sleep.sh"
4956
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ

PKGBUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pkgname=msi-meg-coreliquid-s360-driver
2-
pkgver=0.1.0
2+
pkgver=0.1.1
33
pkgrel=1
44
pkgdesc="Driver MSI Coreliquid MEG S360 (GPL3, hidapi)"
55
arch=('x86_64')
@@ -15,6 +15,7 @@ sha256sums=('SKIP')
1515

1616
build() {
1717
cmake -B build -S "$startdir" \
18+
-DPROJECT_VERSION="$pkgver" \
1819
-DCMAKE_BUILD_TYPE=Release \
1920
-DCMAKE_INSTALL_PREFIX=/usr/local
2021

README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ but having the system library is recommended for stability.
3636
mkdir build
3737
cd build
3838
cmake -DCMAKE_BUILD_TYPE=Release ..
39-
cmake --build . --config Release
39+
cmake --build .
4040
```
4141

4242
Here, I use libhidapi-hidraw, but I guess it would work as well with libhidapi-libusb0.
@@ -50,6 +50,12 @@ After building, you can install the driver system‑wide:
5050
sudo cmake --install . --prefix "/usr/local"
5151
```
5252

53+
You can use install_manifest.txt to remove the installed files:
54+
55+
```bash
56+
cat install_manifest.txt | xargs sudo rm
57+
```
58+
5359
This will install:
5460

5561
- The executable `/usr/local/bin/my_msi_coreliquid_driver`
@@ -96,12 +102,22 @@ Enable and start it with:
96102

97103
```bash
98104
sudo systemctl daemon-reload
99-
sudo systemctl enable my_msi_coreliquid_driver.service
100-
sudo systemctl start my_msi_coreliquid_driver.service
105+
sudo systemctl enable my_msi_coreliquid_driver@5.service
106+
sudo systemctl start my_msi_coreliquid_driver@5.service
107+
```
108+
109+
Switch to Game mode (2):
110+
111+
```bash
112+
systemctl stop my_msi_coreliquid_driver@5
113+
systemctl start my_msi_coreliquid_driver@2
101114
```
102115

103-
The service runs with mode `5` (SMART) by default. To change the mode, edit the service file
104-
(`/usr/lib/systemd/system/my_msi_coreliquid_driver.service`) and modify the `-M` argument.
116+
Make Silent (0) mode the default mode when booting the system:
117+
118+
```bash
119+
systemctl enable my_msi_coreliquid_driver@0
120+
```
105121

106122
## Arch Linux
107123

@@ -111,7 +127,6 @@ You can build from source using the provided PKGBUILD.
111127
makepkg -i
112128
```
113129

114-
115130
## License
116131

117132
GPLv3 – see the LICENSE file.

msi-coreliquid-driver.install

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
post_install() {
22
udevadm control --reload-rules && udevadm trigger
33
systemctl daemon-reload
4-
systemctl enable --now my_msi_coreliquid_driver.service
4+
systemctl enable --now my_msi_coreliquid_driver@5.service
55
}
66

77
post_upgrade() {
88
systemctl daemon-reload
9-
systemctl restart my_msi_coreliquid_driver.service
9+
10+
CURRENT_UNIT=$(systemctl list-units --state=active --no-legend "my_msi_coreliquid_driver@*" | awk '{print $1}')
11+
if [ -n "$CURRENT_UNIT" ]; then
12+
systemctl restart "$CURRENT_UNIT"
13+
else
14+
systemctl start my_msi_coreliquid_driver@5.service
15+
fi
1016
}
1117

1218
pre_remove() {
13-
systemctl disable --now my_msi_coreliquid_driver.service
19+
CURRENT_UNITS=$(systemctl list-units --all --no-legend "my_msi_coreliquid_driver@*" | awk '{print $1}')
20+
for unit in $CURRENT_UNITS; do
21+
systemctl disable --now "$unit"
22+
done
1423
}

service/my_msi_coreliquid_driver.service.in

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[Unit]
2+
Description=MSI MEG CoreLiquid S360 Daemon (Mode %i)
3+
Conflicts=my_msi_coreliquid_driver@0.service my_msi_coreliquid_driver@1.service my_msi_coreliquid_driver@2.service my_msi_coreliquid_driver@4.service my_msi_coreliquid_driver@5.service
4+
5+
6+
[Service]
7+
Type=simple
8+
ExecStart=@INSTALL_PREFIX@/bin/my_msi_coreliquid_driver -M %i startd
9+
StandardOutput=journal
10+
StandardError=journal
11+
ExecReload=/bin/kill -HUP $MAINPID
12+
ExecStop=/bin/kill -TERM $MAINPID
13+
KillMode=mixed
14+
Restart=on-failure
15+
16+
[Install]
17+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)