122 lines
3.8 KiB
Bash
122 lines
3.8 KiB
Bash
# 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"
|
|
}
|