Skip to content

Instantly share code, notes, and snippets.

@muness
Last active August 19, 2025 14:49
Show Gist options
  • Select an option

  • Save muness/d9995d1d8a32b6b4de3f19c2bc518308 to your computer and use it in GitHub Desktop.

Select an option

Save muness/d9995d1d8a32b6b4de3f19c2bc518308 to your computer and use it in GitHub Desktop.
Install glances including GPU and web server plugins
#!/usr/bin/env bash
#
# tb3_auto_auth.sh
# Enumerate all Thunderbolt devices via boltctl, enroll them if needed,
# and authorize any that are currently connected.
set -e
# Make sure boltctl is installed
if ! command -v boltctl &>/dev/null; then
echo "Error: boltctl not found. Install 'bolt' from your package manager first."
exit 1
fi
echo "=== Scanning for Thunderbolt devices to enroll/authorize… ==="
# Extract each UUID from `boltctl list`
UUIDS=()
while IFS= read -r line; do
# Each line matching "UUID: <uuid>" → grab the second field
UUIDS+=("$(awk '{print $2}' <<<"$line")")
done < <(boltctl list | grep 'UUID:')
if [ ${#UUIDS[@]} -eq 0 ]; then
echo "No Thunderbolt devices found in 'boltctl list'."
exit 0
fi
for uuid in "${UUIDS[@]}"; do
echo
echo "→ Processing device UUID = $uuid"
# 1) Enroll (if not already enrolled). Ignore "already enrolled" errors.
if boltctl enroll "$uuid" &>/dev/null; then
echo " • Enrolled $uuid"
else
echo " • Already enrolled (or enroll failed)."
fi
# 2) Check connection status before authorizing
connected=$(boltctl info "$uuid" | awk '/Connected:/ {print $2}')
if [ "$connected" != "yes" ]; then
echo " • Device is not connected right now. Skipping authorize."
continue
fi
# 3) Authorize if not already authorized
authorized=$(boltctl info "$uuid" | awk '/authorized:/ {print $2}')
if [ "$authorized" = "yes" ]; then
echo " • Already authorized."
else
if boltctl authorize "$uuid" &>/dev/null; then
echo " • Authorized $uuid"
else
echo " • Failed to authorize (device might have disconnected)."
fi
fi
done
echo
echo "=== Done. Any connected TB devices are now enrolled + authorized. ==="
mkdir -p ~/.config/glances
cat > ~/.config/glances/glances.conf <<EOF
[global]
# enable the GPU plugin for both CLI & Web
gpu = True
# optionally toggle the Sensors section on by default
show_sensors = True
[webserver]
# make sure the Web UI will include the sensors/GPU panel
export_gpu = True
EOF
sudo tee /etc/systemd/system/glances.service > /dev/null << 'EOF'
[Unit]
Description=Glances HTTP Server (CPU + GPU monitoring)
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=audiolinux
WorkingDirectory=/home/audiolinux
ExecStart=/home/audiolinux/glances-venv/bin/glances -w --bind 0.0.0.0
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
sudo chmod 644 /etc/systemd/system/glances.service
sudo systemctl daemon-reload
sudo systemctl enable glances.service
sudo systemctl start glances.service
#!/usr/bin/env bash
## Suitable for Arch Linux.
## I am using this under AudioLinux v4 to observe HQPlayer Desktop performance.
set -euo pipefail
# 1. Ensure we have python3-venv and pip available
echo "Installing python3-venv (if missing)…"
sudo pacman -Sy --noconfirm python-virtualenv python-pip
# 2. Create a venv in ~/glances-venv (if it doesn't already exist)
VENV_DIR="$HOME/glances-venv"
if [[ -d "$VENV_DIR" ]]; then
echo "==> Virtualenv already exists at $VENV_DIR, skipping creation."
else
echo "==> Creating Python venv at $VENV_DIR…"
python3 -m venv "$VENV_DIR"
fi
# 3. Activate the venv
echo "==> Activating venv…"
# shellcheck source=/dev/null
source "$VENV_DIR/bin/activate"
# 4. Upgrade pip & setuptools inside the venv
echo "==> Upgrading pip & setuptools in the venv…"
pip install --upgrade pip setuptools
# 5. Install Glances + NVIDIA plugin dependencies
echo "==> Installing Glances + GPU support…"
pip install glances gpustat py3nvml uvicorn fastapi jinja2
# 6. Verify installation
echo "==> Verifying Glances and GPU plugin…"
if ! command -v glances >/dev/null 2>&1; then
echo "ERROR: 'glances' not found in venv PATH." >&2
exit 1
fi
echo
echo "======================================================="
echo "✅ Glances and GPU‐monitoring plugins are installed."
echo " To run Glances as a web server, execute:"
echo
echo " source \"$VENV_DIR/bin/activate\""
echo " glances -w --bind 0.0.0.0"
echo
echo " Then point your browser to:"
echo
echo " http://<this-machine-IP>:61208/"
echo
echo " (Press Ctrl+C in this shell to stop Glances.)"
echo "======================================================="
echo
# 7. (Optional) auto-launch now
read -r -p "Do you want to start Glances web server right now? [y/N] " yn
case "$yn" in
[Yy]* )
echo "Starting Glances in web mode…"
glances -w --bind 0.0.0.0
;;
* )
echo "Skipping auto-start. You can run 'glances -w --bind 0.0.0.0' later."
;;
esac
# 8. Deactivate venv (if it’s still active)
deactivate 2>/dev/null || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment