diff --git a/admin/initdb.py b/admin/initdb.py new file mode 100644 index 00000000..4e1b7f48 --- /dev/null +++ b/admin/initdb.py @@ -0,0 +1,6 @@ +from freeposte import db + + +# Initialize the database +db.create_all() +db.session.commit() diff --git a/admin/run.py b/admin/run.py index 389791c7..9b9768eb 100644 --- a/admin/run.py +++ b/admin/run.py @@ -1,10 +1,5 @@ from freeposte import app, db -# Initialize the database if required (first launch) -db.create_all() -db.session.commit() - - if __name__ == '__main__': app.run(debug=True) diff --git a/start.sh b/start.sh index b46fee5b..554ed07f 100755 --- a/start.sh +++ b/start.sh @@ -27,22 +27,26 @@ mkdir -p \ /data/ssl # Create the main database if necessary -[ -f /data/freeposte.db ] || sqlite3 /data/freeposte.db .databases > /dev/null +if [ ! -f /data/freeposte.db ]; then + echo 'Initializing the database...' + cd /admin && python initdb.py +fi # Fixing permissions -chown mail:www-data /data/freeposte.db +chown www-data:mail /data/freeposte.db +chmod 664 /data/freeposte.db chown -R mail:mail /data/mail chown -R www-data:www-data /data/webmail /data/logs/webmail # Copy the system snakeoil certificate if none is provided if [ ! -f /data/ssl/cert.pem ]; then - cat <<< EOF + cat << EOF No TLS certificate is installed, a snakeoil ceritifcate is thus being configured. You MUST NOT run a production server with this certificate, as the private key is known publicly. You have been warned. - EOF +EOF cp /etc/ssl/private/ssl-cert-snakeoil.key /data/ssl/key.pem cp /etc/ssl/certs/ssl-cert-snakeoil.pem /data/ssl/cert.pem fi