install.sh 993 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. NAME="amd-gpu-temp-control"
  4. SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  5. SRC="$SELF/$NAME.js"
  6. TPL="$SELF/$NAME.service"
  7. BINARY="/usr/local/bin/$NAME"
  8. DEST="/etc/systemd/system/$NAME.service"
  9. install() {
  10. [[ -f "$TPL" ]] || { echo "Missing $NAME.service template"; exit 1; }
  11. [[ -f "$SRC" ]] || { echo "Missing $NAME.js"; exit 1; }
  12. command -v node &>/dev/null || { echo "node not found"; exit 1; }
  13. command -v upp &>/dev/null || { echo "upp not found in PATH"; exit 1; }
  14. cp "$SRC" "$BINARY"
  15. chmod +x "$BINARY"
  16. cp "$TPL" "$DEST"
  17. systemctl daemon-reload
  18. systemctl enable "$NAME.service"
  19. systemctl restart "$NAME.service"
  20. echo "Installed — journalctl -u $NAME -f"
  21. }
  22. uninstall() {
  23. systemctl stop "$NAME" 2>/dev/null || true
  24. systemctl disable "$NAME" 2>/dev/null || true
  25. rm -f "$DEST" "$BINARY"
  26. systemctl daemon-reload
  27. echo "Uninstalled."
  28. }
  29. case "${1:-}" in
  30. --uninstall) uninstall ;;
  31. *) install ;;
  32. esac