@zeluizr/lattice 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env bash
2
+ # (Optional) Allow `powermetrics` via sudo WITHOUT a password, so lattice can
3
+ # show watts without you typing your password every time.
4
+ #
5
+ # Creates /etc/sudoers.d/lattice-powermetrics. Run with:
6
+ # sudo bash scripts/setup-sudoers.sh
7
+ set -euo pipefail
8
+
9
+ if [ "$(id -u)" -ne 0 ]; then
10
+ echo "Run with sudo: sudo bash scripts/setup-sudoers.sh" >&2
11
+ exit 1
12
+ fi
13
+
14
+ USER_NAME="${SUDO_USER:-$(whoami)}"
15
+ PM="$(command -v powermetrics || echo /usr/bin/powermetrics)"
16
+ FILE="/etc/sudoers.d/lattice-powermetrics"
17
+
18
+ echo "${USER_NAME} ALL=(root) NOPASSWD: ${PM}" > "$FILE"
19
+ chmod 0440 "$FILE"
20
+
21
+ # validate syntax; if invalid, remove so it can't break sudo
22
+ if visudo -cf "$FILE" >/dev/null; then
23
+ echo "OK: ${USER_NAME} can run ${PM} without a password."
24
+ echo "Now run: lattice"
25
+ else
26
+ rm -f "$FILE"
27
+ echo "Invalid syntax — file removed." >&2
28
+ exit 1
29
+ fi