setup default to port 80

This commit is contained in:
RNL
2026-03-07 14:31:59 +11:00
parent c1686f6bad
commit bbe123c45d
3 changed files with 57 additions and 54 deletions

View File

@@ -24,11 +24,7 @@ It runs quietly in the background 24/7, capturing every print, filament change,
- [Native Setup (Recommended for Raspberry Pi)](#native-setup-recommended-for-raspberry-pi) - [Native Setup (Recommended for Raspberry Pi)](#native-setup-recommended-for-raspberry-pi)
- [What You'll Need](#what-youll-need) - [What You'll Need](#what-youll-need)
- [Step 1: Clone and run setup.sh](#step-1-clone-and-run-setupsh) - [Clone and run setup.sh](#clone-and-run-setupsh)
- [Step 2: Credentials and .env](#step-2-credentials-and-env)
- [Step 3: Bambu Cloud authentication](#step-3-bambu-cloud-authentication)
- [Step 4: Dashboard login](#step-4-dashboard-login)
- [Step 5: Services start automatically](#step-5-services-start-automatically)
- [Managing Bambu-Run](#managing-bambu-run) - [Managing Bambu-Run](#managing-bambu-run)
- [Troubleshooting (Native)](#troubleshooting-native) - [Troubleshooting (Native)](#troubleshooting-native)
- [Docker Setup](#docker-setup) - [Docker Setup](#docker-setup)
@@ -42,11 +38,11 @@ No Docker required. Works on any Raspberry Pi (including 32-bit Pi Model B) runn
### What You'll Need ### What You'll Need
- Raspberry Pi on your local network (Python 3.10+ — ships with Raspberry Pi OS Bookworm by default) - Raspberry Pi on your local network (Python 3.10+)
- Bambu Lab printer on the **same local network** - Bambu Lab printer
- Bambu Lab account **email and password** - Bambu Lab account **email and password**
### Step 1: Clone and run setup.sh ### Clone and run setup.sh
```bash ```bash
git clone https://github.com/RunLit/Bambu-Run.git git clone https://github.com/RunLit/Bambu-Run.git
@@ -54,57 +50,28 @@ cd Bambu-Run
bash setup.sh bash setup.sh
``` ```
The script is fully interactive and idempotent (safe to re-run). It: That's it! The script handles everything interactively, just answer the prompts. When it finishes, open `http://<ip>` from any device on same network.
1. Checks Python >= 3.10 and installs `python3-venv` if missing The script is safe to re-run at any time.
2. Creates `.venv`, stubs opencv to avoid slow ARM compilation, and runs `pip install ".[standalone]"`
3. Prompts for credentials and auto-generates `DJANGO_SECRET_KEY` — writes `.env`
4. Runs `manage.py migrate`
5. Runs `bambu_collector --once` for Bambu Cloud email verification (see Step 3)
6. Runs `manage.py createsuperuser` for your dashboard login
7. Runs `collectstatic`
8. Optionally imports the bundled Bambu filament color catalog
9. Writes and enables `systemd` user services, calls `loginctl enable-linger` so they survive SSH disconnect, and starts them
### Step 2: Credentials and .env ---
If `.env` doesn't exist, the script prompts for: **What the script does**:
| Variable | Description | - **Dependencies**: creates a Python virtual environment, installs all packages
|---|---| - **Credentials**: prompts for your **BambuLab Cloud account** email, password, and timezone; auto-generates a `DJANGO_SECRET_KEY`; writes `.env`
| `BAMBU_USERNAME` | Bambu Lab account email | - **Bambu Cloud auth**: runs `bambu_collector --once`;
| `BAMBU_PASSWORD` | Bambu Lab account password | - Bambu Lab will send a 6-digit code to your email; check you email box and enter it when prompted;
| `TIMEZONE` | e.g. `America/New_York` (default: `UTC`) | - the resulting token is saved to `.env` automatically; future restarts skip this step
- **Dashboard login**: runs `createsuperuser`; choose a username and password for Bambu-Run web UI log in
- **Services**: installs and starts two systemd services (`bambu-run-web` and `bambu-run-collector`), enables linger so they auto-start on boot
- **Port 80**: sets an `iptables` redirect (80 to 8000) so you can reach the dashboard at a plain `http://<pi-ip>` with no port number; persisted via `iptables-persistent` across reboots.
`DJANGO_SECRET_KEY` is auto-generated. To edit later: `nano .env`, then `./native/bambu-run.sh restart`. ---
### Step 3: Bambu Cloud authentication
Bambu Lab requires email verification on first login:
1. The script runs `bambu_collector --once` — a 6-digit code is sent to your email
2. Enter the code when prompted
3. A `BAMBU_TOKEN` is printed — paste it when the script asks, and it's appended to `.env`
Future restarts skip verification automatically. To re-authenticate, remove `BAMBU_TOKEN` from `.env` and re-run the script.
### Step 4: Dashboard login
The script runs `manage.py createsuperuser` — choose a username and password for the web dashboard.
### Step 5: Services start automatically
Two systemd user services are installed and started:
| Service | Role |
|---|---|
| `bambu-run-web` | gunicorn on port 8000 (1 worker <1 GB RAM, 2 workers otherwise) |
| `bambu-run-collector` | MQTT poller, restarts on failure |
Both auto-start on boot via `loginctl enable-linger`. Open `http://<pi-ip>:8000` from any device on your network.
### Managing Bambu-Run ### Managing Bambu-Run
All commands manage Bambu-Run encapsulated in `./native/bambu-run.sh`. Alternatively, you can do it yourself with systemctl commands.
```bash ```bash
./native/bambu-run.sh status # service status ./native/bambu-run.sh status # service status
./native/bambu-run.sh logs # tail live logs (Ctrl+C to stop) ./native/bambu-run.sh logs # tail live logs (Ctrl+C to stop)
@@ -136,6 +103,11 @@ systemctl --user disable bambu-run-web bambu-run-collector
rm ~/.config/systemd/user/bambu-run-{web,collector}.service rm ~/.config/systemd/user/bambu-run-{web,collector}.service
systemctl --user daemon-reload systemctl --user daemon-reload
# Remove port 80 redirect (if it was set)
sudo iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000 2>/dev/null || true
sudo iptables -t nat -D OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8000 2>/dev/null || true
sudo netfilter-persistent save 2>/dev/null || true
# Delete repo — wipes venv, database, and .env # Delete repo — wipes venv, database, and .env
cd ~ cd ~
rm -rf ~/Bambu-Run rm -rf ~/Bambu-Run

View File

@@ -21,4 +21,8 @@ Hex:#AF1685
Silver Silver
Hex:#87909A Hex:#87909A
Black Black
Hex:#000000 Hex:#000000
Mint
Hex:#7AE1BF
Lavender
Hex:#7248BD

View File

@@ -184,15 +184,42 @@ loginctl enable-linger "$USER" 2>/dev/null || \
systemctl --user start bambu-run-web.service bambu-run-collector.service systemctl --user start bambu-run-web.service bambu-run-collector.service
# ── 10. Summary ─────────────────────────────────────────────────────────────── # ── 10. Port 80 redirect (so http://<ip> works without :8000) ────────────────
PORT80_OK=false
if sudo iptables -t nat -C PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000 2>/dev/null; then
yellow "Port 80 → 8000 redirect already set."
PORT80_OK=true
else
if sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8000 && \
sudo iptables -t nat -A OUTPUT -o lo -p tcp --dport 80 -j REDIRECT --to-port 8000; then
green "Port 80 → 8000 redirect configured."
PORT80_OK=true
# Persist so it survives reboot
if ! command -v netfilter-persistent &>/dev/null; then
yellow "Installing iptables-persistent to survive reboots..."
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y -qq iptables-persistent
fi
sudo netfilter-persistent save 2>/dev/null || sudo sh -c 'iptables-save > /etc/iptables/rules.v4'
else
yellow "Warning: Could not set port 80 redirect (sudo required). Access via http://<ip>:8000"
fi
fi
# ── 11. Summary ───────────────────────────────────────────────────────────────
PI_IP=$(hostname -I 2>/dev/null | awk '{print $1}') PI_IP=$(hostname -I 2>/dev/null | awk '{print $1}')
if [ "$PORT80_OK" = true ]; then
DASHBOARD_URL="http://${PI_IP:-localhost}"
else
DASHBOARD_URL="http://${PI_IP:-localhost}:8000"
fi
echo echo
green "============================================" green "============================================"
green " Bambu-Run is running!" green " Bambu-Run is running!"
green "============================================" green "============================================"
echo echo
echo " Dashboard: http://${PI_IP:-localhost}:8000" echo " Dashboard: $DASHBOARD_URL"
echo " Status: systemctl --user status bambu-run-web bambu-run-collector" echo " Status: systemctl --user status bambu-run-web bambu-run-collector"
echo " Logs: journalctl --user -u bambu-run-web -u bambu-run-collector -f" echo " Logs: journalctl --user -u bambu-run-web -u bambu-run-collector -f"
echo " Helper: ./native/bambu-run.sh {start|stop|restart|status|logs|update}" echo " Helper: ./native/bambu-run.sh {start|stop|restart|status|logs|update}"