#!/bin/bash set -eu mongo_cli="mongo ${MONGODB_HOST}:${MONGODB_PORT}/${MONGODB_DATABASE} -u ${MONGODB_USERNAME} -p ${MONGODB_PASSWORD}" echo "=> Creating directories" mkdir -p /app/data/public/uploads /run/nodebb/logs /run/nodebb/public /run/nodebb/node_modules /run/nodebb/npm /run/nodebb/build export NODE_ENV=production export NODE_PATH=/app/code/node_modules # Some plugins write stuff into node_modules. Not nice :/ echo "=> Moving node_modules" cp -rf /app/code/node_modules_copy/* /run/nodebb/node_modules if [[ -z "$(ls -A /run/nodebb/public)" ]]; then echo "=> Copying public files" cp -rf /app/code/public_template/* /run/nodebb/public # symlink uploads for backup cp -rf /app/code/public_template/uploads/* /app/data/public/uploads rm -rf /run/nodebb/public/uploads ln -sf /app/data/public/uploads /run/nodebb/public/uploads # The public/ contains code that requires with relative links ln -s /app/code/src /run/nodebb/src fi chown -R cloudron:cloudron /app/data /run/nodebb if [[ ! -f /app/data/.setup_done ]]; then echo "=> Running initial setup" setup="{ \"url\": \"${APP_ORIGIN}\", \"admin:username\": \"admin\", \"admin:password\": \"changeme123\", \"admin:password:confirm\": \"changeme123\", \"admin:email\": \"admin@cloudron.io\", \"database\": \"mongo\", \"mongo:host\": \"${MONGODB_HOST}\", \"mongo:port\": \"${MONGODB_PORT}\", \"mongo:username\": \"${MONGODB_USERNAME}\", \"mongo:password\": \"${MONGODB_PASSWORD}\", \"mongo:database\": \"${MONGODB_DATABASE}\" }" # this will create a config.json cd /app/code && /usr/local/bin/gosu cloudron:cloudron node /app/code/app --setup "${setup}" --series touch /app/data/.setup_done fi # load session secret if [[ -f /app/data/secret ]]; then secret=$(cat /app/data/secret) else secret=$(uuid) echo "${secret}" > /app/data/secret fi # Re-create config.json sed -e "s,##APP_ORIGIN,${APP_ORIGIN}," \ -e "s/##MONGODB_HOST/${MONGODB_HOST}/" \ -e "s/##MONGODB_PORT/${MONGODB_PORT}/" \ -e "s/##MONGODB_USERNAME/${MONGODB_USERNAME}/" \ -e "s/##MONGODB_PASSWORD/${MONGODB_PASSWORD}/" \ -e "s/##MONGODB_DATABASE/${MONGODB_DATABASE}/" \ -e "s/##SECRET/${secret}/" \ /app/code/config.json.template > /run/nodebb/config.json echo "=> Checking plugins to be installed" for plugin in $(./nodebb plugins | grep 'nodebb-' | cut -f3 -d' '); do if [[ ! -d "/app/code/node_modules/${plugin}" ]]; then echo "Could not find plugin ${plugin}. Installing it" cd /app/code && /usr/local/bin/gosu cloudron:cloudron npm install "${plugin}" fi done echo "Setting up email" ${mongo_cli} --eval "db.objects.update({ _key: 'config' }, { \$set: { 'email:smtpTransport:enabled': '1', 'email:smtpTransport:service': 'nodebb-custom-smtp', 'email:smtpTransport:host': '${MAIL_SMTP_SERVER}', 'email:smtpTransport:port': '${MAIL_SMTP_PORT}', 'email:smtpTransport:user': '${MAIL_SMTP_USERNAME}', 'email:smtpTransport:pass': '${MAIL_SMTP_PASSWORD}', 'email:smtpTransport:security': 'NONE', 'email:from': '${MAIL_FROM}' } }, { upsert: true })" # there are 3 binaries # nodebb - this is used for controlling nodebb (start/stop/restart) etc # loader - this is what "nodebb start" starts. loader spawns 'n' number of app(s) # app - this is what "nodebb build" calls echo "=> Updating nodebb (and building assets)" series=1 /usr/local/bin/gosu cloudron:cloudron /app/code/nodebb upgrade --schema --build echo "=> Starting nodebb" series=1 exec /usr/local/bin/gosu cloudron:cloudron node /app/code/loader.js --no-daemon --no-silent