refactor: streamline Nightscout installation using a release helper, simplify the default environment file

This commit is contained in:
Francesco Vattiato 2026-01-18 06:34:50 +01:00
parent 61400266fc
commit ba78a10250

View File

@ -20,36 +20,25 @@ MONGO_VERSION="8.0" setup_mongodb
NODE_VERSION="22" setup_nodejs NODE_VERSION="22" setup_nodejs
msg_info "Installing Nightscout (Patience)" msg_info "Installing Nightscout (Patience)"
cd /opt fetch_and_deploy_gh_release "nightscout" "nightscout/cgm-remote-monitor" "source"
git clone https://github.com/nightscout/cgm-remote-monitor.git nightscout $STD npm install --prefix /opt/nightscout
cd nightscout
$STD npm install
msg_ok "Installed Nightscout" msg_ok "Installed Nightscout"
msg_info "Creating Service" msg_info "Creating Service"
useradd -s /bin/bash -m nightscout useradd -s /bin/bash -m nightscout
chown -R nightscout:nightscout /opt/nightscout chown -R nightscout:nightscout /opt/nightscout
# Create a default my.env file if it doesn't exist, to prevent crash on start if user doesn't configure it immediately? cat > /opt/nightscout/my.env <<EOF
# Nightscout needs env vars to run. We will create a template.
cat <<EOF > /opt/nightscout/my.env
# DB connection string.
# MongoDB is installed locally on port 27017.
# You should create a DB and user in Mongo, or trust localhost auth.
# For simplicity in this script we assume localhost with no auth for local binding or the user must configure it.
# However, the installation guide recommends creating a user.
# For now, we point to localhost test DB.
MONGO_CONNECTION=mongodb://127.0.0.1:27017/nightscout MONGO_CONNECTION=mongodb://127.0.0.1:27017/nightscout
BASE_URL=http://localhost:1337 BASE_URL=http://localhost:1337
API_SECRET=yoursecret123 API_SECRET=yoursecret123
DISPLAY_UNITS=mg/dl DISPLAY_UNITS=mg/dl
ENABLE=careportal boluscalc food bwp cage sage iage iob cob basal ar2 rawbg pushover bgi pump openaps pvb linear custom ENABLE=careportal boluscalc food bwp cage sage iage iob cob basal ar2 rawbg pushover bgi pump openaps pvb linear custom
# Allow HTTP (avoids redirect loops with reverse proxies)
INSECURE_USE_HTTP=true INSECURE_USE_HTTP=true
EOF EOF
chown nightscout:nightscout /opt/nightscout/my.env chown nightscout:nightscout /opt/nightscout/my.env
cat <<EOF >/etc/systemd/system/nightscout.service cat > /etc/systemd/system/nightscout.service <<EOF
[Unit] [Unit]
Description=Nightscout CGM Service Description=Nightscout CGM Service
After=network.target mongodb.service After=network.target mongodb.service
@ -60,7 +49,6 @@ User=nightscout
WorkingDirectory=/opt/nightscout WorkingDirectory=/opt/nightscout
EnvironmentFile=/opt/nightscout/my.env EnvironmentFile=/opt/nightscout/my.env
ExecStart=/usr/bin/npm start ExecStart=/usr/bin/npm start
ExecStart=/usr/bin/npm start
Restart=always Restart=always
[Install] [Install]