Complex setup

Also generate and save a Rocket secret key, which avoid deconnecting us when restarting the instance

Other small improvements
This commit is contained in:
Bat 2018-06-19 18:23:26 +01:00
parent f5d70ddfd4
commit a281612051
3 changed files with 30 additions and 3 deletions

4
.env
View File

@ -1,2 +1,6 @@
BASE_URL=plu.me BASE_URL=plu.me
ROCKET_SECRET_KEY=7IdEGAf7EL7ehPjLNncCcE+2B0MTiywxDzr8KklU/VA=
ROCKET_PORT=7878
ROCKET_ADDRESS=0.0.0.0

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ rls
rls rls
translations translations
po/*.po~ po/*.po~
.env

View File

@ -53,15 +53,20 @@ fn run_setup(conn: Option<DbConn>) {
check_native_deps(); check_native_deps();
let conn = setup_db(conn); let conn = setup_db(conn);
setup_type(conn); setup_type(conn);
dotenv().ok();
println!("{}\n{}\n{}", println!("{}\n{}\n{}",
"Your Plume instance is now ready to be used.".magenta(), "Your Plume instance is now ready to be used.".magenta(),
"We hope you will enjoy it.".magenta(), "We hope you will enjoy it.".magenta(),
"If you ever encounter a problem, feel free to report it at https://github.com/Plume-org/Plume/issues/".magenta(), "If you ever encounter a problem, feel free to report it at https://github.com/Plume-org/Plume/issues/".magenta(),
); );
println!("\nPress Enter to start it.\n");
} }
fn setup_db(conn: Option<DbConn>) -> DbConn { fn setup_db(conn: Option<DbConn>) -> DbConn {
write_to_dotenv("DB_URL", DB_URL.as_str().to_string());
match conn { match conn {
Some(conn) => conn, Some(conn) => conn,
None => { None => {
@ -151,12 +156,29 @@ fn quick_setup(conn: DbConn) {
println!("{}\n", " ✔️ Your instance was succesfully created!".green()); println!("{}\n", " ✔️ Your instance was succesfully created!".green());
// Generate Rocket secret key.
let key = Command::new("openssl")
.arg("rand")
.arg("-base64")
.arg("32")
.output()
.map(|o| String::from_utf8(o.stdout).expect("Invalid output from openssl"))
.expect("Couldn't generate secret key.");
write_to_dotenv("ROCKET_SECRET_KEY", key);
create_admin(instance, conn); create_admin(instance, conn);
} }
fn complete_setup(conn: DbConn) { fn complete_setup(conn: DbConn) {
// TODO
quick_setup(conn); quick_setup(conn);
println!("\nOn which port should Plume listen? (default: 7878)");
let port = read_line_or("7878");
write_to_dotenv("ROCKET_PORT", port);
println!("\nOn which port should Plume listen? (default: 0.0.0.0)");
let address = read_line_or("0.0.0.0");
write_to_dotenv("ROCKET_ADDRESS", address);
} }
fn create_admin(instance: Instance, conn: DbConn) { fn create_admin(instance: Instance, conn: DbConn) {