refactor(install): clean up install script and enhance Docker installation logic

Refactored the install script to improve readability by removing unnecessary whitespace and consolidating Docker installation logic into a dedicated function. This change enhances maintainability and clarity, particularly for the installation process across different operating systems. Additionally, the script now includes specific handling for Ubuntu 24.10, ensuring users receive appropriate guidance for installation. Overall, these updates contribute to a more streamlined and user-friendly installation experience.
This commit is contained in:
Andras Bacsai
2025-03-14 13:20:45 +01:00
parent 2c845461c9
commit 9dbe221ad5

View File

@@ -283,7 +283,6 @@ if [ -z "$LATEST_REALTIME_VERSION" ]; then
LATEST_REALTIME_VERSION=latest LATEST_REALTIME_VERSION=latest
fi fi
case "$OS_TYPE" in case "$OS_TYPE" in
arch | ubuntu | debian | raspbian | centos | fedora | rhel | ol | rocky | sles | opensuse-leap | opensuse-tumbleweed | almalinux | amzn | alpine) ;; arch | ubuntu | debian | raspbian | centos | fedora | rhel | ol | rocky | sles | opensuse-leap | opensuse-tumbleweed | almalinux | amzn | alpine) ;;
*) *)
@@ -299,8 +298,6 @@ if [ "$1" != "" ]; then
LATEST_VERSION="${LATEST_VERSION#v}" LATEST_VERSION="${LATEST_VERSION#v}"
fi fi
echo -e "---------------------------------------------" echo -e "---------------------------------------------"
echo "| Operating System | $OS_TYPE $OS_VERSION" echo "| Operating System | $OS_TYPE $OS_VERSION"
echo "| Docker | $DOCKER_VERSION" echo "| Docker | $DOCKER_VERSION"
@@ -347,7 +344,6 @@ sles | opensuse-leap | opensuse-tumbleweed)
;; ;;
esac esac
echo -e "2. Check OpenSSH server configuration. " echo -e "2. Check OpenSSH server configuration. "
# Detect OpenSSH server # Detect OpenSSH server
@@ -370,7 +366,6 @@ elif [ -x "$(command -v service)" ]; then
fi fi
fi fi
if [ "$SSH_DETECTED" = "false" ]; then if [ "$SSH_DETECTED" = "false" ]; then
echo " - OpenSSH server not detected. Installing OpenSSH server." echo " - OpenSSH server not detected. Installing OpenSSH server."
case "$OS_TYPE" in case "$OS_TYPE" in
@@ -436,6 +431,18 @@ if [ -x "$(command -v snap)" ]; then
fi fi
fi fi
install_docker() {
curl -s https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh 2>&1
if ! [ -x "$(command -v docker)" ]; then
curl -s https://get.docker.com | sh -s -- --version ${DOCKER_VERSION} 2>&1
if ! [ -x "$(command -v docker)" ]; then
echo " - Docker installation failed."
echo " Maybe your OS is not supported?"
echo " - Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue."
exit 1
fi
fi
}
echo -e "3. Check Docker Installation. " echo -e "3. Check Docker Installation. "
if ! [ -x "$(command -v docker)" ]; then if ! [ -x "$(command -v docker)" ]; then
echo " - Docker is not installed. Installing Docker. It may take a while." echo " - Docker is not installed. Installing Docker. It may take a while."
@@ -500,22 +507,36 @@ if ! [ -x "$(command -v docker)" ]; then
systemctl start docker >/dev/null 2>&1 systemctl start docker >/dev/null 2>&1
systemctl enable docker >/dev/null 2>&1 systemctl enable docker >/dev/null 2>&1
;; ;;
*) "ubuntu" | "debian" | "raspbian")
if [ "$OS_TYPE" = "ubuntu" ] && [ "$OS_VERSION" = "24.10" ]; then if [ "$OS_TYPE" = "ubuntu" ] && [ "$OS_VERSION" = "24.10" ]; then
echo "Docker automated installation is not supported on Ubuntu 24.10 (non-LTS release)." echo " - Installing Docker for Ubuntu 24.10..."
echo "Please install Docker manually." apt-get update >/dev/null
exit 1 apt-get install -y ca-certificates curl >/dev/null
fi install -m 0755 -d /etc/apt/keyrings
curl -s https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh 2>&1 curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
if ! [ -x "$(command -v docker)" ]; then chmod a+r /etc/apt/keyrings/docker.asc
curl -s https://get.docker.com | sh -s -- --version ${DOCKER_VERSION} 2>&1
# Add the repository to Apt sources
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" |
tee /etc/apt/sources.list.d/docker.list >/dev/null
apt-get update >/dev/null
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin >/dev/null
if ! [ -x "$(command -v docker)" ]; then if ! [ -x "$(command -v docker)" ]; then
echo " - Docker installation failed." echo " - Docker installation failed."
echo " Maybe your OS is not supported?" echo " Please visit https://docs.docker.com/engine/install/ubuntu/ and install Docker manually to continue."
echo " - Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue."
exit 1 exit 1
fi fi
echo " - Docker installed successfully for Ubuntu 24.10."
else
install_docker
fi fi
;;
*)
install_docker
;;
esac esac
echo " - Docker installed successfully." echo " - Docker installed successfully."
else else