log_error "Docker installation failed, please visit https://docs.docker.com/install for instructions."
exit 1
fi
log_start_step "Verifying Docker installation"
command_exists docker
}
function verify_docker_running(){
local STDERR_OUTPUT
STDERR_OUTPUT="$(docker info 2>&1 >/dev/null)"
local-irRET=$?
if(( RET == 0 ));then
return 0
elif[["${STDERR_OUTPUT}"==*"Is the docker daemon running"*]];then
start_docker
return
fi
return"${RET}"
}
function fetch(){
curl --silent--show-error--fail"$@"
}
function install_docker(){
(
# Change umask so that /usr/share/keyrings/docker-archive-keyring.gpg has the right permissions.
# See https://github.com/Jigsaw-Code/outline-server/issues/951.
# We do this in a subprocess so the umask for the calling process is unaffected.
umask 0022
fetch https://get.docker.com/ | sh
)>&2
}
function start_docker(){
systemctl enable--now docker.service >&2
}
function docker_container_exists(){
docker ps | grep--quiet"$1"
}
function remove_shadowbox_container(){
remove_docker_container "${CONTAINER_NAME}"
}
function remove_watchtower_container(){
remove_docker_container watchtower
}
function remove_docker_container(){
docker rm-f"$1">&2
}
function handle_docker_container_conflict(){
local-rCONTAINER_NAME="$1"
local-rEXIT_ON_NEGATIVE_USER_RESPONSE="$2"
local PROMPT="The container name \"${CONTAINER_NAME}\" is already in use by another container. This may happen when running this script multiple times."
PROMPT="${PROMPT} We will attempt to remove the existing container and restart it. Would you like to proceed?"
else
PROMPT="${PROMPT} Would you like to replace this container? If you answer no, we will proceed with the remainder of the installation."
fi
if! confirm "${PROMPT}";then
if${EXIT_ON_NEGATIVE_USER_RESPONSE};then
exit 0
fi
return 0
fi
if run_step "Removing ${CONTAINER_NAME} container""remove_${CONTAINER_NAME}_container";then
log_start_step "Restarting ${CONTAINER_NAME}"
"start_${CONTAINER_NAME}"
return$?
fi
return 1
}
# Set trap which publishes error tag only if there is an error.
function finish {
local-irEXIT_CODE=$?
if(( EXIT_CODE != 0 ));then
if[[-s"${LAST_ERROR}"]];then
log_error "\nLast error: $(< "${LAST_ERROR}")">&2
fi
log_error "\nSorry! Something went wrong. If you can't figure this out, please copy and paste all this output into the Outline Manager screen, and send it to us, to see if we can help you.">&2
log_error "Full log: ${FULL_LOG}">&2
else
rm"${FULL_LOG}"
fi
rm"${LAST_ERROR}"
}
function get_random_port {
local-inum=0 # Init to an invalid value, to prevent "unbound variable" errors.