Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(install): stop the bare-metal installer aborting on a fresh host

Pouzorcefb96ddb4c0
diff --git a/INSTALLATION.md b/INSTALLATION.md
index 5ba6f00..2fdcfd6 100644
--- a/INSTALLATION.md
+++ b/INSTALLATION.md
@@ -101,17 +101,22 @@ git clone https://github.com/Pouzor/homelable.git /opt/homelable
sudo bash /opt/homelable/scripts/install-baremetal.sh
```
+It prompts for the admin password and the CIDR range to scan, then writes
+`backend/.env` with a generated `SECRET_KEY` and bcrypt hash. Open
+**http://\<host-ip\>:3000**.
+
The script can also clone for you — run it from anywhere and it fetches the repo
-into `INSTALL_DIR` if that directory is empty:
+into `INSTALL_DIR` when that directory is empty. Piped into `bash` there is no
+terminal to prompt on, so pass the two answers as environment variables:
```bash
curl -fsSL https://raw.githubusercontent.com/Pouzor/homelable/main/scripts/install-baremetal.sh \
- | sudo bash
+ | sudo ADMIN_PASSWORD=hunter2 SCANNER_RANGES='["192.168.1.0/24"]' bash
```
-It prompts for the admin password and the CIDR range to scan, then writes
-`backend/.env` with a generated `SECRET_KEY` and bcrypt hash. Open
-**http://\<host-ip\>:3000**.
+Without them the prompts are skipped and their defaults apply — the password
+becomes `admin` and the range is guessed from the primary interface. The script
+warns when that happens; change the password before exposing the host.
Re-running is safe and is how you upgrade — an existing `backend/.env` is kept
untouched, everything else is rebuilt:
@@ -123,7 +128,8 @@ sudo bash scripts/install-baremetal.sh
### Options
-Every setting is an environment variable, so a non-interactive install is one line:
+Every setting is an environment variable. Setting them all skips every prompt,
+which is what makes an unattended install possible:
```bash
sudo HTTP_PORT=8080 ADMIN_PASSWORD=hunter2 SCANNER_RANGES='["10.0.0.0/24"]' \
@@ -138,8 +144,8 @@ sudo HTTP_PORT=8080 ADMIN_PASSWORD=hunter2 SCANNER_RANGES='["10.0.0.0/24"]' \
| `BACKEND_PORT` | `8000` | uvicorn port, bound to loopback |
| `HTTP_PORT` | `3000` | nginx port |
| `SERVER_NAME` | `_` | nginx `server_name` |
-| `ADMIN_PASSWORD` | prompt (`admin`) | Initial password for user `admin` |
-| `SCANNER_RANGES` | prompt (guessed) | JSON array of CIDRs |
+| `ADMIN_PASSWORD` | prompt, else `admin` | Initial password for user `admin` |
+| `SCANNER_RANGES` | prompt, else guessed | JSON array of CIDRs |
| `SKIP_NGINX=1` | off | Do not install or touch nginx |
### Afterwards
diff --git a/scripts/install-baremetal.sh b/scripts/install-baremetal.sh
index 310f56f..640f8ce 100755
--- a/scripts/install-baremetal.sh
+++ b/scripts/install-baremetal.sh
@@ -22,6 +22,9 @@
# ADMIN_PASSWORD initial admin password (default: prompt, "admin" on empty)
# SCANNER_RANGES JSON array of CIDRs to scan (default: prompt, guessed from
# the primary interface)
+#
+# The two prompts are skipped when stdin is not a TTY (`curl … | sudo bash`);
+# set the matching variables to control them there, or take the defaults.
# SKIP_NGINX=1 do not install or touch nginx (bring your own reverse proxy)
set -euo pipefail
@@ -54,9 +57,15 @@ if [[ "$SKIP_NGINX" != "1" ]]; then
fi
# Node 20+ — Debian 12 ships 18, too old for Vite 7 / React 19.
-node_major="$(node --version 2>/dev/null | sed 's/^v\([0-9]*\).*/\1/')"
-if [[ -z "$node_major" || "$node_major" -lt "$NODE_MAJOR" ]]; then
- log "Installing Node.js $NODE_MAJOR (found: ${node_major:-none})"
+# `|| true`: with no node installed the substitution exits 127, and under
+# `set -euo pipefail` that aborts the script before we get to install it.
+node_major="$(node --version 2>/dev/null | sed 's/^v\([0-9]*\).*/\1/' || true)"
+node_major="${node_major//[^0-9]/}" # `-lt` errors on anything non-numeric
+node_major="${node_major:-0}"
+if [[ "$node_major" -lt "$NODE_MAJOR" ]]; then
+ found="$node_major"
+ if [[ "$found" == "0" ]]; then found="none"; fi
+ log "Installing Node.js $NODE_MAJOR (found: $found)"
curl -fsSL "https://deb.nodesource.com/setup_${NODE_MAJOR}.x" | bash - >/dev/null
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq nodejs >/dev/null
fi
@@ -104,7 +113,11 @@ else
admin_password="${ADMIN_PASSWORD:-}"
if [[ -z "$admin_password" ]]; then
- read -rsp "Initial admin password [default: admin]: " admin_password; echo
+ if [[ -t 0 ]]; then
+ read -rsp "Initial admin password [default: admin]: " admin_password; echo
+ else
+ warn "No TTY (piped install) and ADMIN_PASSWORD unset — defaulting to 'admin'."
+ fi
admin_password="${admin_password:-admin}"
fi
@@ -112,9 +125,13 @@ else
if [[ -z "$scanner_ranges" ]]; then
guess="$(ip -o -f inet addr show scope global 2>/dev/null \
| awk '{print $4}' | head -n1 \
- | awk -F/ '{split($1,o,"."); print o[1]"."o[2]"."o[3]".0/"$2}')"
+ | awk -F/ '{split($1,o,"."); print o[1]"."o[2]"."o[3]".0/"$2}' || true)"
guess="${guess:-192.168.1.0/24}"
- read -rp "CIDR range to scan [$guess]: " scanner_ranges
+ if [[ -t 0 ]]; then
+ read -rp "CIDR range to scan [$guess]: " scanner_ranges
+ else
+ warn "No TTY (piped install) and SCANNER_RANGES unset — defaulting to $guess."
+ fi
scanner_ranges="[\"${scanner_ranges:-$guess}\"]"
fi
@@ -123,9 +140,11 @@ else
password_hash="$(HL_PW="$admin_password" "$VENV/bin/python" -c \
'import os, bcrypt; print(bcrypt.hashpw(os.environ["HL_PW"].encode(), bcrypt.gensalt()).decode())')"
- host_ip="$(hostname -I 2>/dev/null | awk '{print $1}')"
+ host_ip="$(hostname -I 2>/dev/null | awk '{print $1}' || true)"
origins="[\"http://localhost:${HTTP_PORT}\""
- [[ -n "$host_ip" ]] && origins="${origins},\"http://${host_ip}:${HTTP_PORT}\""
+ if [[ -n "$host_ip" ]]; then
+ origins="${origins},\"http://${host_ip}:${HTTP_PORT}\""
+ fi
origins="${origins}]"
umask 077
@@ -263,7 +282,7 @@ else
log "Backend is up."
fi
-HOST_IP="$(hostname -I 2>/dev/null | awk '{print $1}')"
+HOST_IP="$(hostname -I 2>/dev/null | awk '{print $1}' || true)"
cat <<EOF