From 4e0163f2cbfc56499be69163d68ddda1a94a8408 Mon Sep 17 00:00:00 2001 From: jude Date: Fri, 24 Mar 2023 17:44:43 +0000 Subject: [PATCH] Rename some environment variables. Add partial deb metadata --- Cargo.lock | 142 ++++++++++++++++++++++++++++++------ Cargo.toml | 17 ++++- Rocket.toml | 10 +-- conf/default.env | 15 ++++ debian/.gitignore | 2 + nginx/reminder-rs | 41 +++++++++++ src/consts.rs | 4 +- src/main.rs | 6 +- systemd/reminder-rs.service | 12 +++ web/src/consts.rs | 4 +- web/src/lib.rs | 2 +- 11 files changed, 217 insertions(+), 38 deletions(-) create mode 100644 conf/default.env create mode 100644 debian/.gitignore create mode 100644 nginx/reminder-rs create mode 100644 systemd/reminder-rs.service diff --git a/Cargo.lock b/Cargo.lock index 8d3e2d9..b7f3707 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -144,7 +144,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -680,17 +680,38 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "event-listener" version = "2.5.3" @@ -999,6 +1020,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -1232,12 +1259,35 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "ipnet" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec947b7a4ce12e3b87e353abae7ce124d025b6c7d6c5aea5cc0bcf92e9510ded" +[[package]] +name = "is-terminal" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1347,6 +1397,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lock_api" version = "0.4.9" @@ -1589,7 +1645,7 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -2383,6 +2439,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rustix" +version = "0.36.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + [[package]] name = "rustls" version = "0.20.7" @@ -3560,19 +3630,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.2", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" @@ -3588,9 +3682,9 @@ checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" @@ -3606,9 +3700,9 @@ checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" @@ -3624,9 +3718,9 @@ checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" @@ -3642,15 +3736,15 @@ checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" @@ -3666,9 +3760,9 @@ checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winreg" diff --git a/Cargo.toml b/Cargo.toml index 1f0c577..ee61be2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "reminder_rs" version = "1.6.10" -authors = ["jellywx "] +authors = ["Jude Southworth "] edition = "2021" [dependencies] @@ -12,7 +12,7 @@ reqwest = "0.11" lazy-regex = "2.3.0" regex = "1.6" log = "0.4" -env_logger = "0.9" +env_logger = "0.10" chrono = "0.4" chrono-tz = { version = "0.8", features = ["serde"] } lazy_static = "1.4" @@ -31,3 +31,16 @@ path = "postman" [dependencies.reminder_web] path = "web" + +[package.metadata.deb] +depends = "$auto, nginx, python3, python3-venv" +suggests = "mysql-server-8.0" +maintainer-scripts = "debian" +assets = [ + ["target/release/reminder-rs", "usr/bin/reminder-rs", "755"], + ["conf/default.env", "etc/reminder-rs/default.env", "600"] +] + +[package.metadata.deb.systemd-units] +unit-scripts = "systemd" +start = false diff --git a/Rocket.toml b/Rocket.toml index 1c51269..872f0f4 100644 --- a/Rocket.toml +++ b/Rocket.toml @@ -1,6 +1,6 @@ [default] address = "0.0.0.0" -port = 5000 +port = 18920 template_dir = "web/templates" limits = { json = "10MiB" } @@ -11,18 +11,18 @@ secret_key = "tR8krio5FXTnnyIZNiJDXPondz0kI1v6X6BXZcBGIRY=" certs = "web/private/rsa_sha256_cert.pem" key = "web/private/rsa_sha256_key.pem" -[rsa_sha256.tls] +[debug.rsa_sha256.tls] certs = "web/private/rsa_sha256_cert.pem" key = "web/private/rsa_sha256_key.pem" -[ecdsa_nistp256_sha256.tls] +[debug.ecdsa_nistp256_sha256.tls] certs = "web/private/ecdsa_nistp256_sha256_cert.pem" key = "web/private/ecdsa_nistp256_sha256_key_pkcs8.pem" -[ecdsa_nistp384_sha384.tls] +[debug.ecdsa_nistp384_sha384.tls] certs = "web/private/ecdsa_nistp384_sha384_cert.pem" key = "web/private/ecdsa_nistp384_sha384_key_pkcs8.pem" -[ed25519.tls] +[debug.ed25519.tls] certs = "web/private/ed25519_cert.pem" key = "eb/private/ed25519_key.pem" diff --git a/conf/default.env b/conf/default.env new file mode 100644 index 0000000..2eb23f0 --- /dev/null +++ b/conf/default.env @@ -0,0 +1,15 @@ +DATABASE_URL= + +DISCORD_TOKEN= +PATREON_GUILD_ID= +PATREON_ROLE_ID= + +LOCAL_TIMEZONE= +MIN_INTERVAL= +PYTHON_LOCATION= +SECRET_KEY= + +REMIND_INTERVAL= +OAUTH2_DISCORD_CALLBACK= +OAUTH2_CLIENT_ID= +OAUTH2_CLIENT_SECRET= diff --git a/debian/.gitignore b/debian/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/debian/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/nginx/reminder-rs b/nginx/reminder-rs new file mode 100644 index 0000000..5861cdf --- /dev/null +++ b/nginx/reminder-rs @@ -0,0 +1,41 @@ +server { + server_name www.reminder-bot.com; + + return 301 $scheme://reminder-bot.com$request_uri; +} + +server { + listen 80; + server_name reminder-bot.com; + + return 301 https://reminder-bot.com$request_uri; +} + +server { + listen 443 ssl; + server_name reminder-bot.com; + + ssl_certificate /etc/letsencrypt/live/reminder-bot.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/reminder-bot.com/privkey.pem; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + proxy_buffer_size 128k; + proxy_buffers 4 256k; + proxy_busy_buffers_size 256k; + + location / { + proxy_pass http://localhost:18920; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /static { + alias /var/www/reminder-rs/static; + expires 30d; + } +} diff --git a/src/consts.rs b/src/consts.rs index d2b3c2d..0bc0af2 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -27,7 +27,7 @@ lazy_static! { .into(); pub static ref REGEX_CHANNEL_USER: Regex = Regex::new(r#"\s*<(#|@)(?:!)?(\d+)>\s*"#).unwrap(); pub static ref SUBSCRIPTION_ROLES: HashSet = HashSet::from_iter( - env::var("SUBSCRIPTION_ROLES") + env::var("PATREON_ROLE_ID") .map(|var| var .split(',') .filter_map(|item| { item.parse::().ok() }) @@ -35,7 +35,7 @@ lazy_static! { .unwrap_or_else(|_| Vec::new()) ); pub static ref CNC_GUILD: Option = - env::var("CNC_GUILD").map(|var| var.parse::().ok()).ok().flatten(); + env::var("PATREON_GUILD_ID").map(|var| var.parse::().ok()).ok().flatten(); pub static ref MIN_INTERVAL: i64 = env::var("MIN_INTERVAL").ok().and_then(|inner| inner.parse::().ok()).unwrap_or(600); pub static ref MAX_TIME: i64 = env::var("MAX_TIME") diff --git a/src/main.rs b/src/main.rs index 55ac01a..70d8597 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,10 +18,10 @@ use std::{ env, error::Error as StdError, fmt::{Debug, Display, Formatter}, + path::Path, }; use chrono_tz::Tz; -use dotenv::dotenv; use log::{error, warn}; use poise::serenity_prelude::model::{ gateway::GatewayIntents, @@ -88,7 +88,9 @@ async fn main() -> Result<(), Box> { async fn _main(tx: Sender<()>) -> Result<(), Box> { env_logger::init(); - dotenv()?; + if Path::new("/etc/soundfx-rs/default.env").exists() { + dotenv::from_path("/etc/soundfx-rs/default.env")?; + } let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"); diff --git a/systemd/reminder-rs.service b/systemd/reminder-rs.service new file mode 100644 index 0000000..0ca2582 --- /dev/null +++ b/systemd/reminder-rs.service @@ -0,0 +1,12 @@ +[Unit] +Description=Reminder Bot + +[Service] +Type=simple +ExecStart=/usr/bin/reminder-rs +Restart=always +RestartSec=4 +# Environment="RUST_LOG=warn,reminder_rs=info,postman=info" + +[Install] +WantedBy=multi-user.target diff --git a/web/src/consts.rs b/web/src/consts.rs index 906c574..8ca284a 100644 --- a/web/src/consts.rs +++ b/web/src/consts.rs @@ -31,7 +31,7 @@ lazy_static! { ) .into(); pub static ref SUBSCRIPTION_ROLES: HashSet = HashSet::from_iter( - env::var("SUBSCRIPTION_ROLES") + env::var("PATREON_ROLE_ID") .map(|var| var .split(',') .filter_map(|item| { item.parse::().ok() }) @@ -39,7 +39,7 @@ lazy_static! { .unwrap_or_else(|_| Vec::new()) ); pub static ref CNC_GUILD: Option = - env::var("CNC_GUILD").map(|var| var.parse::().ok()).ok().flatten(); + env::var("PATREON_GUILD_ID").map(|var| var.parse::().ok()).ok().flatten(); pub static ref MIN_INTERVAL: u32 = env::var("MIN_INTERVAL") .ok() .map(|inner| inner.parse::().ok()) diff --git a/web/src/lib.rs b/web/src/lib.rs index 81584f2..92b45f6 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -75,7 +75,7 @@ pub async fn initialize( env::var("OAUTH2_CLIENT_ID").expect("`OAUTH2_CLIENT_ID' not supplied"); env::var("OAUTH2_CLIENT_SECRET").expect("`OAUTH2_CLIENT_SECRET' not supplied"); env::var("OAUTH2_DISCORD_CALLBACK").expect("`OAUTH2_DISCORD_CALLBACK' not supplied"); - env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD' not supplied"); + env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD_ID' not supplied"); info!("Done!"); let oauth2_client = BasicClient::new(