check-requirements 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/bash
  2. set -e -o errexit -o nounset -o pipefail
  3. #
  4. # Colors
  5. #
  6. declare -r RED="\e[31m"
  7. declare -r GREEN="\e[32m"
  8. declare -r BLUE="\e[34m"
  9. declare -r NO_COLOR="\e[0m"
  10. #
  11. # Helper functions
  12. #
  13. function highlight() {
  14. local reset="${2:-$NO_COLOR}"
  15. echo "${BLUE}$1${reset}"
  16. }
  17. function action_start() {
  18. echo -en "⚙️ $1: "
  19. }
  20. function action_ok() {
  21. echo -e "\n\t✅ ${GREEN}${*}${NO_COLOR}\n"
  22. }
  23. function action_error() {
  24. echo -e "\n\t❌ ${RED}${*}${NO_COLOR}" >&2
  25. }
  26. function action_error_exit() {
  27. action_error "${*}\n\n${RED}Aborting!${NO_COLOR}"
  28. exit 1
  29. }
  30. #
  31. # Configuration
  32. #
  33. declare -r min_docker_compose_version_arr=(2 17)
  34. min_docker_compose_version=$(
  35. IFS=.
  36. echo "${min_docker_compose_version[*]}"
  37. )
  38. #
  39. # Help text
  40. #
  41. DOCKER_HELP="
  42. \tWe recommend installing Docker (and Compose) directly from Docker.com instead of your Operation System package registry.
  43. \tPlease see $(highlight "https://docs.docker.com/engine/install/")${RED} for information on how to install Docker on your system.
  44. \tA convinience script is provided by Docker to automate the installation that should work on all supported platforms:
  45. \t\t ${GREEN}\$${BLUE} curl -fsSL https://get.docker.com -o get-docker.sh
  46. \t\t ${GREEN}\$${BLUE} sudo sh ./get-docker.sh
  47. ${RED}
  48. \tPlease see $(highlight "https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script")${RED} for more information
  49. \tAlternatively, you can update *JUST* the Compose plugin by following the guide here:
  50. \t$(highlight "https://docs.docker.com/compose/install/linux/#install-the-plugin-manually")${RED}
  51. \tLearn more about Docker compose release history here:
  52. \t$(highlight "https://docs.docker.com/compose/release-notes/")${RED}${NO_COLOR}"
  53. declare -r DOCKER_HELP
  54. #
  55. # System checks
  56. #
  57. echo -e "👋 ${GREEN}Hello!"
  58. echo -e ""
  59. echo -e "This script will check your system for the minimum requirements outlined in the Pixelfed Docker install guide"
  60. echo -e "You can find the guide here ${BLUE}https://jippi.github.io/pixelfed-docs-next/pr-preview/pr-1/running-pixelfed/docker/prerequisites.html#software${GREEN}."
  61. echo -e "${NO_COLOR}"
  62. # git installed?
  63. action_start "Checking if [$(highlight "git")] command is available"
  64. command -v git >/dev/null 2>&1 || {
  65. action_error_exit "Pixelfed require the 'git' command, but it's not installed"
  66. }
  67. action_ok "git is installed"
  68. # docker installed?
  69. action_start "Checking if [$(highlight "docker")] command is available"
  70. command -v docker >/dev/null 2>&1 || {
  71. action_error_exit "Pixelfed require the 'docker' command, but it's not installed. ${DOCKER_HELP}"
  72. }
  73. action_ok "docker is installed"
  74. # docker compose installed?
  75. action_start "Checking if [$(highlight "docker compose")] command is available"
  76. docker compose >/dev/null 2>&1 || {
  77. action_error_exit "Pixelfed require the 'docker compose' command, but it's not installed. ${DOCKER_HELP}"
  78. }
  79. action_ok "docker compose is installed"
  80. # docker compose version is acceptable?
  81. compose_version=$(docker compose version --short)
  82. declare -a compose_version_arr
  83. IFS="." read -r -a compose_version_arr <<<"$compose_version"
  84. ## major version
  85. action_start "Checking if [$(highlight "docker compose version")] major version (${min_docker_compose_version_arr[0]}) is acceptable"
  86. [[ ${compose_version_arr[0]} -eq ${min_docker_compose_version_arr[0]} ]] || {
  87. action_error_exit "Pixelfed require minimum Docker Compose major version ${min_docker_compose_version_arr[0]}.x.x - found ${compose_version}.${DOCKER_HELP}"
  88. }
  89. action_ok "You're using major version ${compose_version_arr[0]}"
  90. ## minor version
  91. action_start "Checking if [$(highlight "docker compose version")] minor version (${min_docker_compose_version_arr[1]}) is acceptable"
  92. [[ ${compose_version_arr[1]} -ge ${min_docker_compose_version_arr[1]} ]] || {
  93. action_error_exit "Pixelfed require minimum Docker Compose minor version ${min_docker_compose_version_arr[0]}.${min_docker_compose_version_arr[1]} - found ${compose_version}.${DOCKER_HELP}"
  94. }
  95. action_ok "You're using minor version ${compose_version_arr[1]}"
  96. # Yay, everything is fine
  97. echo -e "🎉 ${GREEN}All checks passed, you should be ready to run Pixelfed on this server!${NO_COLOR}"