From cdfe44d958d481fcb56b44f8cca852ef2269d350 Mon Sep 17 00:00:00 2001 From: jude Date: Wed, 14 Jun 2023 13:29:48 +0100 Subject: [PATCH] Configure permissions properly on Rocket.toml. Make static path behave better --- Cargo.lock | 2 +- README.md | 28 +++++++++++++++++----------- conf/Rocket.toml | 2 +- debian/postinst | 1 + debian/postrm | 11 +++++++++++ web/src/lib.rs | 7 +++++-- 6 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 debian/postrm diff --git a/Cargo.lock b/Cargo.lock index ad5fb05..2a9b8ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2189,7 +2189,7 @@ checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "reminder-rs" -version = "1.6.10-4" +version = "1.6.10" dependencies = [ "base64", "chrono", diff --git a/README.md b/README.md index a06e573..6944347 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,22 @@ reminders are paid on the hosted version of the bot. Keep reading if you want to You'll need rustc and cargo for compilation. To run, you'll need Python 3 still (due to no suitable replacement for dateparser in Rust) -### Compiling for local target +### Build APT package + +Recommended method. + +By default, this builds targeting Ubuntu 20.04. Modify the Containerfile if you wish to target a different platform. These instructions are written using `podman`, but `docker` should work too. + +1. Install container software: `sudo apt install podman`. +2. Install database server: `sudo apt install mysql-server-8.0`. Create a database called `reminders` +3. Install SQLx CLI: `cargo install sqlx-cli` +4. From the source code directory, execute `sqlx migrate run` +5. Build container image: `podman build -t reminder-rs .` +6. Build with podman: `podman run --rm --network=host -v "$PWD":/mnt -w /mnt -e "DATABASE_URL=mysql://user@localhost/reminders" reminder-rs cargo deb` + + +### Compiling for other target + 1. Install requirements: `sudo apt install gcc gcc-multilib cmake libssl-dev build-essential python3-dateparser` 2. Install rustup from https://rustup.rs @@ -19,18 +34,9 @@ You'll need rustc and cargo for compilation. To run, you'll need Python 3 still * `DATABASE_URL` - the URL of your MySQL database (`mysql://user[:password]@domain/database`) 8. Build: `cargo build --release` -### Compiling for other target -By default, this builds targeting Ubuntu 20.04. Modify the Containerfile if you wish to target a different platform. These instructions are written using `podman`, but `docker` should work too. - -1. Install container software: `sudo apt install podman`. -2. Install database server: `sudo apt install mysql-server-8.0`. Create a database called `reminders` -3. Install SQLx CLI: `cargo install sqlx-cli` -4. From the source code directory, execute `sqlx migrate run` -5. Build container image: `podman build -t reminder-rs .` -6. Build with podman: `podman run --rm --network=host -v "$PWD":/mnt -w /mnt -e "DATABASE_URL=mysql://user@localhost/reminders" reminder-rs cargo deb` - ### Configuring + Reminder Bot reads a number of environment variables. Some are essential, and others have hardcoded fallbacks. Environment variables can be loaded from a .env file in the working directory. __Required Variables__ diff --git a/conf/Rocket.toml b/conf/Rocket.toml index 5fb0fb2..7a773e8 100644 --- a/conf/Rocket.toml +++ b/conf/Rocket.toml @@ -5,4 +5,4 @@ template_dir = "/lib/reminder-rs/templates" limits = { json = "10MiB" } [release] -secret_key = "release" +# secret_key = "" diff --git a/debian/postinst b/debian/postinst index 851559d..a65ce72 100644 --- a/debian/postinst +++ b/debian/postinst @@ -10,5 +10,6 @@ if [ ! -f '/etc/reminder-rs/config.env' ]; then fi chown reminder /etc/reminder-rs/config.env +chown reminder /etc/reminder-rs/Rocket.toml #DEBHELPER# diff --git a/debian/postrm b/debian/postrm new file mode 100644 index 0000000..b697e49 --- /dev/null +++ b/debian/postrm @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +id -u reminder &>/dev/null || userdel reminder + +if [ -f '/etc/reminder-rs/config.env' ]; then + rm /etc/reminder-rs/config.env +fi + +#DEBHELPER# diff --git a/web/src/lib.rs b/web/src/lib.rs index 7a11b12..0e5240d 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -6,7 +6,7 @@ mod consts; mod macros; mod routes; -use std::{collections::HashMap, env}; +use std::{collections::HashMap, env, path::Path}; use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl}; use rocket::{ @@ -88,6 +88,9 @@ pub async fn initialize( let reqwest_client = reqwest::Client::new(); + let static_path = + if Path::new("web/static").exists() { "web/static" } else { "/lib/reminder-rs/static" }; + rocket::build() .attach(Template::fairing()) .register( @@ -105,7 +108,7 @@ pub async fn initialize( .manage(reqwest_client) .manage(serenity_context) .manage(db_pool) - .mount("/static", FileServer::from("/lib/reminder-rs/static")) + .mount("/static", FileServer::from(static_path)) .mount( "/", routes![