diff --git a/README.md b/README.md index 0852110b..8a3e2934 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,19 @@ or sudo pip3 install --break-system-packages git+https://github.com/rbonghi/jetson_stats.git ``` +### Option 4: Ubuntu 24.04 run jtop without sudo and without "--break-system-packages" +```console +First run "sudo -v" + -v, --validate does not run any command, but does allow the use of sudo in the bash script. +Then "download install_jtop_torun_without_sudo.sh" +Make it executable: +chmod +x install_jtop_torun_without_sudo.sh +Then run it: +./install_jtop_torun_without_sudo.sh +``` +See the full guide: [How it works & why](docs/nosudo.rst) + +``` _Don't forget to **logout/login** or **reboot** your board_
diff --git a/docs/nosudo.rst b/docs/nosudo.rst new file mode 100644 index 00000000..3deb5386 --- /dev/null +++ b/docs/nosudo.rst @@ -0,0 +1,53 @@ +🧩 How it works +=============== + +The ``install_jtop_torun_without_sudo.sh`` script automates a safe, +user-friendly installation of **jtop** that allows you to run it without +``sudo``. It performs the following steps: + +1. **Safety check** + + - Refuses to run if invoked as ``root`` or via ``sudo``. + - Instructs you to run ``sudo -v`` first so that later privileged + commands (``apt``, ``systemctl``) can execute without repeated password prompts. + +2. **Prepare environment** + + - Verifies whether ``pip3`` and ``pipx`` are installed; if either is missing, installs them via ``apt``. + - Ensures ``~/.local/bin`` is on your ``PATH`` so that ``pipx`` applications are available in future shells. + +3. **Install jtop via pipx** + + - Uses ``pipx install "git+https://github.com/rbonghi/jetson_stats.git"`` to install the latest version in an isolated user environment. + - Determines the correct executable path (usually ``~/.local/bin/jtop`` or inside the pipx venv). + +4. **Systemd service setup** + + - Creates or updates ``/etc/systemd/system/jtop.service`` to point to your user’s jtop binary. + - Sets safe defaults (``Restart=on-failure``, ``RestartSec=10s``, etc.) to make the service robust. + +5. **Enable and start the service** + + - Reloads systemd, enables ``jtop.service`` to start automatically at boot, + and restarts it immediately. + +6. **Result** + + After installation, you can simply launch jtop from your terminal + as a normal user (no ``sudo`` required): + + .. code-block:: bash + + jtop + + +Why use this method +=================== + +.. code-block:: text + + • Keeps the system (root) Python environment clean and untouched + • Uses pipx’s isolation, making upgrades and uninstalls clean and safe + • Fully compatible with Ubuntu 24.04+ and later Debian-based systems + • Ensures jtop runs under your user account (avoids root-owned processes) + • Provides systemd integration for automatic startup and recovery diff --git a/install_jtop_torun_without_sudo.sh b/install_jtop_torun_without_sudo.sh new file mode 100755 index 00000000..c1be13c8 --- /dev/null +++ b/install_jtop_torun_without_sudo.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +set -euo pipefail + +PKG_NAME="jetson_stats" +APP_NAME="jtop" +SYSTEMD_UNIT="jtop.service" + +if [[ $EUID -eq 0 ]]; then + echo "Please first run 'sudo -v'" + echo "Then run this script by itself, NOT with sudo" + exit 1 +fi + +echo "Ensuring pip3 & pipx exist" + +need_update=0 +to_install=() + +if ! command -v pip3 >/dev/null 2>&1; then + to_install+=("python3-pip") + need_update=1 +fi + +if ! command -v pipx >/dev/null 2>&1; then + to_install+=("pipx") + need_update=1 +fi + +if (( need_update )); then + echo "Missing: ${to_install[*]} → installing via apt" + sudo apt-get update + sudo apt-get install -y "${to_install[@]}" +else + echo "pip3 and pipx already installed." +fi + +# Make sure future shells have ~/.local/bin in PATH (no-op if already set) +pipx ensurepath || true + +echo "Installing ${APP_NAME} with pipx" + pipx install "git+https://github.com/rbonghi/jetson_stats.git" + +JTOP_BIN="$HOME/.local/bin/${APP_NAME}" +[ -x "$JTOP_BIN" ] || JTOP_BIN="$HOME/.local/share/pipx/venvs/${PKG_NAME}/bin/${APP_NAME}" + +echo "Ensuring a systemd unit exists and points to ${JTOP_BIN}" +UNIT_FILE="/etc/systemd/system/${SYSTEMD_UNIT}" +if [ ! -f "${UNIT_FILE}" ]; then + # Create a minimal unit if repo didn't install one + echo "Creating ${UNIT_FILE}…" + sudo tee "${UNIT_FILE}" >/dev/null <