Simplify mix pleroma.instance gen task

This commit is contained in:
Alex Gleason 2021-05-16 15:08:20 -05:00
parent 28840d2f31
commit ba177d2a4b
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 23 additions and 66 deletions

View file

@ -59,7 +59,7 @@ def run(["gen" | rest]) do
get_option(
options,
:domain,
"What domain will your instance use? (e.g pleroma.soykaf.com)"
"What domain will your instance use? (e.g mysite.com)"
),
":"
) ++ [443]
@ -68,11 +68,16 @@ def run(["gen" | rest]) do
get_option(
options,
:instance_name,
"What is the name of your instance? (e.g. The Corndog Emporium)",
"What is the name of your instance? (e.g. Our Wonderful Community)",
domain
)
email = get_option(options, :admin_email, "What is your admin email address?")
email =
get_option(
options,
:admin_email,
"What is your admin email address? (this will be public)"
)
notify_email =
get_option(
@ -90,23 +95,17 @@ def run(["gen" | rest]) do
"y"
) === "y"
db_configurable? =
get_option(
options,
:db_configurable,
"Do you want to store the configuration in the database (allows controlling it from admin-fe)? (y/n)",
"n"
) === "y"
db_configurable? = true
dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
dbhost = get_option(options, :dbhost, "Where will your database live?", "localhost")
dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma")
dbname = get_option(options, :dbname, "What shall we name your database?", "pleroma")
dbuser =
get_option(
options,
:dbuser,
"What is the user used to connect to your database?",
"What shall we name your database user?",
"pleroma"
)
@ -114,18 +113,12 @@ def run(["gen" | rest]) do
get_option(
options,
:dbpass,
"What is the password used to connect to your database?",
"What shall be your database password?",
:crypto.strong_rand_bytes(64) |> Base.encode64() |> binary_part(0, 64),
"autogenerated"
)
rum_enabled =
get_option(
options,
:rum,
"Would you like to use RUM indices?",
"n"
) === "y"
rum_enabled = false
listen_port =
get_option(
@ -139,60 +132,25 @@ def run(["gen" | rest]) do
get_option(
options,
:listen_ip,
"What ip will the app listen to (leave it if you are using the default setup with nginx)?",
"What IP will the app listen to (leave it if you are using the default setup with nginx)?",
"127.0.0.1"
)
uploads_dir =
get_option(
options,
:uploads_dir,
"What directory should media uploads go in (when using the local uploader)?",
Keyword.get(options, :uploads_dir) ||
Config.get([Pleroma.Uploaders.Local, :uploads])
)
|> Path.expand()
|> Path.expand()
static_dir =
get_option(
options,
:static_dir,
"What directory should custom public files be read from (custom emojis, frontend bundle overrides, robots.txt, etc.)?",
Keyword.get(options, :static_dir) ||
Config.get([:instance, :static_dir])
)
|> Path.expand()
|> Path.expand()
{strip_uploads_message, strip_uploads_default} =
if Pleroma.Utils.command_available?("exiftool") do
{"Do you want to strip location (GPS) data from uploaded images? This requires exiftool, it was detected as installed. (y/n)",
"y"}
else
{"Do you want to strip location (GPS) data from uploaded images? This requires exiftool, it was detected as not installed, please install it if you answer yes. (y/n)",
"n"}
end
strip_uploads = false
strip_uploads =
get_option(
options,
:strip_uploads,
strip_uploads_message,
strip_uploads_default
) === "y"
anonymize_uploads = false
anonymize_uploads =
get_option(
options,
:anonymize_uploads,
"Do you want to anonymize the filenames of uploads? (y/n)",
"n"
) === "y"
dedupe_uploads =
get_option(
options,
:dedupe_uploads,
"Do you want to deduplicate uploaded files? (y/n)",
"n"
) === "y"
dedupe_uploads = false
Config.put([:instance, :static_dir], static_dir)

View file

@ -91,12 +91,11 @@ test "running gen" do
assert generated_config =~ "password: \"dbpass\""
assert generated_config =~ "configurable_from_database: true"
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
assert generated_config =~ "filters: [Pleroma.Upload.Filter.Exiftool]"
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
assert File.exists?(Path.expand("./test/instance/static/robots.txt"))
end
defp generated_setup_psql do
~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\nCREATE EXTENSION IF NOT EXISTS rum;\n)
~s(CREATE USER dbuser WITH ENCRYPTED PASSWORD 'dbpass';\nCREATE DATABASE dbname OWNER dbuser;\n\\c dbname;\n--Extensions made by ecto.migrate that need superuser access\nCREATE EXTENSION IF NOT EXISTS citext;\nCREATE EXTENSION IF NOT EXISTS pg_trgm;\nCREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\n\n)
end
end