Skip to content

Instantly share code, notes, and snippets.

@jesuslg123
Created March 26, 2026 20:37
Show Gist options
  • Select an option

  • Save jesuslg123/e7be315654810e3e2dc199d71cfc96e0 to your computer and use it in GitHub Desktop.

Select an option

Save jesuslg123/e7be315654810e3e2dc199d71cfc96e0 to your computer and use it in GitHub Desktop.
Bash Script to install a patched version of jtop for Jetson Orin Nano
cat > /tmp/fix_jtop.sh <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$HOME/jetson_stats"
PATCH_FILE="$REPO_DIR/jtop/gui/lib/common.py"
echo "[1/8] Installing required packages..."
sudo apt update
sudo apt install -y git python3-pip
echo "[2/8] Removing old jetson-stats installs..."
sudo python3 -m pip uninstall -y jetson-stats UNKNOWN || true
echo "[3/8] Removing old binaries and old repo..."
sudo rm -f /usr/local/bin/jtop /usr/local/bin/jetson_release /usr/local/bin/jetson_config /usr/local/bin/jetson_swap
rm -rf "$REPO_DIR"
echo "[4/8] Upgrading Python packaging tools..."
sudo python3 -m pip install -U pip setuptools wheel build
echo "[5/8] Cloning fresh repo..."
git clone https://github.com/rbonghi/jetson_stats.git "$REPO_DIR"
echo "[6/8] Applying patch..."
python3 - <<'PY'
from pathlib import Path
import re
path = Path.home() / "jetson_stats" / "jtop" / "gui" / "lib" / "common.py"
text = path.read_text(encoding="utf-8")
if 'if value is None:' in text:
print("[OK] Patch already present")
else:
pattern = r"def unit_to_string\(value, unit, type\):\s*return value_to_string\(value, unit, type, unit_min\)"
replacement = (
"def unit_to_string(value, unit, type):\n"
" if value is None:\n"
" return \"-\"\n"
" return value_to_string(value, unit, type, unit_min)"
)
new_text, count = re.subn(pattern, replacement, text, count=1)
if count != 1:
raise SystemExit("[ERROR] Could not find unit_to_string() to patch")
path.write_text(new_text, encoding="utf-8")
print("[OK] Patch applied")
PY
echo "[7/8] Reinstalling patched jetson-stats..."
cd "$REPO_DIR"
sudo python3 -m pip install . --no-cache-dir
echo "[8/8] Restarting jtop service..."
sudo systemctl restart jtop.service || true
echo
echo "[INFO] Patched function:"
python3 - <<'PY'
from pathlib import Path
import re
path = Path.home() / "jetson_stats" / "jtop" / "gui" / "lib" / "common.py"
text = path.read_text(encoding="utf-8")
m = re.search(r"def unit_to_string\(value, unit, type\):.*?return value_to_string\(value, unit, type, unit_min\)", text, re.S)
print(m.group(0) if m else "[WARN] function not found")
PY
echo
echo "[INFO] Installed version:"
jtop --version || /usr/local/bin/jtop --version || true
echo
echo "[DONE] Now run:"
echo "jtop"
EOF
chmod +x /tmp/fix_jtop.sh
bash /tmp/fix_jtop.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment