logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

pleroma_ctl (4513B)


  1. #!/bin/sh
  2. # XXX: This should be removed when elixir's releases get custom command support
  3. detect_flavour() {
  4. arch="$(uname -m)"
  5. if [ "$arch" = "x86_64" ]; then
  6. arch="amd64"
  7. elif [ "$arch" = "armv7l" ]; then
  8. arch="arm"
  9. elif [ "$arch" = "aarch64" ]; then
  10. arch="arm64"
  11. else
  12. echo "Unsupported arch: $arch" >&2
  13. exit 1
  14. fi
  15. if getconf GNU_LIBC_VERSION >/dev/null; then
  16. libc_postfix=""
  17. elif [ "$(ldd 2>&1 | head -c 9)" = "musl libc" ]; then
  18. libc_postfix="-musl"
  19. elif [ "$(find /lib/libc.musl* | wc -l)" ]; then
  20. libc_postfix="-musl"
  21. else
  22. echo "Unsupported libc" >&2
  23. exit 1
  24. fi
  25. echo "$arch$libc_postfix"
  26. }
  27. detect_branch() {
  28. version="$(cut -d' ' -f2 <"$RELEASE_ROOT"/releases/start_erl.data)"
  29. # Expected format: major.minor.patch_version(-number_of_commits_ahead_of_tag-gcommit_hash).branch
  30. branch="$(echo "$version" | cut -d'.' -f 4)"
  31. if [ "$branch" = "develop" ]; then
  32. echo "develop"
  33. elif [ "$branch" = "" ]; then
  34. echo "stable"
  35. else
  36. # Note: branch name in version is of SemVer format and may only contain [0-9a-zA-Z-] symbols —
  37. # if supporting releases for more branches, need to ensure they contain only these symbols.
  38. echo "Can't detect the branch automatically, please specify it by using the --branch option." >&2
  39. exit 1
  40. fi
  41. }
  42. update() {
  43. set -e
  44. NO_RM=false
  45. while echo "$1" | grep "^-" >/dev/null; do
  46. case "$1" in
  47. --zip-url)
  48. FULL_URI="$2"
  49. shift 2
  50. ;;
  51. --no-rm)
  52. NO_RM=true
  53. shift
  54. ;;
  55. --flavour)
  56. FLAVOUR="$2"
  57. shift 2
  58. ;;
  59. --branch)
  60. BRANCH="$2"
  61. shift 2
  62. ;;
  63. --tmp-dir)
  64. TMP_DIR="$2"
  65. shift 2
  66. ;;
  67. -*)
  68. echo "invalid option: $1" 1>&2
  69. shift
  70. ;;
  71. esac
  72. done
  73. RELEASE_ROOT=$(dirname "$SCRIPTPATH")
  74. uri="https://git.pleroma.social"
  75. project_id="2"
  76. project_branch="${BRANCH:-$(detect_branch)}"
  77. flavour="${FLAVOUR:-$(detect_flavour)}"
  78. tmp="${TMP_DIR:-/tmp}"
  79. artifact="$tmp/pleroma.zip"
  80. full_uri="${FULL_URI:-${uri}/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=${flavour}}"
  81. echo "Downloading the artifact from ${full_uri} to ${artifact}"
  82. curl "$full_uri" -o "${artifact}"
  83. echo "Unpacking ${artifact} to ${tmp}"
  84. unzip -q "$artifact" -d "$tmp"
  85. echo "Copying files over to $RELEASE_ROOT"
  86. if [ "$NO_RM" = false ]; then
  87. echo "Removing files from the previous release"
  88. rm -r "${RELEASE_ROOT:-?}"/*
  89. fi
  90. cp -rf "$tmp/release"/* "$RELEASE_ROOT"
  91. echo "Removing temporary files"
  92. rm -r "$tmp/release"
  93. rm "$artifact"
  94. echo "Done! Please refer to the changelog/release notes for changes and update instructions"
  95. set +e
  96. }
  97. if [ -z "$1" ] || [ "$1" = "help" ]; then
  98. # TODO: Just list the commands on `pleroma_ctl help` and output help for the individual command on `pleroma_ctl help $COMMAND`
  99. echo "Usage: $(basename "$0") COMMAND [ARGS]
  100. The known commands are:
  101. create
  102. Create database schema (needs to be executed only once)
  103. migrate
  104. Execute database migrations (needs to be done after updates)
  105. rollback [VERSION]
  106. Rollback database migrations (needs to be done before downgrading)
  107. update [OPTIONS]
  108. Update the instance.
  109. Options:
  110. --branch Update to a specified branch, instead of the latest version of the current one.
  111. --flavour Update to a specified flavour (CPU architecture+libc), instead of the current one.
  112. --zip-url Get the release from a specified url. If set, renders the previous 2 options inactive.
  113. --no-rm Do not erase previous release's files.
  114. --tmp-dir Download the temporary files to a specified directory.
  115. and any mix tasks under Pleroma namespace, for example \`mix pleroma.user COMMAND\` is
  116. equivalent to \`$(basename "$0") user COMMAND\`
  117. By default pleroma_ctl will try calling into a running instance to execute non migration-related commands,
  118. if for some reason this is undesired, set PLEROMA_CTL_RPC_DISABLED environment variable.
  119. "
  120. else
  121. SCRIPT=$(realpath "$0")
  122. SCRIPTPATH=$(dirname "$SCRIPT")
  123. FULL_ARGS="$*"
  124. ACTION="$1"
  125. if [ $# -gt 0 ]; then
  126. shift
  127. fi
  128. echo "$1" | grep "^-" >/dev/null
  129. if [ $? -eq 1 ]; then
  130. SUBACTION="$1"
  131. if [ $# -gt 0 ]; then
  132. shift
  133. fi
  134. fi
  135. if [ "$ACTION" = "update" ]; then
  136. update "$@"
  137. elif [ "$ACTION" = "migrate" ] || [ "$ACTION" = "rollback" ] || [ "$ACTION" = "create" ] || [ "$ACTION $SUBACTION" = "instance gen" ] || [ "$PLEROMA_CTL_RPC_DISABLED" = true ]; then
  138. "$SCRIPTPATH"/pleroma eval 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")'
  139. else
  140. "$SCRIPTPATH"/pleroma rpc 'Pleroma.ReleaseTasks.run("'"$FULL_ARGS"'")'
  141. fi
  142. fi