#!/bin/bash docker_file_dir="$(pwd)/docker" function get_docker_install() { (cd "${docker_file_dir}" && chmod +x docker_off-line_install.sh && ./docker_off-line_install.sh -f docker-26.1.0.tgz >/dev/null 2>&1 && systemctl start docker >/dev/null 2>&1 && systemctl enable docker >/dev/null 2>&1) } function check_docker_status() { [ ! -z "$(docker ps 2>/dev/null)" ] } function check_compose_status() { [ ! -z "$(docker compose 2>/dev/null)" ] } function check_docker_compose_status() { [ ! -z "$(docker-compose 2>/dev/null)" ] } function get_compose_install() { echo "try to install docker compose service" (DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker} && mkdir -p $DOCKER_CONFIG/cli-plugins && cp "${docker_file_dir}/docker-compose" $DOCKER_CONFIG/cli-plugins/docker-compose && chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose) (check_compose_status || get_docker_compose_install) } function get_docker_compose_install() { (cp "${docker_file_dir}/docker-compose" /usr/local/bin/ && chmod +x /usr/local/bin/docker-compose && ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose) (check_docker_compose_status || echo "Please install docker compose yourself") } function check_docker_compose_install() { check_compose_status || (check_docker_compose_status || get_compose_install) echo "The docker compose service is running normally" } function check_docker_install() { # check if "docker.tar.gz" exists, if not, echo an error message [ ! -f "${docker_file_dir}/docker.tar.gz" ] && echo "Error: ${docker_file_dir}/docker.tar.gz does not exist" && exit 1 # decompress "docker.tar.gz" into the current directory tar -zxf "docker.tar.gz" --directory "$(pwd)" if [ -x "$(command -v 'docker')" ]; then check_docker_status || (systemctl start docker 2>/dev/null || service docker start 2>/dev/null) check_docker_status || (get_docker_install ) check_docker_status && echo "The docker service is running normally" || echo "Please install docker yourself" else echo "It is detected that the system does not have docker service installed, try to install docker service" get_docker_install check_docker_status && echo "The docker service is running normally" || echo "Please install docker yourself" fi } # check if the script is run as root if [ "$(id -u)" != "0" ]; then echo "Error: This script must be run as root" 1>&2 exit 1 fi # check if the script is run in the current directory if [ "$(pwd)" != "$(dirname "$0")" ]; then echo "Error: This script must be run in the current directory" 1>&2 exit 1 fi # run the script check_docker_install check_docker_compose_install