Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ NC='\033[0m' # No Color.
# Default ports.
DEFAULT_HTTP_PORT=80
DEFAULT_HTTPS_PORT=443
DEFAULT_DOCKER_CMD=docker
DEFAULT_USE_TIMEOUT=1

# Initialize variables with default values
HTTP_PORT=$DEFAULT_HTTP_PORT
HTTPS_PORT=$DEFAULT_HTTPS_PORT
DOCKER_CMD=$DEFAULT_DOCKER_CMD
USE_TIMEOUT=$DEFAULT_USE_TIMEOUT

# Parse command line options
while [ $# -gt 0 ]; do
Expand All @@ -36,11 +40,31 @@ while [ $# -gt 0 ]; do
exit 1
fi
;;
--docker-command)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
DOCKER_CMD=$2
shift 2
else
log_error "Error: Argument for $1 is missing"
exit 1
fi
;;
--use-timeout)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
USE_TIMEOUT=$2
shift 2
else
log_error "Error: Argument for $1 is missing"
exit 1
fi
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo "Available options:"
echo " --http-port PORT Specify custom HTTP port (default: $DEFAULT_HTTP_PORT)"
echo " --https-port PORT Specify custom HTTPS port (default: $DEFAULT_HTTPS_PORT)"
echo " --docker-command DOCKER_COMMAND Specify explicit location of the docker command (default: $DEFAULT_DOCKER_CMD)"
echo " --use-timeout (0 or 1) Run docker asynchronously with a timeout (default: $DEFAULT_USE_TIMEOUT)"
echo " -h, --help Show this help message"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a line in the help be added for use-timeout?

exit 0
;;
Expand Down Expand Up @@ -124,27 +148,27 @@ check_requirements_docker() {
log_info "Checking system requirements."

# Check if Docker is installed.
if ! command_exists docker; then
if ! command_exists $DOCKER_CMD; then
log_error "Docker is not installed. Please install Docker first."
log_info "Visit https://docs.docker.com/get-docker/ for installation instructions."
exit 1
fi

# Check that Docker is running and the user has permissions to use it.
if ! run_with_timeout 10 "docker ps"; then
if ! run_with_timeout 10 "$DOCKER_CMD ps"; then
log_error "Docker is either not running or this user doesn't have permission to use Docker. Make sure Docker is started. If Docker is running, it is likely the user doesn't have permission to use Docker. Either run the script as root or contact your system administrator."
exit 1
fi

# Check if Docker Compose is installed.
if ! run_with_timeout 10 "docker compose version"; then
if ! run_with_timeout 10 "$DOCKER_CMD compose version"; then
log_error "Docker is installed but Compose is not. Please install Docker Compose first."
log_info "Visit https://docs.docker.com/compose/install/ for installation instructions."
exit 1
fi

# Check Docker Compose version.
compose_version=$(docker compose version --short 2>/dev/null || docker-compose --version | awk '{print $3}')
compose_version=$($DOCKER_CMD compose version --short 2>/dev/null || docker-compose --version | awk '{print $3}')
compose_version=$(echo "$compose_version" | sed 's/[^0-9.]*//g')
if ! version_ge "$MIN_COMPOSE_VERSION" "$compose_version"; then
log_error "Docker Compose version $compose_version is too old. Please install Docker Compose version $MIN_COMPOSE_VERSION or higher."
Expand Down Expand Up @@ -302,14 +326,23 @@ check_ports() {

# Pull and start containers.
deploy_containers_docker() {
local use_timeout=$1

log_info "Pulling latest container images."
if ! output=$(run_with_timeout 300 docker compose pull 2>&1); then
if [ $use_timeout -eq 1 ] && ! output=$(run_with_timeout 300 $DOCKER_CMD compose pull 2>&1); then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work when running inside the macOS installer...

log_error "Failed to pull container images. Error: $output"
exit 1
elif [ $use_timeout -eq 0 ]; then
$DOCKER_CMD compose pull
local return_code=$?
if [ $return_code -ne 0 ]; then
log_error "Failed to pull container images directly."
exit 1
fi
fi

log_info "Starting containers."
if ! output=$(docker compose up -d 2>&1); then
if ! output=$($DOCKER_CMD compose up -d 2>&1); then
log_error "Failed to start containers. Error: $output"
exit 1
fi
Expand Down Expand Up @@ -374,7 +407,7 @@ main() {
if [ $(uname -m) = "ppc64le" ]; then
deploy_containers_podman
else
deploy_containers_docker
deploy_containers_docker $USE_TIMEOUT
fi

log_info "Installation completed successfully!"
Expand Down