mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
Generating nginx certs on first startup.
This commit is contained in:
parent
4823a63773
commit
f375e4c955
5 changed files with 38 additions and 7 deletions
|
|
@ -60,6 +60,9 @@ echo "Controller pre-installed"
|
|||
# Configure nginx.
|
||||
cp /opt/wrolpi/etc/raspberrypios/nginx.conf /etc/nginx/nginx.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/50x.html /var/www/50x.html
|
||||
# Copy wrolpi.conf which defines the location blocks for reverse proxy.
|
||||
[ -f /etc/nginx/conf.d/default.conf ] && rm /etc/nginx/conf.d/default.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi.conf /etc/nginx/conf.d/wrolpi.conf
|
||||
|
||||
# WROLPi needs a few privileged commands.
|
||||
cp /opt/wrolpi/etc/raspberrypios/90-wrolpi /etc/sudoers.d/90-wrolpi
|
||||
|
|
@ -98,6 +101,8 @@ systemctl enable NetworkManager
|
|||
|
||||
# Enable iperf3 for speed testing.
|
||||
systemctl enable iperf3
|
||||
# Enable first startup script to generate certificates and start nginx.
|
||||
systemctl enable wrolpi-first-startup.service
|
||||
# Enable Controller service to start on boot.
|
||||
systemctl enable wrolpi-controller.service
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ chown -R wrolpi:wrolpi /opt/wrolpi
|
|||
# Configure nginx.
|
||||
cp /opt/wrolpi/etc/raspberrypios/nginx.conf /etc/nginx/nginx.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/50x.html /var/www/50x.html
|
||||
# Copy wrolpi.conf which defines the location blocks for reverse proxy.
|
||||
[ -f /etc/nginx/conf.d/default.conf ] && rm /etc/nginx/conf.d/default.conf
|
||||
cp /opt/wrolpi/etc/raspberrypios/wrolpi.conf /etc/nginx/conf.d/wrolpi.conf
|
||||
|
||||
# WROLPi needs a few privileged commands.
|
||||
cp /opt/wrolpi/etc/raspberrypios/90-wrolpi /etc/sudoers.d/90-wrolpi
|
||||
|
|
|
|||
|
|
@ -46,12 +46,7 @@ cp /opt/wrolpi/etc/raspberrypios/wrolpi.conf /etc/nginx/conf.d/wrolpi.conf
|
|||
cp /opt/wrolpi/etc/raspberrypios/50x.html /var/www/50x.html
|
||||
|
||||
# Generate nginx certificate for HTTPS.
|
||||
if [[ ! -f /etc/nginx/cert.crt || ! -f /etc/nginx/cert.key ]]; then
|
||||
openssl genrsa -out /etc/nginx/cert.key 2048
|
||||
openssl req -new -x509 -nodes -key /etc/nginx/cert.key -out /etc/nginx/cert.crt -days 3650 \
|
||||
-subj "/C=US/ST=State/L=City/O=Org/OU=WROLPi/CN=$(hostname).local"
|
||||
chmod 640 /etc/nginx/cert.key /etc/nginx/cert.crt
|
||||
fi
|
||||
/opt/wrolpi/scripts/generate_certificates.sh
|
||||
|
||||
# Start nginx quickly so user can access Controller from React UI
|
||||
systemctl start nginx || :
|
||||
|
|
|
|||
19
scripts/generate_certificates.sh
Executable file
19
scripts/generate_certificates.sh
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env bash
|
||||
# Generate self-signed SSL certificates for nginx if they don't exist.
|
||||
|
||||
set -e
|
||||
|
||||
CERT_FILE="/etc/nginx/cert.crt"
|
||||
KEY_FILE="/etc/nginx/cert.key"
|
||||
|
||||
if [[ -f "${CERT_FILE}" && -f "${KEY_FILE}" ]]; then
|
||||
echo "Certificates already exist at ${CERT_FILE} and ${KEY_FILE}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Generating nginx certificates..."
|
||||
openssl genrsa -out "${KEY_FILE}" 2048
|
||||
openssl req -new -x509 -nodes -key "${KEY_FILE}" -out "${CERT_FILE}" -days 3650 \
|
||||
-subj "/C=US/ST=State/L=City/O=Org/OU=WROLPi/CN=$(hostname).local"
|
||||
chmod 640 "${KEY_FILE}" "${CERT_FILE}"
|
||||
echo "Certificates generated successfully."
|
||||
|
|
@ -1,5 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
# This script is run once on the first startup of a Raspberry Pi.
|
||||
# This script is run once on the first startup of a Raspberry Pi or Debian Live.
|
||||
|
||||
set -x
|
||||
|
||||
# Generate nginx certificate for HTTPS if it doesn't exist.
|
||||
/opt/wrolpi/scripts/generate_certificates.sh
|
||||
|
||||
# Enable and start nginx now that certificates exist.
|
||||
systemctl enable nginx
|
||||
systemctl start nginx || echo "Warning: nginx failed to start"
|
||||
|
||||
# Copy skeleton files to first users home directory.
|
||||
USER_HOME=$(getent passwd 1000 | cut -d: -f6)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue