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

@@ -182,7 +182,7 @@ WARNING_SPACE=false
if [ "$TOTAL_SPACE" -lt "$REQUIRED_TOTAL_SPACE" ]; then if [ "$TOTAL_SPACE" -lt "$REQUIRED_TOTAL_SPACE" ]; then
WARNING_SPACE=true WARNING_SPACE=true
cat << EOF cat <<EOF
WARNING: Insufficient total disk space! WARNING: Insufficient total disk space!
Total disk space: ${TOTAL_SPACE}GB Total disk space: ${TOTAL_SPACE}GB
@@ -193,7 +193,7 @@ EOF
fi fi
if [ "$AVAILABLE_SPACE" -lt "$REQUIRED_AVAILABLE_SPACE" ]; then if [ "$AVAILABLE_SPACE" -lt "$REQUIRED_AVAILABLE_SPACE" ]; then
cat << EOF cat <<EOF
WARNING: Insufficient available disk space! WARNING: Insufficient available disk space!
Available disk space: ${AVAILABLE_SPACE}GB Available disk space: ${AVAILABLE_SPACE}GB
@@ -201,7 +201,7 @@ Required available space: ${REQUIRED_AVAILABLE_SPACE}GB
================== ==================
EOF EOF
WARNING_SPACE=true WARNING_SPACE=true
fi fi
if [ "$WARNING_SPACE" = true ]; then if [ "$WARNING_SPACE" = true ]; then
@@ -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
@@ -699,7 +720,7 @@ fi
# Merge .env and .env.production. New values will be added to .env # Merge .env and .env.production. New values will be added to .env
echo -e "7. Propagating .env with new values - if necessary." echo -e "7. Propagating .env with new values - if necessary."
awk -F '=' '!seen[$1]++' "$ENV_FILE-$DATE" /data/coolify/source/.env.production > $ENV_FILE awk -F '=' '!seen[$1]++' "$ENV_FILE-$DATE" /data/coolify/source/.env.production >$ENV_FILE
if [ "$AUTOUPDATE" = "false" ]; then if [ "$AUTOUPDATE" = "false" ]; then
if ! grep -q "AUTOUPDATE=" /data/coolify/source/.env; then if ! grep -q "AUTOUPDATE=" /data/coolify/source/.env; then
@@ -745,7 +766,7 @@ if [ "$IS_COOLIFY_VOLUME_EXISTS" -eq 0 ]; then
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal -q -N "" -C coolify ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal -q -N "" -C coolify
chown 9999 /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal chown 9999 /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal
sed -i "/coolify/d" ~/.ssh/authorized_keys sed -i "/coolify/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub >> ~/.ssh/authorized_keys cat /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub >>~/.ssh/authorized_keys
rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub rm -f /data/coolify/ssh/keys/id.$CURRENT_USER@host.docker.internal.pub
fi fi