# CNPERP Local Server Installation

On-premise deployment: one PC runs the ERP for everyone on the LAN. The ZIP contains a **CNPERP** folder. LAN transactions sync to the CNP cloud hub in near real time.

## Extract paths

| OS | Extract ZIP to | Result |
|----|----------------|--------|
| Windows | `C:\` | `C:\CNPERP` |
| Linux | `/opt` | `/opt/CNPERP` |
| macOS | `~` | `~/CNPERP` |

## Customer flow

1. **Download** — [Local Server Install](/install/local) or `GET /api/v1/installer/download/package`
2. **Install** — platform script in `deploy/local-server/`:
   - **Windows:** `Install-CNPERP-Local.ps1` (Administrator)
   - **Linux:** `install-cnperp-local.sh --install-service`
   - **macOS:** `install-cnperp-local.sh`
3. **Start** — desktop shortcut, `start-cnperp-server.sh`, or `systemctl start cnperp-local`
4. **Setup** — `http://localhost:8010/setup` (license + company; cloud mirror auto-provisioned)
5. **Cloud link** — `license_key` in `deploy/license-node.json` → `Connect-Cloud.ps1` or `connect-cloud.sh`

## Prerequisites

| Component | Requirement |
|-----------|-------------|
| OS | Windows 10/11 or Server 2019+ |
| Python | 3.10+ on PATH |
| PostgreSQL | 14+ (installer creates `cnperp_local` / `cnperp_user`) |
| RAM | 4 GB+ recommended |

## Scripts

| File | Purpose |
|------|---------|
| `Install-CNPERP-Local.ps1` | Verify deps, venv, `.env`, DB bootstrap, firewall, shortcuts |
| `Start-CNPERP-Server.ps1` | Run uvicorn on `0.0.0.0:8010` for LAN access |
| `Connect-Cloud.ps1` | Register node + heartbeat after license is configured |
| `local-install.env.template` | Reference for manual `.env` |

Database initialization is handled by `scripts/bootstrap_local_install.py`.

## API (cloud site)

- `GET /install/local` — Installation guide page
- `GET /api/v1/installer/local` — JSON metadata and download URLs
- `GET /api/v1/installer/download/package` — **Full ZIP** (one-click; cached under `dist/`)
- `GET /api/v1/installer/download/{filename}` — Individual installer scripts

## Building a release ZIP

```powershell
.\deploy\local-server\Create-LocalInstallPackage.ps1
```

Produces `dist/cnperp-local-install-<version>.zip` with app code + installer scripts for offline copy to the customer server.

## Parameters (installer)

- `-InstallPath` — Path to repo root (folder containing `app\main.py`)
- `-CloudUrl` — License validation hub (default in script)
- `-Port` — HTTP port (default `8010`)
- `-DbPassword` — PostgreSQL password (auto-generated if omitted)
- `-SkipPythonDeps` / `-SkipDbBootstrap` — For upgrades or re-runs

## In-app updates (local server)

Administrators can update from **Settings → Software Updates** (or **System → Software Updates** in the navbar).

The server runs `deploy/auto_update.ps1` (Windows) or `deploy/auto_update.sh` (Linux): backup → `git pull origin main` → pip → migrations → restart service.

Requirements: git installed, outbound GitHub access, app installed from a git clone (not ZIP-only without `.git`).

## LAN users

After the server is running, other PCs open:

`http://<server-ip>:8010`

They use the same login created during setup; no separate install on client machines.
