# Dell OptiPlex CasaOS NAS Bootstrap

This package contains a friendly **interactive Bash setup wizard** for turning a fresh **Debian headless/minimal** install into a simple CasaOS NAS.

Primary script:

```text
bootstrap_casaos_nas.sh
```

A Python version is also included as an older/backup variant, but the shell script is now the recommended one.

## Recommended hardware layout

```text
Small SSD/HDD       -> Debian + CasaOS OS drive
Separate media HDDs -> storage only, mounted later under /mnt
Ethernet            -> router/switch
```

During Debian installation, safest option is to **disconnect the media drives** so only the OS drive can be selected/wiped.

## Debian installer choices

When Debian asks for software selection, choose:

```text
[✓] SSH server
[✓] standard system utilities
```

Do not select:

```text
[ ] Debian desktop environment
[ ] GNOME
[ ] KDE
[ ] XFCE
[ ] print server
```

## Run the wizard

After Debian boots, copy the shell script to the Dell NAS:

```bash
scp bootstrap_casaos_nas.sh youruser@NAS-IP:~/
```

SSH in:

```bash
ssh youruser@NAS-IP
```

Run:

```bash
sudo bash bootstrap_casaos_nas.sh
```

The script will show a friendly checklist where selected items appear as `[x]`.

## Interactive checklist options

The wizard lets you toggle:

```text
[x] CasaOS
[x] Tailscale
[x] OpenSSH server
[x] Samba / SMB
[x] Cockpit
[x] UFW firewall baseline
[x] Fail2ban
[x] unattended security upgrades
[x] Avahi .local discovery
[x] SMART/disk/admin tools
```

All are selected by default because this is the recommended NAS baseline.

## Identity prompts

The wizard asks for:

```text
Hostname for this NAS [dell-nas]
Existing Debian admin username [auto-detected user]
```

The admin user must already exist. Create it during Debian installation.

## Mount/share/fstab workflow

The wizard can create reliable cold-boot mounts and Samba shares.

It will:

1. show detected disks/filesystems with:

   ```bash
   lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,UUID,MOUNTPOINTS
   ```

2. ask for an existing filesystem UUID,
3. ask for a mountpoint such as:

   ```text
   /mnt/media_primary
   /mnt/media_backup
   ```

4. ask for a Samba share name,
5. write a managed `/etc/fstab` block using UUIDs,
6. run:

   ```bash
   systemctl daemon-reload
   mount -a
   findmnt <mountpoint>
   ```

7. write matching Samba shares.

### Safety rule

The wizard does **not** format, partition, wipe, or erase drives.

It only mounts filesystems that already exist and have UUIDs. It also refuses the detected OS/root filesystem as a media share.

## What it installs/configures

Depending on your checklist choices:

- CasaOS
- Tailscale
- OpenSSH server
- Samba / SMB
- Cockpit web admin panel
- UFW firewall baseline
- Fail2ban
- unattended security upgrades
- Avahi `.local` discovery
- SMART/disk/admin tools: `smartmontools`, `hdparm`, `nvme-cli`, filesystem utilities
- useful admin tools: `rsync`, `htop`, `tmux`, `jq`, `nmap`, etc.

## After it finishes

### 1. Authenticate Tailscale

```bash
sudo tailscale up --ssh
```

If you do not want Tailscale SSH:

```bash
sudo tailscale up
```

### 2. Set your Samba password

```bash
sudo smbpasswd -a youruser
```

This is the username/password you use from Windows/macOS/Linux to access SMB shares.

### 3. Reboot once

```bash
sudo reboot
```

### 4. Verify after reboot

The wizard writes this helper:

```bash
sudo /usr/local/sbin/heph-nas-verify-after-reboot
```

It checks:

- SSH
- Samba
- Tailscale
- CasaOS gateway
- Cockpit
- Avahi
- Fail2ban
- `/mnt` mounts
- Samba share definitions
- listening ports

## URLs after setup

CasaOS:

```text
http://dell-nas.local/
```

or:

```text
http://NAS-IP/
```

Cockpit, optional:

```text
https://dell-nas.local:9090/
```

Your browser may warn about the self-signed certificate. That is normal for Cockpit unless you add a trusted certificate later.

## SMB paths

If you create a share called `media_primary`, access it as:

Windows:

```text
\\dell-nas\media_primary
```

macOS/Linux file manager:

```text
smb://dell-nas.local/media_primary
```

## Non-interactive options

You can still use command flags if needed:

```bash
sudo bash bootstrap_casaos_nas.sh --help
```

Useful examples:

```bash
sudo bash bootstrap_casaos_nas.sh --no-mount-shares
sudo bash bootstrap_casaos_nas.sh --skip-cockpit
sudo bash bootstrap_casaos_nas.sh --skip-firewall
sudo bash bootstrap_casaos_nas.sh --dry-run
```

For most cases, just run:

```bash
sudo bash bootstrap_casaos_nas.sh
```

## Backups and logs

The script backs up key edited configs to:

```text
/root/hephaestus-nas-bootstrap-backups/
```

Main log file:

```text
/var/log/hephaestus-nas-bootstrap/bootstrap.log
```

Managed config blocks:

```text
/etc/fstab       -> BEGIN/END HEPHAESTUS MANAGED NAS MOUNTS
/etc/samba/smb.conf -> BEGIN/END HEPHAESTUS MANAGED NAS SHARES
```

## Later improvements worth adding

Not essential on day one, but useful:

1. SMART email/dashboard alerts for failing disks.
2. Non-destructive backup/sync from primary media to backup disk.
3. UPS support if the NAS will be always-on.
4. Static DHCP reservation on the router so the NAS keeps the same LAN IP.
5. Jellyfin/Navidrome through CasaOS if you want media serving.
6. Tailscale-only remote access, not public port forwarding.
