# Deploying to a device (SSH / first-time setup)

## Update device (deploy script)

From your **local machine** (with the repo and SSH access to the device):

```bash
# Default device: root@10.130.60.121
./scripts/deploy.sh

# Or specify target
./scripts/deploy.sh root@192.168.1.100

# Or use env
TARGET=root@10.130.60.121 ./scripts/deploy.sh
```

The script:
1. Copies `etc/`, `scripts/`, `web/`, and `configure_fm350_5g.sh` to the device at `/tmp/Alpine_5G/`
2. Runs `./scripts/install.sh` on the device (installs/updates scripts, services, Web GUI)
3. Restarts `5g-router` and `5g-webgui` so changes take effect

Ensure SSH key or password auth works to the target before running.

---

## First-time SSH access

### 1. Get the device on the network

- Connect the device via Ethernet (eth0) so it gets an IP (DHCP) or set a static IP during Alpine setup.
- Note the device IP (e.g. from your router’s DHCP list or Alpine’s console).

### 2. SSH key-based login (recommended)

On your **local machine** (not the device):

```bash
# Generate a key if you don’t have one
ssh-keygen -t ed25519 -C "your@email" -f ~/.ssh/alpine_5g -N ""

# Copy the public key to the device (replace IP and user)
ssh-copy-id -i ~/.ssh/alpine_5g.pub root@10.130.60.121
```

Then connect with the key:

```bash
ssh -i ~/.ssh/alpine_5g root@10.130.60.121
```

To avoid specifying the key each time, add to `~/.ssh/config`:

```
Host alpine-5g
    HostName 10.130.60.121
    User root
    IdentityFile ~/.ssh/alpine_5g
```

Then: `ssh alpine-5g`.

### 3. Password login

If you prefer password auth:

```bash
ssh root@10.130.60.121
```

You’ll be prompted for the root password. Key-based auth is still recommended for scripts and automation.

### 4. Deploy the repo to the device

From your **local machine** (repo on your laptop):

```bash
# Copy entire repo
scp -r /path/to/Alpine_5G root@10.130.60.121:/tmp/

# Then on the device (SSH in and run):
ssh root@10.130.60.121 "cd /tmp/Alpine_5G && chmod +x scripts/install.sh && ./scripts/install.sh"
```

Or clone from git on the device if it has internet:

```bash
ssh root@10.130.60.121
apk add git
git clone https://github.com/YOUR_USER/Alpine_5G.git /tmp/Alpine_5G
cd /tmp/Alpine_5G && ./scripts/install.sh
```

## After deployment

- Edit `/etc/5g-router.conf` on the device if needed (APN, interfaces).
- Start 5G: `service 5g-router start` or `/usr/local/bin/connect-5g.sh`.
- Check status: `/usr/local/bin/status-5g.sh`.
- Health check for monitoring: `/usr/local/bin/healthcheck-5g.sh` (exit 0 = OK, 1 = down).
