mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-21 00:39:16 +00:00
Refactor copypasta to a private function in instance.ex
This commit is contained in:
parent
cbe22deb51
commit
d924b6cd3d
|
@ -59,49 +59,37 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
||||||
|
|
||||||
unless not proceed? do
|
unless not proceed? do
|
||||||
domain =
|
domain =
|
||||||
Keyword.get(options, :domain) ||
|
get_option(
|
||||||
Mix.shell().prompt("What domain will your instance use? (e.g. pleroma.soykaf.com)")
|
options,
|
||||||
|> String.trim()
|
:domain,
|
||||||
|
"What domain will your instance use? (e.g pleroma.soykaf.com)"
|
||||||
|
)
|
||||||
|
|
||||||
name =
|
name =
|
||||||
Keyword.get(options, :name) ||
|
get_option(options, :name, "What is the name of your instance? (e.g. Pleroma/Soykaf)")
|
||||||
Mix.shell().prompt("What is the name of your instance? (e.g. Pleroma/Soykaf)")
|
|
||||||
|> String.trim()
|
|
||||||
|
|
||||||
email =
|
email = get_option(options, :admin_email, "What is your admin email address?")
|
||||||
Keyword.get(options, :admin_email) ||
|
|
||||||
Mix.shell().prompt("What is your admin email address?")
|
|
||||||
|> String.trim()
|
|
||||||
|
|
||||||
dbhost =
|
dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
|
||||||
Keyword.get(options, :dbhost) ||
|
|
||||||
case Mix.shell().prompt("What is the hostname of your database? [localhost]") do
|
|
||||||
"\n" -> "localhost"
|
|
||||||
dbhost -> dbhost |> String.trim()
|
|
||||||
end
|
|
||||||
|
|
||||||
dbname =
|
dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma_dev")
|
||||||
Keyword.get(options, :dbname) ||
|
|
||||||
case Mix.shell().prompt("What is the name of your database? [pleroma_dev]") do
|
|
||||||
"\n" -> "pleroma_dev"
|
|
||||||
dbname -> dbname |> String.trim()
|
|
||||||
end
|
|
||||||
|
|
||||||
dbuser =
|
dbuser =
|
||||||
Keyword.get(options, :dbuser) ||
|
get_option(
|
||||||
case Mix.shell().prompt("What is the user used to connect to your database? [pleroma]") do
|
options,
|
||||||
"\n" -> "pleroma"
|
:dbuser,
|
||||||
dbuser -> dbuser |> String.trim()
|
"What is the user used to connect to your database?",
|
||||||
end
|
"pleroma"
|
||||||
|
)
|
||||||
|
|
||||||
dbpass =
|
dbpass =
|
||||||
Keyword.get(options, :dbpass) ||
|
get_option(
|
||||||
case Mix.shell().prompt(
|
options,
|
||||||
"What is the password used to connect to your database? [autogenerated]"
|
:dbpass,
|
||||||
) do
|
"What is the password used to connect to your database?",
|
||||||
"\n" -> :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
|
:crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64),
|
||||||
dbpass -> dbpass |> String.trim()
|
"autogenerated"
|
||||||
end
|
)
|
||||||
|
|
||||||
secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
|
secret = :crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64)
|
||||||
|
|
||||||
|
@ -160,4 +148,18 @@ defmodule Mix.Tasks.Pleroma.Instance do
|
||||||
defp escape_sh_path(path) do
|
defp escape_sh_path(path) do
|
||||||
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
|
~S(') <> String.replace(path, ~S('), ~S(\')) <> ~S(')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_option(options, opt, prompt, def \\ nil, defname \\ nil) do
|
||||||
|
Keyword.get(options, opt) ||
|
||||||
|
case Mix.shell().prompt("#{prompt} [#{defname || def}]") do
|
||||||
|
"\n" ->
|
||||||
|
case def do
|
||||||
|
nil -> get_option(options, opt, prompt, def)
|
||||||
|
def -> def
|
||||||
|
end
|
||||||
|
|
||||||
|
opt ->
|
||||||
|
opt |> String.trim()
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue