Metadata-Version: 2.4
Name: eznfs
Version: 1.0.0
Summary: Safely manage Linux NFS entries in /etc/fstab
Author-email: markmental <marky611@gmail.com>
License-Expression: MIT
Project-URL: Source, https://github.com/MARKMENTAL/eznfs
Keywords: nfs,fstab,linux,mount,sysadmin
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: System :: Filesystems
Classifier: Topic :: Terminals
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rich==15.0.0
Provides-Extra: build
Requires-Dist: pyinstaller==6.22.3; extra == "build"
Provides-Extra: publish
Requires-Dist: build==1.6.1; extra == "publish"
Requires-Dist: twine==7.0.0; extra == "publish"
Dynamic: license-file

# eznfs

`eznfs` is a Python 3 CLI and interactive wizard for safely adding, editing, listing, and removing Linux NFS shares in `/etc/fstab`. Its terminal interface uses Rich 15.0.0 for panels, tables, syntax highlighting, prompts, and progress displays.

It creates the local mount point, writes a backed-up and atomically updated fstab entry, reloads systemd, and mounts the share immediately. The default options are designed so an unavailable NFS server does not fail or indefinitely delay boot.

Source repository: [github.com/MARKMENTAL/eznfs](https://github.com/MARKMENTAL/eznfs)

## Requirements

- Linux with Python 3.10 or newer for source/virtual-environment installs
- Rich 15.0.0 and its dependencies for source installs; bundled in the standalone binary
- An NFS client helper (`mount.nfs`)
- systemd for the preferred mounting path; a bounded `mount` fallback is available on non-systemd hosts

Install the NFS client if necessary:

```bash
# Debian / Ubuntu
sudo apt install nfs-common

# Fedora / RHEL
sudo dnf install nfs-utils
```

`eznfs` does not install packages automatically.

## Install

### From PyPI

After the release is published:

```bash
pipx install eznfs
# or
python3 -m pip install eznfs
```

### From source

Create or activate a virtual environment and install the project in editable mode:

```bash
python3 -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -e .
```

The installer creates an `eznfs` entry point inside the virtual environment:

```bash
.venv/bin/eznfs --help
```

Run privileged commands through the virtual-environment entry point:

```bash
sudo "$PWD/.venv/bin/eznfs"
```

The examples below use `eznfs` for readability. With a virtual environment, substitute `sudo "$PWD/.venv/bin/eznfs"` wherever they show `sudo eznfs`.

Alternatively, invoke the module directly after installing its dependencies:

```bash
.venv/bin/python eznfs.py --help
```

### Terminal appearance

Rich formatting is used for all command output when attached to a terminal. eznfs automatically selects a light or dark palette from `COLORFGBG` when available and falls back to the dark palette otherwise. Light terminals use darker amber, green, red, magenta, and cyan variants for contrast, along with light-background syntax highlighting.

Override the palette explicitly when needed:

```bash
EZNFS_COLOR_THEME=light eznfs list
EZNFS_COLOR_THEME=dark eznfs list
EZNFS_COLOR_THEME=auto eznfs list
```

When output is redirected, running in CI, or `TERM=dumb`, eznfs automatically uses plain text without animation. `NO_COLOR` is also respected by Rich; it removes color codes, although Rich may still use bold or dim attributes.

Optional shell aliases can preserve these settings through `sudo`. These examples assume the repository is at `$HOME/eznfs`:

```bash
# Virtual-environment install
alias eznfs-nc='sudo NO_COLOR=1 "$HOME/eznfs/.venv/bin/eznfs"'
alias eznfs-light='sudo EZNFS_COLOR_THEME=light "$HOME/eznfs/.venv/bin/eznfs"'
alias eznfs-dark='sudo EZNFS_COLOR_THEME=dark "$HOME/eznfs/.venv/bin/eznfs"'

# Standalone binary resolved through the current PATH
alias eznfs-nc='sudo NO_COLOR=1 "$(command -v eznfs)"'
alias eznfs-light='sudo EZNFS_COLOR_THEME=light "$(command -v eznfs)"'
alias eznfs-dark='sudo EZNFS_COLOR_THEME=dark "$(command -v eznfs)"'
```

Use the aliases directly because they already include `sudo`:

```bash
eznfs-nc list
eznfs-light list
eznfs-dark list
```

Adjust the repository path as needed. The `light` and `dark` aliases bypass automatic terminal detection, while `command -v eznfs` resolves the standalone binary through your current `PATH` before passing its absolute path to `sudo`.

### Standalone binary

A PyInstaller build bundles Python, Rich, and the application into one executable. The target machine does not need Python or pip, but it still needs the Linux system tools listed under Requirements.

Build on a Linux host:

```bash
python3 -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -e '.[build]'
./build.sh
```

The build uses pinned PyInstaller `6.22.3`, runs unprivileged smoke tests, and produces:

```text
dist/eznfs
dist/release/eznfs-<version>-linux-<arch>.tar.gz
dist/staging/eznfs-<version>-linux-<arch>/build-info.json
```

Run the binary directly:

```bash
./dist/eznfs --help
sudo ./dist/eznfs
```

PyInstaller is not a cross-compiler. The executable is specific to the build host's architecture and glibc version, and it is not static. One-file builds also extract to a temporary directory at startup, which may be restricted on hardened systems.

Generate forge-neutral release notes and checksums after a successful build:

```bash
.venv/bin/python tools/release_notes.py
```

This creates `dist/release/*-RELEASE_NOTES.md` and `dist/release/*-SHA256SUMS.txt`. The tool validates build metadata and refuses to generate notes unless the smoke tests passed. It does not publish releases.

### Publishing to PyPI

Install the pinned publishing tools:

```bash
.venv/bin/python -m pip install -e '.[publish]'
```

Build and validate the sdist and wheel without uploading:

```bash
./publish.sh testpypi --check-only
```

Package artifacts are written to `dist/pypi/`, separate from the standalone binary and release archives. The workflow runs `twine check` and generates SHA-256 checksums automatically.

For an interactive TestPyPI upload, use a TestPyPI API token when prompted:

```bash
./publish.sh testpypi
```

For noninteractive use, provide the token through the environment rather than command-line arguments:

```bash
export TWINE_USERNAME=__token__
read -rsp "API token: " TWINE_PASSWORD
export TWINE_PASSWORD
./publish.sh testpypi --non-interactive
unset TWINE_PASSWORD
```

After testing the TestPyPI install in a clean virtual environment, upload the same validated artifacts to production:

```bash
./publish.sh pypi --skip-build
```

Twine rejects attempts to reuse an existing release version, so finalize the version and metadata before uploading to production. Never commit or print API tokens.

## Interactive wizard

Run without a command:

```bash
sudo eznfs
```

The wizard requires root and checks this before displaying any prompts. If run without `sudo`, it exits immediately with instructions to re-run it as root.

![Interactive eznfs wizard in kitty on KDE Plasma 6](screenshot-wizard.png)

*Interactive wizard in kitty on KDE Plasma 6.*

The wizard asks for:

1. NFS server IP address or hostname
2. Absolute export path on the server
3. Absolute local mount point
4. Filesystem type: automatic, NFSv4, or NFSv3
5. Retry profile: hard or soft
6. Local user for the UID/GID permission check

The server hostname is checked immediately after entry. If it cannot be resolved, the wizard offers to re-enter it, explicitly save it for offline provisioning, or cancel.

When invoked through `sudo`, the wizard defaults to the invoking user from `SUDO_USER`/`SUDO_UID`, not root. It then displays a reminder to verify that the numeric UID/GID match the exported directory on the NFS server.

It then displays the exact fstab entry and offers to apply and mount it, save it without mounting, or cancel.

## CLI usage

### Add and mount a share

```bash
sudo eznfs add \
  --server nas.lan \
  --share /srv/nfs/media \
  --mountpoint /mnt/media
```

This creates `/mnt/media` if needed, saves the entry, reloads systemd, and mounts it immediately. It also prints the UID/GID permission reminder. Use `--user USERNAME` to check a specific local account:

```bash
sudo eznfs add \
  --server nas.lan \
  --share /srv/nfs/media \
  --mountpoint /mnt/media \
  --user mrkmntal
```

### Hostname resolution

Before creating a mount point or writing fstab, eznfs checks hostname resolution through `getent ahosts`. Literal IP addresses skip this check, and the lookup is limited to five seconds.

If a hostname cannot be resolved, eznfs stops without changing fstab and reports the hostname along with typo, `/etc/hosts`, DNS, and connectivity guidance. Use `--allow-unresolved` only when intentionally provisioning a share before its hostname or server is available:

```bash
sudo eznfs add \
  --server offline.lan \
  --share /export/media \
  --mountpoint /mnt/media \
  --allow-unresolved
```

The wizard and `edit` command offer to re-enter the hostname or explicitly save it anyway. A hostname that resolves is still allowed when the NFS service itself is offline.

### NFS UID/GID permission check

NFS permissions use numeric UID/GID values, not just matching usernames. Before relying on a share, verify the exported directory on the server:

```bash
stat -c 'uid=%u gid=%g mode=%a path=%n' /srv/nfs/media
```

Compare those values with the intended local user:

```bash
id mrkmntal
```

With `root_squash`, non-root UID/GID values pass through normally; only client root is mapped to the server's anonymous user. With `all_squash`, the server's `anonuid` and `anongid` settings control the displayed ownership instead. Client-side mount-point ownership or `uid=`/`gid=` options are not a substitute for correct server-side NFS permissions.

### Select NFSv4 and save without mounting

```bash
sudo eznfs add \
  --server 192.168.1.20 \
  --share /export/backups \
  --mountpoint /mnt/backups \
  --type nfs4 \
  --no-mount
```

`--type auto` is the default and is stored as `nfs`, allowing normal NFS version negotiation. Use `--type nfs` for the generic NFS type or `--type nfs4` to request NFSv4 explicitly.

### Preview without root or changes

```bash
eznfs add \
  --server nas.lan \
  --share /srv/nfs/media \
  --mountpoint /mnt/media \
  --dry-run
```

A dry run does not create directories, modify fstab, reload systemd, or mount the server. It may perform the normal hostname-resolution check unless `--allow-unresolved` is supplied.

### List NFS entries

```bash
eznfs list
```

This lists all NFS/NFSv4 entries, their mount state, whether `eznfs` manages them, and TCP latency to port `2049`.

![eznfs list output in kitty on KDE Plasma 6](screenshot-list.png)

*`eznfs list` in kitty on KDE Plasma 6, showing TCP latency.*

By default, each unique server is probed with six TCP connections. The column shows average latency, range, and successful attempts:

```text
13.4 ms (5.1–24.4, 6/6)
```

Latency colors:

| Average TCP latency | Color | Interpretation |
|---|---|---|
| `< 5 ms` | Green | Ideal |
| `5–20 ms` | Yellow | Acceptable |
| `20–100 ms` | Orange | Degraded |
| `≥ 100 ms` | Red | Unusable for interactive NFS work |

Partial failure downgrades the color by one tier and shows the success count. Complete failure displays `unreachable` or `unresolved`.

This is TCP connection latency, not ICMP ping or actual NFS RPC latency. Firewalls, DNS, and TCP backlog limits can affect it.

Skip probes for a fast local listing:

```bash
eznfs list --no-latency
```

Adjust the per-attempt timeout:

```bash
eznfs list --latency-timeout 2.0
```

### Edit a connection source

```bash
sudo eznfs edit
```

The editor requires root before displaying its menu. It lists every NFS/NFSv4 entry in fstab order:

```text
1) /mnt/media
   Source: nas.lan:/srv/nfs/media
   Type: nfs | mounted | eznfs

2) /mnt/backups
   Source: 192.168.1.20:/export/backups
   Type: nfs4 | not mounted | unmanaged

q) Cancel
```

Select a number, enter the replacement `fs_spec`, review the exact old and new fstab lines, and confirm. Hostnames, IPv4 addresses, and bracketed IPv6 addresses are supported.

Only the source field is changed. The mount point, filesystem type, options, dump/pass values, comments, spacing, and eznfs marker are preserved. The update uses the normal fstab lock, timestamped backup, and atomic replacement.

`eznfs edit` always mounts the share after a successful edit. If it was already mounted, it is unmounted first. If the new source cannot be mounted, `eznfs` restores the original fstab source and remounts the old share when it was originally mounted. If the share was originally unmounted, rollback restores its fstab source but leaves it unmounted. Rollback failures are reported explicitly.

### Remove an entry

```bash
sudo eznfs remove /mnt/media
```

Removal asks for confirmation. If the share is mounted, `eznfs` refuses to remove the entry unless `--unmount` is supplied:

```bash
sudo eznfs remove /mnt/media --unmount
```

For scripts and other noninteractive use:

```bash
sudo eznfs remove /mnt/media --unmount --yes
```

Preview a removal without changing anything:

```bash
eznfs remove /mnt/media --unmount --dry-run
```

## Default fstab entry

```fstab
# Managed by eznfs
nas.lan:/srv/nfs/media  /mnt/media  nfs  rw,hard,timeo=600,retrans=2,_netdev,nofail,x-systemd.device-timeout=10s,x-systemd.mount-timeout=15s  0  0
```

Option meanings:

- `rw`: read/write mount.
- `hard`: default retry profile; favors data integrity.
- `timeo=600,retrans=2`: explicit NFS timeout and retry settings.
- `_netdev`: identifies a network-dependent mount.
- `nofail`: an unavailable share does not make boot fail.
- `x-systemd.device-timeout=10s`: limits waiting for the mount device.
- `x-systemd.mount-timeout=15s`: limits the mount operation.

Use `--profile soft` for a profile with `soft,timeo=100,retrans=2` plus the same network and boot-safety options.

### Important safety behavior

`nofail` protects the boot process; it does **not** guarantee that applications never block. A hard-mounted NFS server that disappears after mounting can still cause active I/O to hang. Soft mounts return errors sooner but failed writes can risk data inconsistency.

If the immediate mount fails, `eznfs` leaves the fstab entry in place and exits nonzero. The entry remains protected by `nofail` and the configured timeouts and can be retried later.

## fstab safety

When applying changes, `eznfs`:

- Requires root.
- Refuses duplicate mount-point entries.
- Refuses `/` and protected system trees such as `/boot`, `/etc`, `/proc`, `/run`, `/sys`, and `/dev`.
- Refuses symbolic-link or regular-file mount points.
- Escapes spaces, tabs, and backslashes for fstab.
- Creates missing mount-point directories with mode `0755`; existing directory permissions are not changed.
- Locks fstab against concurrent `eznfs` edits.
- Creates a timestamped backup before writing.
- Atomically replaces fstab while preserving its ownership and mode.

Backups are named like:

```text
/etc/fstab.eznfs-20261128T123456.123456.bak
```

## Tests

Run the unit and CLI tests without root:

```bash
.venv/bin/python -m unittest discover -s tests -v
.venv/bin/python -m py_compile eznfs.py eznfs_ui.py tools/build_dist.py tools/release_notes.py tools/publish_pypi.py tests/test_eznfs.py tests/test_eznfs_ui.py tests/test_release_tools.py tests/test_publish_tools.py
git diff --check
```

The tests use temporary fstab files, mocked mount/systemd operations, in-memory Rich consoles, and temporary release artifacts. They do not modify the real `/etc/fstab`, require root, contact an NFS server, mount shares, or invoke a real PyInstaller build.

## License

eznfs is released under the [MIT License](LICENSE).
