From 511687c8c3d645a02773481c91e03387924af684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Thu, 22 May 2025 03:36:56 +0300 Subject: [PATCH] add proper instructions --- .gitignore | 2 ++ README.md | 26 ++++++++++++++++++++++---- config.lua | 2 ++ secrets.lua.example | 2 +- start.sh | 28 ++++++++++++++++++++++++++++ util.lua | 2 -- 6 files changed, 55 insertions(+), 7 deletions(-) create mode 100755 start.sh diff --git a/.gitignore b/.gitignore index 665fef9..a49ad37 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ db.*.sqlite static/avatars/* !static/avatars/default.webp secrets.lua + +.first_launch.* diff --git a/README.md b/README.md index dc18aa9..dca74ac 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ porous forum Released under [CNPLv7+](https://thufie.lain.haus/NPL.html). Please read the [full terms](./LICENSE.md) for proper wording. -# installing +# installing & first time setup 1. first, install OpenResty. instructions for linux can be found [here](https://openresty.org/en/linux-packages.html). -2. then, install LuaJIT +2. then, install LuaJIT and Lua 5.1 (usually called `lua5.1` in package managers) 3. then, install [LuaRocks](https://luarocks.org) (prefer your package manager instead of a local install recommended by the guide) 4. add luarocks search dirs to path: @@ -19,9 +19,27 @@ Please read the [full terms](./LICENSE.md) for proper wording. 6. install the dependencies: ```bash -luarocks --local --lua-version 5.1 build --only-deps +$ luarocks --local --lua-version 5.1 build --only-deps ``` -7. rest is TBD until a start script is provided +7. create a file named `secrets.lua` in the project directory. +use the `secrets.lua.example` file as reference, and generate a cryptographically secure random key, for example, with: + +```bash +$ openssl rand -hex 32 +``` +8. run: + +```bash +$ start.sh production +``` +the script will perform some necessary first time setup (and create a hidden file in the folder to ensure it won't do so again). it will create an administrator account and print the credentials to the console; **this will only happen once**. make sure you save them somewhere. the administrator account is the only one that can promote other users to moderator. +(note the `production` argument. if called with no arguments, `start.sh` will run in a development environment, which uses a separate database.) + +this app is made with the assumption that it is being reverse-proxied. as such, you may want to change the port to something other than the default `8080`. you can do that in [`config.lua`]([./config.lua]). + +after the first time setup is complete, everything is ready to go. put the app behind your reverse proxy and serve it on the web. the app does not run in https by itself, but the reverse proxy can be set up to do that. + +once you are able to navigate to the forum, you can log in as the administrator account. other people may also sign up, but they are not able to post until manually verified by an administrator or a moderator. the administrator can promote regular users to moderator. # icons the icons in the `icons/` folder are by [Gabriele Malaspina](https://www.figma.com/community/file/1136337054881623512/iconcino-v2-0-0-free-icons-cc0-1-0-license) diff --git a/config.lua b/config.lua index 41b9288..cfff976 100644 --- a/config.lua +++ b/config.lua @@ -2,6 +2,7 @@ local config = require("lapis.config") local secrets = require("secrets") config({"development", "production"}, { + port = 8080, server = "nginx", code_cache = "off", num_workers = "1", @@ -21,4 +22,5 @@ config("production", { sqlite = { database = "db.prod.sqlite" }, + session_name = "porom_session_s" }) diff --git a/secrets.lua.example b/secrets.lua.example index 43231c1..a9ffb57 100644 --- a/secrets.lua.example +++ b/secrets.lua.example @@ -1,3 +1,3 @@ return { - key = PROD_SECRET_KEY_HERE, + key = "PROD_SECRET_KEY_HERE", } diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..e2558ed --- /dev/null +++ b/start.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +start() { + lapis serve +} + +first_launch() { + echo "Setting up for the first time" + touch ".first_launch.$LAPIS_ENVIRONMENT" + lua5.1 schema.lua + lapis migrate + lua5.1 create_default_accounts.lua +} + +if [[ $# -ne 1 ]]; then + export LAPIS_ENVIRONMENT="development" + echo "WARN: no environment passed, assuming default (development)" +else + export LAPIS_ENVIRONMENT="$1" +fi + +echo "Starting in $LAPIS_ENVIRONMENT" + +if ! [ -f ".first_launch.$LAPIS_ENVIRONMENT" ]; then + first_launch +fi + +start diff --git a/util.lua b/util.lua index 1aefe9d..38d29ae 100644 --- a/util.lua +++ b/util.lua @@ -169,9 +169,7 @@ function util.transfer_and_delete_user(user) end function util.pop_infobox(req) - print("1") if not req.session.infobox then return end - print("2") req.infobox = req.session.infobox req.session.infobox = nil end