lib/mix/tasks: s/@doc/@moduledoc/
[akkoma] / lib / mix / tasks / generate_config.ex
1 defmodule Mix.Tasks.GenerateConfig do
2 use Mix.Task
3
4 @moduledoc """
5 Generate a new config
6
7 ## Usage
8 ``mix generate_config``
9
10 This mix task is interactive, and will overwrite the config present at ``config/generated_config.exs``.
11 """
12
13 def run(_) do
14 IO.puts("Answer a few questions to generate a new config\n")
15 IO.puts("--- THIS WILL OVERWRITE YOUR config/generated_config.exs! ---\n")
16 domain = IO.gets("What is your domain name? (e.g. pleroma.soykaf.com): ") |> String.trim()
17 name = IO.gets("What is the name of your instance? (e.g. Pleroma/Soykaf): ") |> String.trim()
18 email = IO.gets("What's your admin email address: ") |> String.trim()
19
20 secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
21 dbpass = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
22
23 resultSql = EEx.eval_file("lib/mix/tasks/sample_psql.eex", dbpass: dbpass)
24
25 result =
26 EEx.eval_file(
27 "lib/mix/tasks/sample_config.eex",
28 domain: domain,
29 email: email,
30 name: name,
31 secret: secret,
32 dbpass: dbpass
33 )
34
35 IO.puts(
36 "\nWriting config to config/generated_config.exs.\n\nCheck it and configure your database, then copy it to either config/dev.secret.exs or config/prod.secret.exs"
37 )
38
39 File.write("config/generated_config.exs", result)
40
41 IO.puts(
42 "\nWriting setup_db.psql, please run it as postgre superuser, i.e.: sudo su postgres -c 'psql -f config/setup_db.psql'"
43 )
44
45 File.write("config/setup_db.psql", resultSql)
46 end
47 end