From 1892f68ebdfc0b75e033e507537abb9a4814527c Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Sun, 10 Mar 2024 14:53:57 +0000 Subject: [PATCH] Add helper script to check minimum requirements --- docker/check-requirements | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100755 docker/check-requirements diff --git a/docker/check-requirements b/docker/check-requirements new file mode 100755 index 000000000..ad8d0ede4 --- /dev/null +++ b/docker/check-requirements @@ -0,0 +1,112 @@ +#!/bin/bash + +set -e -o errexit -o nounset -o pipefail + +# +# Colors +# + +declare -r RED="\e[31m" +declare -r GREEN="\e[32m" +declare -r YELLOW="\e[33m" +declare -r BLUE="\e[34m" +declare -r NO_COLOR="\e[0m" + +# +# Helper functions +# + +function highlight() { + local reset="${2:-$NO_COLOR}" + echo "${BLUE}$1${reset}" +} + +function action_start() { + echo -en "⚙️ $1: " +} + +function action_start_newline() { + action_start "$1" + echo +} + +function action_ok() { + echo -e "\n\t✅ ${GREEN}${*}${NO_COLOR}\n" +} + +function action_warn() { + echo -e "⚠️ ${YELLOW}${*}${NO_COLOR}" +} + +function action_error() { + echo -e "\n\t❌ ${RED}${*}${NO_COLOR}" >&2 +} + +function action_error_exit() { + action_error "${*}\n\n${RED}Aborting!${NO_COLOR}" + + exit 1 +} + +# +# Configuration +# + +declare -r min_docker_compose_version_arr=(2 17) +min_docker_compose_version=$( + IFS=. + echo "${min_docker_compose_version[*]}" +) + +# +# Help text +# + +DOCKER_HELP=" + +\tWe recommend installing Docker (and Compose) directly from Docker.com instead of your Operation System package registry. +\tPlease see $(highlight "https://docs.docker.com/engine/install/")${RED} for information on how to install Docker on your system. + +\tAlternatively, you can update *JUST* the Compose plugin by following the guide here: +\t$(highlight "https://docs.docker.com/compose/install/linux/#install-the-plugin-manually")${RED}. + +\tLearn more about Docker compose release history here: +\t$(highlight "https://docs.docker.com/compose/release-notes/")${RED}.${NO_COLOR}" +declare -r DOCKER_HELP + +# +# System checks +# + +echo -e "👋 ${GREEN}Hello!" +echo -e "" +echo -e "This script will check your system for the minimum requirements outlined in the Pixelfed Docker install guide" +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}." +echo -e "${NO_COLOR}" + +action_start "Checking if [$(highlight "git")] command is available" +command -v git >/dev/null 2>&1 || { action_error_exit "I require the 'git' command, but it's not installed"; } +action_ok "git is installed" + +action_start "Checking if [$(highlight "docker")] command is available" +command -v docker >/dev/null 2>&1 || { action_error_exit "I require the 'docker' command, but it's not installed. ${DOCKER_HELP}"; } +action_ok "docker is installed" + +action_start "Checking if [$(highlight "docker compose")] command is available" +docker compose >/dev/null 2>&1 || { action_error_exit "I require the 'docker compose' command, but it's not installed. ${DOCKER_HELP}"; } +action_ok "docker compose is installed" + +compose_version=$(docker compose version --short) + +declare -a compose_version_arr +IFS="." read -r -a compose_version_arr <<<"$compose_version" + +action_start "Checking if [$(highlight "docker compose version")] major version (${min_docker_compose_version_arr[0]}) is acceptable" +[[ ${compose_version_arr[0]} -eq ${min_docker_compose_version_arr[0]} ]] || { action_error_exit "I require minimum Docker Compose major version ${min_docker_compose_version_arr[0]}.x.x - found ${compose_version}.${DOCKER_HELP}"; } +action_ok "You're using major version ${compose_version_arr[0]}" + +action_start "Checking if [$(highlight "docker compose version")] minor version (${min_docker_compose_version_arr[1]}) is acceptable" +[[ ${compose_version_arr[1]} -ge ${min_docker_compose_version_arr[1]} ]] || { action_error_exit "I require minimum Docker Compose minor version ${min_docker_compose_version_arr[0]}.${min_docker_compose_version_arr[1]} - found ${compose_version}.${DOCKER_HELP}"; } +action_ok "You're using minor version ${compose_version_arr[1]}" + +echo -e "🎉 ${GREEN}All checks passed, you should be ready to run Pixelfed on this server!${NO_COLOR}"