This commit is contained in:
sankalp committed 2026-03-23 15:28:18 +05:45
1 parent 899d4c831f
commit 46cbcb5b4b
3 files changed
+124 -4

No files matched your search

+1 -2
View File
@@ -24,5 +24,4 @@ target
# Added by cargo
/target
./lapctl.py
lapctl.py
./PKGBUILD
+121
View File
@@ -0,0 +1,121 @@
# Maintainer: Sankalp Tharu <contact@sankalptharu.com.np>
pkgname=lapctl
pkgver=0.3.0
pkgrel=1
pkgdesc="Control Linux laptop hardware (Graphics, Battery, Power, Cooling, Display) with Rust"
arch=('x86_64' 'aarch64')
url="https://github.com/S4NKALP/lapctl"
license=('MIT')
depends=('systemd-libs' 'dbus' 'wayland')
makedepends=('rust' 'cargo' 'wayland-protocols')
optdepends=(
'xorg-xrandr: for GPU switching on X11'
'nvidia-settings: for NVIDIA GPU management on X11'
)
source=("${pkgname}-${pkgver}.tar.gz::${url}/archive/refs/tags/${pkgver}.tar.gz")
sha256sums=('fda8c8dd9a170cbd54b549a57194dc36f1cdff7387cb85f70d1c1ae55c315259')
prepare() {
cd "${pkgname}-${pkgver}"
export RUSTUP_TOOLCHAIN=stable
cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}
build() {
cd "${pkgname}-${pkgver}"
export RUSTUP_TOOLCHAIN=stable
export CARGO_TARGET_DIR=target
cargo build --frozen --release --all-features
}
check() {
cd "${pkgname}-${pkgver}"
export RUSTUP_TOOLCHAIN=stable
cargo test --frozen --all-features
}
package() {
cd "${pkgname}-${pkgver}"
# Binary
install -Dm755 "target/release/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"
# D-Bus Policy
install -Dm644 /dev/stdin "${pkgdir}/etc/dbus-1/system.d/org.lapctl.conf" <<EOF
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.lapctl"/>
<allow send_destination="org.lapctl"/>
<allow receive_sender="org.lapctl"/>
</policy>
<policy group="wheel">
<allow send_destination="org.lapctl"/>
<allow receive_sender="org.lapctl"/>
</policy>
<policy group="sudo">
<allow send_destination="org.lapctl"/>
<allow receive_sender="org.lapctl"/>
</policy>
</busconfig>
EOF
# Systemd Service
install -Dm644 /dev/stdin "${pkgdir}/usr/lib/systemd/system/lapctld.service" <<EOF
[Unit]
Description=lapctl hardware management daemon
After=dbus.service
[Service]
Type=simple
ExecStart=/usr/bin/lapctl daemon
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Polkit Policy
install -Dm644 /dev/stdin "${pkgdir}/usr/share/polkit-1/actions/org.lapctl.policy" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<vendor>lapctl</vendor>
<vendor_url>https://github.com/S4NKALP/lapctl</vendor_url>
<action id="org.lapctl.execute">
<description>Elevated execution for lapctl</description>
<message>Authentication is required to perform privileged lapctl operations</message>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/lapctl</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">false</annotate>
</action>
</policyconfig>
EOF
# Polkit Rules
install -Dm644 /dev/stdin "${pkgdir}/usr/share/polkit-1/rules.d/10-lapctl.rules" <<EOF
/* /usr/share/polkit-1/rules.d/10-lapctl.rules
* Automatically generated by lapctl package
* This rule allows users in the 'wheel' or 'sudo' groups to
* perform privileged lapctl operations via pkexec without a password.
*/
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.policykit.exec" &&
action.lookup("program").indexOf("lapctl") !== -1 &&
(subject.isInGroup("wheel") || subject.isInGroup("sudo"))) {
return polkit.Result.YES;
}
});
EOF
# License
install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
+2 -2
View File
@@ -12,7 +12,7 @@ const POLKIT_POLICY: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<policyconfig>
<vendor>lapctl</vendor>
<vendor_url>https://github.com/S4NKALP/lapctl</vendor_url>
<action id="org.s4nkalp.lapctl.execute">
<action id="org.lapctl.execute">
<description>Elevated execution for lapctl</description>
<message>Authentication is required to perform privileged lapctl operations</message>
<defaults>
@@ -89,7 +89,7 @@ pub fn execute() {
create_file(rules_path, LAPCTL_UDEV_RULES, false);
// Polkit fallbacks for rootless execution without the daemon
let polkit_policy_path = "/usr/share/polkit-1/actions/org.s4nkalp.lapctl.policy";
let polkit_policy_path = "/usr/share/polkit-1/actions/org.lapctl.policy";
create_file(polkit_policy_path, POLKIT_POLICY, false);
let polkit_rules_path = "/etc/polkit-1/rules.d/10-lapctl.rules";