2024-06-18 16:17:54 -06:00
|
|
|
#!/usr/bin/env bash
|
2026-02-24 17:14:56 -07:00
|
|
|
# This script is run once on the first startup of a Raspberry Pi or Debian Live.
|
|
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
2026-03-22 13:19:57 -06:00
|
|
|
mkdir -p /etc/caddy /etc/ssl/wrolpi
|
|
|
|
|
|
|
|
|
|
if [ -f /media/wrolpi/config/ssl/ca.crt ]; then
|
|
|
|
|
# Persistent CA exists (drive mounted with previous install).
|
|
|
|
|
# Generate a fresh leaf cert from the existing CA and use the full Caddyfile.
|
|
|
|
|
echo "Persistent CA found, generating leaf cert and using full Caddyfile"
|
|
|
|
|
/opt/wrolpi/scripts/generate_certificates.sh
|
Replace nginx with Caddy for TLS termination and reverse proxying.
- Replace nginx with Caddy as the web server for both Docker and native
(RPi/Debian) deployments. Caddy handles HTTPS termination, reverse
proxying to all services (API, React app, Controller, Kiwix, Help, Map),
and serves the media/download file browsers.
- Generate a Root CA and signed leaf certificates for HTTPS. The Root CA
uses Name Constraints to restrict signing to local addresses only
(.local, localhost, and RFC 1918 private IP ranges), mitigating MITM
risk if the CA key is compromised.
- Add an HTTP landing page that guides users through one-time CA
certificate installation on iOS, Android, macOS, Windows, Linux, and
Firefox, with auto-redirect when the cert is already trusted.
- Add trailing-slash redirects for /controller, /docs, /media, and
/download so bare paths don't fall through to the React catch-all.
- Add a Root CA download link on the Settings page under Configs.
- Update help.sh diagnostics for IPv6 listener detection and HTTP/2
status codes.
- Remove all nginx config files and the https_proxy Docker container.
- Bump wrolpi-help submodule with certificate documentation.
2026-03-07 12:08:27 -07:00
|
|
|
cp /opt/wrolpi/etc/raspberrypios/Caddyfile /etc/caddy/Caddyfile
|
2026-03-22 13:19:57 -06:00
|
|
|
else
|
|
|
|
|
# No persistent CA (fresh install, no drive, or empty drive).
|
|
|
|
|
# Generate a throwaway self-signed cert directly into /etc/ssl/wrolpi/
|
|
|
|
|
# so Caddy can listen on :443. Never writes to /media/wrolpi/.
|
|
|
|
|
echo "No persistent CA, generating temporary cert for onboarding"
|
|
|
|
|
openssl req -x509 -newkey rsa:2048 -nodes \
|
|
|
|
|
-keyout /etc/ssl/wrolpi/cert.key \
|
|
|
|
|
-out /etc/ssl/wrolpi/cert.crt \
|
|
|
|
|
-days 1 -subj "/CN=wrolpi-onboarding"
|
|
|
|
|
chmod 640 /etc/ssl/wrolpi/cert.key /etc/ssl/wrolpi/cert.crt
|
|
|
|
|
if id caddy >/dev/null 2>&1; then
|
|
|
|
|
chown root:caddy /etc/ssl/wrolpi/cert.key /etc/ssl/wrolpi/cert.crt
|
|
|
|
|
fi
|
|
|
|
|
cp /opt/wrolpi/etc/raspberrypios/Caddyfile.onboarding /etc/caddy/Caddyfile
|
2026-02-26 17:38:36 -07:00
|
|
|
fi
|
|
|
|
|
|
Replace nginx with Caddy for TLS termination and reverse proxying.
- Replace nginx with Caddy as the web server for both Docker and native
(RPi/Debian) deployments. Caddy handles HTTPS termination, reverse
proxying to all services (API, React app, Controller, Kiwix, Help, Map),
and serves the media/download file browsers.
- Generate a Root CA and signed leaf certificates for HTTPS. The Root CA
uses Name Constraints to restrict signing to local addresses only
(.local, localhost, and RFC 1918 private IP ranges), mitigating MITM
risk if the CA key is compromised.
- Add an HTTP landing page that guides users through one-time CA
certificate installation on iOS, Android, macOS, Windows, Linux, and
Firefox, with auto-redirect when the cert is already trusted.
- Add trailing-slash redirects for /controller, /docs, /media, and
/download so bare paths don't fall through to the React catch-all.
- Add a Root CA download link on the Settings page under Configs.
- Update help.sh diagnostics for IPv6 listener detection and HTTP/2
status codes.
- Remove all nginx config files and the https_proxy Docker container.
- Bump wrolpi-help submodule with certificate documentation.
2026-03-07 12:08:27 -07:00
|
|
|
# Enable and start Caddy now that certificates exist.
|
|
|
|
|
systemctl enable caddy
|
|
|
|
|
systemctl start caddy || echo "Warning: caddy failed to start"
|
2024-06-18 16:17:54 -06:00
|
|
|
|
|
|
|
|
# Copy skeleton files to first users home directory.
|
|
|
|
|
USER_HOME=$(getent passwd 1000 | cut -d: -f6)
|
|
|
|
|
if [ "$(ls -A /etc/skel)" ]; then
|
|
|
|
|
echo "Files found in /etc/skel, copying to $USER_HOME..."
|
|
|
|
|
# Copy files from /etc/skel to the user's home directory
|
|
|
|
|
cp -r /etc/skel/. "$USER_HOME"
|
|
|
|
|
# Change ownership to the user with UID 1000
|
|
|
|
|
chown -R 1000:1000 "$USER_HOME"
|
|
|
|
|
echo "Files copied successfully."
|
|
|
|
|
else
|
|
|
|
|
echo "No files found in /etc/skel."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2025-03-13 15:06:49 -06:00
|
|
|
# Add the user created on startup to the wrolpi group.
|
|
|
|
|
USER_NAME=$(getent passwd 1000 | cut -d: -f1)
|
|
|
|
|
grep wrolpi: /etc/passwd || useradd -md /home/wrolpi wrolpi -s "$(command -v bash)"
|
|
|
|
|
usermod -aG wrolpi ${USER_NAME}
|
2025-03-21 21:05:09 -06:00
|
|
|
usermod -aG sudo ${USER_NAME}
|
2025-03-13 15:06:49 -06:00
|
|
|
|
2024-06-18 16:17:54 -06:00
|
|
|
# Do not run this script again.
|
|
|
|
|
systemctl disable wrolpi-first-startup.service
|