logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

release_env.ex (1875B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.ReleaseEnv do
  5. use Mix.Task
  6. import Mix.Pleroma
  7. @shortdoc "Generate Pleroma environment file."
  8. @moduledoc File.read!("docs/administration/CLI_tasks/release_environments.md")
  9. def run(["gen" | rest]) do
  10. {options, [], []} =
  11. OptionParser.parse(
  12. rest,
  13. strict: [
  14. force: :boolean,
  15. path: :string
  16. ],
  17. aliases: [
  18. p: :path,
  19. f: :force
  20. ]
  21. )
  22. file_path =
  23. get_option(
  24. options,
  25. :path,
  26. "Environment file path",
  27. "./config/pleroma.env"
  28. )
  29. env_path = Path.expand(file_path)
  30. proceed? =
  31. if File.exists?(env_path) do
  32. get_option(
  33. options,
  34. :force,
  35. "Environment file already exists. Do you want to overwrite the #{env_path} file? (y/n)",
  36. "n"
  37. ) === "y"
  38. else
  39. true
  40. end
  41. if proceed? do
  42. case do_generate(env_path) do
  43. {:error, reason} ->
  44. shell_error(
  45. File.Error.message(%{action: "write to file", reason: reason, path: env_path})
  46. )
  47. _ ->
  48. shell_info("\nThe file generated: #{env_path}.\n")
  49. shell_info("""
  50. WARNING: before start pleroma app please make sure to make the file read-only and non-modifiable.
  51. Example:
  52. chmod 0444 #{file_path}
  53. chattr +i #{file_path}
  54. """)
  55. end
  56. else
  57. shell_info("\nThe file is exist. #{env_path}.\n")
  58. end
  59. end
  60. def do_generate(path) do
  61. content = "RELEASE_COOKIE=#{Base.encode32(:crypto.strong_rand_bytes(32))}"
  62. File.mkdir_p!(Path.dirname(path))
  63. File.write(path, content)
  64. end
  65. end