Portability: sysfs-only sensors with thermal-zone fallback, /sys/block disk discovery, fs blacklist, pwrstat/NUT/apcupsd UPS, login shell from passwd, templated unit + install for any user, cross-compile targets
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
3c6f4d4639
commit
7053cce7fe
+26
-5
@@ -1,11 +1,32 @@
|
||||
#!/bin/sh
|
||||
# Install the built binary and unit on this host, then (re)start the service.
|
||||
# Install the built binary and a systemd unit on this host, then (re)start the service.
|
||||
# Runs as the user who should own the terminals (their login shell, their sudo rights);
|
||||
# needs sudo only for the copy into /usr/local/bin and the unit install.
|
||||
#
|
||||
# HAMLAB_USER user the daemon runs as (default: the invoking user)
|
||||
# PREFIX binary directory (default: /usr/local/bin)
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
sudo install -m 0755 bin/hamlab /usr/local/bin/hamlab
|
||||
sudo install -m 0644 deploy/hamlab.service /etc/systemd/system/hamlab.service
|
||||
|
||||
USER_NAME="${HAMLAB_USER:-${SUDO_USER:-$(id -un)}}"
|
||||
GROUP_NAME="$(id -gn "$USER_NAME")"
|
||||
HOME_DIR="$(getent passwd "$USER_NAME" | cut -d: -f6)"
|
||||
PREFIX="${PREFIX:-/usr/local/bin}"
|
||||
[ -n "$HOME_DIR" ] || { echo "no home dir for $USER_NAME" >&2; exit 1; }
|
||||
|
||||
unit=$(mktemp)
|
||||
sed -e "s|@USER@|$USER_NAME|g" -e "s|@GROUP@|$GROUP_NAME|g" -e "s|@HOME@|$HOME_DIR|g" -e "s|@PREFIX@|$PREFIX|g" \
|
||||
deploy/hamlab.service > "$unit"
|
||||
|
||||
sudo install -m 0755 bin/hamlab "$PREFIX/hamlab"
|
||||
sudo install -m 0644 "$unit" /etc/systemd/system/hamlab.service
|
||||
rm -f "$unit"
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now hamlab.service >/dev/null
|
||||
sudo systemctl enable hamlab.service >/dev/null
|
||||
if [ ! -f "$HOME_DIR/apps/hamlab/config.json" ]; then
|
||||
echo "No config yet. Set a password, then start: $PREFIX/hamlab passwd && sudo systemctl start hamlab" >&2
|
||||
exit 0
|
||||
fi
|
||||
sudo systemctl restart hamlab.service
|
||||
sleep 1
|
||||
systemctl is-active hamlab.service && /usr/local/bin/hamlab version
|
||||
systemctl is-active hamlab.service && "$PREFIX/hamlab" version
|
||||
|
||||
Reference in New Issue
Block a user