fix: update Coolify installer

This commit is contained in:
Andras Bacsai
2024-09-16 14:37:19 +02:00
parent 3fd41c0a92
commit 62a4d7055a
2 changed files with 235 additions and 137 deletions

View File

@@ -1,7 +1,7 @@
{ {
"coolify": { "coolify": {
"v4": { "v4": {
"version": "4.0.0-beta.335" "version": "4.0.0-beta.336"
}, },
"nightly": { "nightly": {
"version": "4.0.0-beta.337" "version": "4.0.0-beta.337"

View File

@@ -5,11 +5,23 @@ set -e # Exit immediately if a command exits with a non-zero status
## $1 could be empty, so we need to disable this check ## $1 could be empty, so we need to disable this check
#set -u # Treat unset variables as an error and exit #set -u # Treat unset variables as an error and exit
set -o pipefail # Cause a pipeline to return the status of the last command that exited with a non-zero status set -o pipefail # Cause a pipeline to return the status of the last command that exited with a non-zero status
DATE=$(date +"%Y%m%d-%H%M%S")
VERSION="1.4" VERSION="1.5"
DOCKER_VERSION="26.0" DOCKER_VERSION="26.0"
CDN="https://cdn.coollabs.io/coolify" mkdir -p /data/coolify/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance,metrics,logs}
mkdir -p /data/coolify/ssh/{keys,mux}
mkdir -p /data/coolify/proxy/dynamic
chown -R 9999:root /data/coolify
chmod -R 700 /data/coolify
INSTALLATION_LOG_WITH_DATE="/data/coolify/source/installation-${DATE}.log"
exec > >(tee -a $INSTALLATION_LOG_WITH_DATE) 2>&1
CDN="https://cdn.coollabs.io/coolify-nightly"
OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"') OS_TYPE=$(grep -w "ID" /etc/os-release | cut -d "=" -f 2 | tr -d '"')
ENV_FILE="/data/coolify/source/.env" ENV_FILE="/data/coolify/source/.env"
@@ -46,12 +58,16 @@ fi
LATEST_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $2}' | tr -d ',') LATEST_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $2}' | tr -d ',')
LATEST_HELPER_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $6}' | tr -d ',') LATEST_HELPER_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $6}' | tr -d ',')
LATEST_REALTIME_VERSION=$(curl --silent $CDN/versions.json | grep -i version | xargs | awk '{print $8}' | tr -d ',')
if [ -z "$LATEST_HELPER_VERSION" ]; then if [ -z "$LATEST_HELPER_VERSION" ]; then
LATEST_HELPER_VERSION=latest LATEST_HELPER_VERSION=latest
fi fi
DATE=$(date +"%Y%m%d-%H%M%S") if [ -z "$LATEST_REALTIME_VERSION" ]; then
LATEST_REALTIME_VERSION=latest
fi
if [ $EUID != 0 ]; then if [ $EUID != 0 ]; then
echo "Please run as root" echo "Please run as root"
@@ -73,18 +89,29 @@ if [ "$1" != "" ]; then
LATEST_VERSION="${LATEST_VERSION#v}" LATEST_VERSION="${LATEST_VERSION#v}"
fi fi
echo -e "-------------" echo -e "\033[0;35m"
echo -e "Welcome to Coolify v4 beta installer!" cat << "EOF"
echo -e "This script will install everything for you." _____ _ _ __
/ ____| | (_)/ _|
| | ___ ___ | |_| |_ _ _
| | / _ \ / _ \| | | _| | | |
| |___| (_) | (_) | | | | | |_| |
\_____\___/ \___/|_|_|_| \__, |
__/ |
|___/
EOF
echo -e "\033[0m"
echo -e "Welcome to Coolify Installer!"
echo -e "This script will install everything for you. Sit back and relax."
echo -e "Source code: https://github.com/coollabsio/coolify/blob/main/scripts/install.sh\n" echo -e "Source code: https://github.com/coollabsio/coolify/blob/main/scripts/install.sh\n"
echo -e "-------------" echo -e "---------------------------------------------"
echo "| Operating System | $OS_TYPE $OS_VERSION"
echo "OS: $OS_TYPE $OS_VERSION" echo "| Docker | $DOCKER_VERSION"
echo "Coolify version: $LATEST_VERSION" echo "| Coolify | $LATEST_VERSION"
echo "Helper version: $LATEST_HELPER_VERSION" echo "| Helper | $LATEST_HELPER_VERSION"
echo "| Realtime | $LATEST_REALTIME_VERSION"
echo -e "-------------" echo -e "---------------------------------------------\n"
echo "Installing required packages..." echo -e "1. Installing required packages (curl, wget, git, jq). "
case "$OS_TYPE" in case "$OS_TYPE" in
arch) arch)
@@ -122,24 +149,26 @@ sles | opensuse-leap | opensuse-tumbleweed)
;; ;;
esac esac
echo -e "2. Check OpenSSH server configuration. "
# Detect OpenSSH server # Detect OpenSSH server
SSH_DETECTED=false SSH_DETECTED=false
if [ -x "$(command -v systemctl)" ]; then if [ -x "$(command -v systemctl)" ]; then
if systemctl status sshd >/dev/null 2>&1; then if systemctl status sshd >/dev/null 2>&1; then
echo "OpenSSH server is installed." echo " - OpenSSH server is installed."
SSH_DETECTED=true SSH_DETECTED=true
fi elif systemctl status ssh >/dev/null 2>&1; then
if systemctl status ssh >/dev/null 2>&1; then echo " - OpenSSH server is installed."
echo "OpenSSH server is installed."
SSH_DETECTED=true SSH_DETECTED=true
fi fi
elif [ -x "$(command -v service)" ]; then elif [ -x "$(command -v service)" ]; then
if service sshd status >/dev/null 2>&1; then if service sshd status >/dev/null 2>&1; then
echo "OpenSSH server is installed." echo " - OpenSSH server is installed."
SSH_DETECTED=true SSH_DETECTED=true
fi elif service ssh status >/dev/null 2>&1; then
if service ssh status >/dev/null 2>&1; then echo " - OpenSSH server is installed."
echo "OpenSSH server is installed."
SSH_DETECTED=true SSH_DETECTED=true
fi fi
fi fi
@@ -151,104 +180,90 @@ if [ "$SSH_DETECTED" = "false" ]; then
fi fi
# Detect SSH PermitRootLogin # Detect SSH PermitRootLogin
SSH_PERMIT_ROOT_LOGIN=false SSH_PERMIT_ROOT_LOGIN=$(sshd -T | grep -i "permitrootlogin" | awk '{print $2}') || true
SSH_PERMIT_ROOT_LOGIN_CONFIG=$(grep "^PermitRootLogin" /etc/ssh/sshd_config | awk '{print $2}') || SSH_PERMIT_ROOT_LOGIN_CONFIG="N/A (commented out or not found at all)" if [ "$SSH_PERMIT_ROOT_LOGIN" = "yes" ] || [ "$SSH_PERMIT_ROOT_LOGIN" = "without-password" ] || [ "$SSH_PERMIT_ROOT_LOGIN" = "prohibit-password" ]; then
if [ "$SSH_PERMIT_ROOT_LOGIN_CONFIG" = "prohibit-password" ] || [ "$SSH_PERMIT_ROOT_LOGIN_CONFIG" = "yes" ] || [ "$SSH_PERMIT_ROOT_LOGIN_CONFIG" = "without-password" ]; then echo " - SSH PermitRootLogin is enabled."
echo "PermitRootLogin is enabled." else
SSH_PERMIT_ROOT_LOGIN=true echo " - SSH PermitRootLogin is disabled."
fi echo " If you have problems with SSH, please read this: https://coolify.io/docs/knowledge-base/server/openssh"
if [ "$SSH_PERMIT_ROOT_LOGIN" != "true" ]; then
echo "###############################################################################"
echo "WARNING: PermitRootLogin is not enabled in /etc/ssh/sshd_config."
echo -e "It is set to $SSH_PERMIT_ROOT_LOGIN_CONFIG. Should be prohibit-password, yes or without-password.\n"
echo -e "Please make sure it is set, otherwise Coolify cannot connect to the host system. \n"
echo "###############################################################################"
fi fi
# Detect if docker is installed via snap # Detect if docker is installed via snap
if [ -x "$(command -v snap)" ]; then if [ -x "$(command -v snap)" ]; then
if snap list | grep -q docker; then SNAP_DOCKER_INSTALLED=$(snap list docker >/dev/null 2>&1 && echo "true" || echo "false")
echo "Docker is installed via snap." if [ "$SNAP_DOCKER_INSTALLED" = "true" ]; then
echo "Please note that Coolify does not support Docker installed via snap." echo " - Docker is installed via snap."
echo "Please remove Docker with snap (snap remove docker) and reexecute this script." echo " Please note that Coolify does not support Docker installed via snap."
echo " Please remove Docker with snap (snap remove docker) and reexecute this script."
exit 1 exit 1
fi fi
fi fi
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."
case "$OS_TYPE" in case "$OS_TYPE" in
"almalinux") "almalinux")
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo >/dev/null 2>&1
dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin dnf install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin >/dev/null 2>&1
if ! [ -x "$(command -v docker)" ]; then if ! [ -x "$(command -v docker)" ]; then
echo "Docker could not be installed automatically. Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue." echo " - Docker could not be installed automatically. Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue."
exit 1 exit 1
fi fi
systemctl start docker systemctl start docker >/dev/null 2>&1
systemctl enable docker systemctl enable docker >/dev/null 2>&1
;; ;;
"alpine") "alpine")
apk add docker docker-cli-compose apk add docker docker-cli-compose >/dev/null 2>&1
rc-update add docker default rc-update add docker default >/dev/null 2>&1
service docker start service docker start >/dev/null 2>&1
if [ -x "$(command -v docker)" ]; then if ! [ -x "$(command -v docker)" ]; then
echo "Docker installed successfully." echo " - Failed to install Docker with apk. Try to install it manually."
else echo " Please visit https://wiki.alpinelinux.org/wiki/Docker for more information."
echo "Failed to install Docker with apk. Try to install it manually." exit 1
echo "Please visit https://wiki.alpinelinux.org/wiki/Docker for more information."
exit
fi fi
;; ;;
"arch") "arch")
pacman -Sy docker docker-compose --noconfirm pacman -Sy docker docker-compose --noconfirm >/dev/null 2>&1
systemctl enable docker.service systemctl enable docker.service >/dev/null 2>&1
if [ -x "$(command -v docker)" ]; then if ! [ -x "$(command -v docker)" ]; then
echo "Docker installed successfully." echo " - Failed to install Docker with pacman. Try to install it manually."
else echo " Please visit https://wiki.archlinux.org/title/docker for more information."
echo "Failed to install Docker with pacman. Try to install it manually." exit 1
echo "Please visit https://wiki.archlinux.org/title/docker for more information."
exit
fi fi
;; ;;
"amzn") "amzn")
dnf install docker -y dnf install docker -y >/dev/null 2>&1
DOCKER_CONFIG=${DOCKER_CONFIG:-/usr/local/lib/docker} DOCKER_CONFIG=${DOCKER_CONFIG:-/usr/local/lib/docker}
mkdir -p $DOCKER_CONFIG/cli-plugins mkdir -p $DOCKER_CONFIG/cli-plugins >/dev/null 2>&1
curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o $DOCKER_CONFIG/cli-plugins/docker-compose curl -sL https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o $DOCKER_CONFIG/cli-plugins/docker-compose >/dev/null 2>&1
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose >/dev/null 2>&1
systemctl start docker systemctl start docker >/dev/null 2>&1
systemctl enable docker systemctl enable docker >/dev/null 2>&1
if [ -x "$(command -v docker)" ]; then if ! [ -x "$(command -v docker)" ]; then
echo "Docker installed successfully." echo " - Failed to install Docker with dnf. Try to install it manually."
else echo " Please visit https://www.cyberciti.biz/faq/how-to-install-docker-on-amazon-linux-2/ for more information."
echo "Failed to install Docker with dnf. Try to install it manually." exit 1
echo "Please visit https://www.cyberciti.biz/faq/how-to-install-docker-on-amazon-linux-2/ for more information."
exit
fi fi
;; ;;
*) *)
# Automated Docker installation curl -s https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh >/dev/null 2>&1
curl https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh if ! [ -x "$(command -v docker)" ]; then
if [ -x "$(command -v docker)" ]; then curl -s https://get.docker.com | sh -s -- --version ${DOCKER_VERSION} >/dev/null 2>&1
echo "Docker installed successfully." if ! [ -x "$(command -v docker)" ]; then
else echo " - Docker installation failed."
echo "Docker installation failed with Rancher script. Trying with official script." echo " Maybe your OS is not supported?"
curl https://get.docker.com | sh -s -- --version ${DOCKER_VERSION} echo " - Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue."
if [ -x "$(command -v docker)" ]; then
echo "Docker installed successfully."
else
echo "Docker installation failed with official script."
echo "Maybe your OS is not supported?"
echo "Please visit https://docs.docker.com/engine/install/ and install Docker manually to continue."
exit 1 exit 1
fi fi
fi fi
esac esac
echo " - Docker installed successfully."
else
echo " - Docker is installed."
fi fi
echo -e "-------------" echo -e "4. Check Docker Configuration. "
echo -e "Check Docker Configuration..."
mkdir -p /etc/docker mkdir -p /etc/docker
# shellcheck disable=SC2015 # shellcheck disable=SC2015
test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json /etc/docker/daemon.json.original-"$DATE" || cat >/etc/docker/daemon.json <<EOL test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json /etc/docker/daemon.json.original-"$DATE" || cat >/etc/docker/daemon.json <<EOL
@@ -277,34 +292,33 @@ fi
mv "$TEMP_FILE" /etc/docker/daemon.json mv "$TEMP_FILE" /etc/docker/daemon.json
restart_docker_service() { restart_docker_service() {
# Check if systemctl is available # Check if systemctl is available
if command -v systemctl >/dev/null 2>&1; then if command -v systemctl >/dev/null 2>&1; then
echo "Using systemctl to restart Docker..." echo " - Using systemctl to restart Docker."
systemctl restart docker systemctl restart docker
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Docker restarted successfully using systemctl." echo " - Docker restarted successfully using systemctl."
else else
echo "Failed to restart Docker using systemctl." echo " - Failed to restart Docker using systemctl."
return 1 return 1
fi fi
# Check if service command is available # Check if service command is available
elif command -v service >/dev/null 2>&1; then elif command -v service >/dev/null 2>&1; then
echo "Using service command to restart Docker..." echo " - Using service command to restart Docker."
service docker restart service docker restart
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Docker restarted successfully using service." echo " - Docker restarted successfully using service."
else else
echo "Failed to restart Docker using service." echo " - Failed to restart Docker using service."
return 1 return 1
fi fi
# If neither systemctl nor service is available # If neither systemctl nor service is available
else else
echo "Neither systemctl nor service command is available on this system." echo " - Neither systemctl nor service command is available on this system."
return 1 return 1
fi fi
} }
@@ -312,39 +326,30 @@ restart_docker_service() {
if [ -s /etc/docker/daemon.json.original-"$DATE" ]; then if [ -s /etc/docker/daemon.json.original-"$DATE" ]; then
DIFF=$(diff <(jq --sort-keys . /etc/docker/daemon.json) <(jq --sort-keys . /etc/docker/daemon.json.original-"$DATE")) DIFF=$(diff <(jq --sort-keys . /etc/docker/daemon.json) <(jq --sort-keys . /etc/docker/daemon.json.original-"$DATE"))
if [ "$DIFF" != "" ]; then if [ "$DIFF" != "" ]; then
echo "Docker configuration updated, restart docker daemon..." echo " - Docker configuration updated, restart docker daemon..."
restart_docker_service restart_docker_service
else else
echo "Docker configuration is up to date." echo " - Docker configuration is up to date."
fi fi
else else
echo "Docker configuration updated, restart docker daemon..." echo " - Docker configuration updated, restart docker daemon..."
restart_docker_service restart_docker_service
fi fi
echo -e "-------------" echo -e "5. Download required files from CDN. "
mkdir -p /data/coolify/{source,ssh,applications,databases,backups,services,proxy,webhooks-during-maintenance,metrics,logs}
mkdir -p /data/coolify/ssh/{keys,mux}
mkdir -p /data/coolify/proxy/dynamic
chown -R 9999:root /data/coolify
chmod -R 700 /data/coolify
echo "Downloading required files from CDN..."
curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml curl -fsSL $CDN/docker-compose.yml -o /data/coolify/source/docker-compose.yml
curl -fsSL $CDN/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml curl -fsSL $CDN/docker-compose.prod.yml -o /data/coolify/source/docker-compose.prod.yml
curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production curl -fsSL $CDN/.env.production -o /data/coolify/source/.env.production
curl -fsSL $CDN/upgrade.sh -o /data/coolify/source/upgrade.sh curl -fsSL $CDN/upgrade.sh -o /data/coolify/source/upgrade.sh
echo -e "6. Make backup of .env to .env-$DATE"
# Copy .env.example if .env does not exist # Copy .env.example if .env does not exist
if [ -f $ENV_FILE ]; then if [ -f $ENV_FILE ]; then
echo "File exists: $ENV_FILE"
echo "Copying .env to .env-$DATE"
cp $ENV_FILE $ENV_FILE-$DATE cp $ENV_FILE $ENV_FILE-$DATE
else else
echo "File does not exist: $ENV_FILE" echo " - File does not exist: $ENV_FILE"
echo "Copying .env.production to .env-$DATE" echo " - Copying .env.production to .env-$DATE"
cp /data/coolify/source/.env.production $ENV_FILE-$DATE cp /data/coolify/source/.env.production $ENV_FILE-$DATE
# Generate a secure APP_ID and APP_KEY # Generate a secure APP_ID and APP_KEY
sed -i "s|^APP_ID=.*|APP_ID=$(openssl rand -hex 16)|" "$ENV_FILE-$DATE" sed -i "s|^APP_ID=.*|APP_ID=$(openssl rand -hex 16)|" "$ENV_FILE-$DATE"
@@ -365,7 +370,7 @@ else
fi 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 "Updating .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
@@ -375,37 +380,130 @@ if [ "$AUTOUPDATE" = "false" ]; then
sed -i "s|AUTOUPDATE=.*|AUTOUPDATE=false|g" /data/coolify/source/.env sed -i "s|AUTOUPDATE=.*|AUTOUPDATE=false|g" /data/coolify/source/.env
fi fi
fi fi
echo -e "8. Checking for SSH key for localhost access."
# Generate an ssh key (ed25519) at /data/coolify/ssh/keys/id.root@host.docker.internal
if [ ! -f /data/coolify/ssh/keys/id.root@host.docker.internal ]; then
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.root@host.docker.internal -q -N "" -C root@coolify
chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal
fi
addSshKey() {
cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >>~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
}
if [ ! -f ~/.ssh/authorized_keys ]; then if [ ! -f ~/.ssh/authorized_keys ]; then
mkdir -p ~/.ssh mkdir -p ~/.ssh
chmod 700 ~/.ssh chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys touch ~/.ssh/authorized_keys
addSshKey chmod 600 ~/.ssh/authorized_keys
fi fi
if ! grep -qw "root@coolify" ~/.ssh/authorized_keys; then checkSshKeyInAuthorizedKeys() {
addSshKey grep -qw "root@coolify" ~/.ssh/authorized_keys
return $?
}
checkSshKeyInCoolifyData() {
[ -s /data/coolify/ssh/keys/id.root@host.docker.internal ]
return $?
}
generateAuthorizedKeys() {
sed -i "/root@coolify/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys
rm -f /data/coolify/ssh/keys/id.root@host.docker.internal.pub
}
generateSshKey() {
echo " - Generating SSH key."
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.root@host.docker.internal -q -N "" -C root@coolify
chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal
generateAuthorizedKeys
}
syncSshKeys() {
DB_RUNNING=$(docker inspect coolify-db --format '{{ .State.Status }}' 2>/dev/null)
# Check if SSH key exists in Coolify data but not in authorized_keys
if checkSshKeyInCoolifyData && ! checkSshKeyInAuthorizedKeys; then
# Add the existing Coolify SSH key to authorized_keys
cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys
# Check if SSH key exists in authorized_keys but not in Coolify data
elif checkSshKeyInAuthorizedKeys && ! checkSshKeyInCoolifyData; then
# Ensure Coolify DB is running before proceeding
if [ "$DB_RUNNING" = "running" ]; then
# Retrieve DB user and SSH key from Coolify database
DB_USER=$(docker inspect coolify-db --format '{{ .Config.Env }}' | grep -oP 'POSTGRES_USER=\K[^ ]+')
DB_SSH_KEY=$(docker exec coolify-db psql -U $DB_USER -d coolify -t -c "SELECT \"private_key\" FROM \"private_keys\" WHERE id = 0 AND team_id = 0 LIMIT 1;" -A -t)
if [ -z "$DB_SSH_KEY" ]; then
# If no key found in DB, generate a new one
echo " - SSH key not found in database. Generating new key."
generateSshKey
else
# If key found in DB, save it and update authorized_keys
echo " - SSH key found in database. Saving to file."
echo "$DB_SSH_KEY" > /data/coolify/ssh/keys/id.root@host.docker.internal
chmod 600 /data/coolify/ssh/keys/id.root@host.docker.internal
chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal
# Generate public key from private key and update authorized_keys
ssh-keygen -y -f /data/coolify/ssh/keys/id.root@host.docker.internal -C root@coolify > /data/coolify/ssh/keys/id.root@host.docker.internal.pub
sed -i "/root@coolify/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys
rm -f /data/coolify/ssh/keys/id.root@host.docker.internal.pub
chmod 600 ~/.ssh/authorized_keys
fi
fi
# If SSH key doesn't exist in either location
elif ! checkSshKeyInAuthorizedKeys && ! checkSshKeyInCoolifyData; then
# Ensure Coolify DB is running before proceeding
if [ "$DB_RUNNING" = "running" ]; then
# Retrieve DB user and SSH key from Coolify database
DB_USER=$(docker inspect coolify-db --format '{{ .Config.Env }}' | grep -oP 'POSTGRES_USER=\K[^ ]+')
DB_SSH_KEY=$(docker exec coolify-db psql -U $DB_USER -d coolify -t -c "SELECT \"private_key\" FROM \"private_keys\" WHERE id = 0 AND team_id = 0 LIMIT 1;" -A -t)
if [ -z "$DB_SSH_KEY" ]; then
# If no key found in DB, generate a new one
echo " - SSH key not found in database. Generating new key."
generateSshKey
else
# If key found in DB, save it and update authorized_keys
echo " - SSH key found in database. Saving to file."
echo "$DB_SSH_KEY" > /data/coolify/ssh/keys/id.root@host.docker.internal
chmod 600 /data/coolify/ssh/keys/id.root@host.docker.internal
ssh-keygen -y -f /data/coolify/ssh/keys/id.root@host.docker.internal -C root@coolify > /data/coolify/ssh/keys/id.root@host.docker.internal.pub
sed -i "/root@coolify/d" ~/.ssh/authorized_keys
cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >> ~/.ssh/authorized_keys
fi
else
generateSshKey
fi
fi
}
syncSshKeys || true
chown -R 9999:root /data/coolify
chmod -R 700 /data/coolify
echo -e "9. Installing Coolify ($LATEST_VERSION)"
echo -e " - It could take a while based on your server's performance, network speed, stars, etc."
echo -e " - Please wait."
JOKES=$(curl -s https://v2.jokeapi.dev/joke/Programming?format=txt&type=single&amount=1 || true)
if [ "$JOKES" != "" ]; then
echo -e " - Until then, here's a joke for you:\n"
echo -e "$JOKES\n"
fi fi
bash /data/coolify/source/upgrade.sh "${LATEST_VERSION:-latest}" "${LATEST_HELPER_VERSION:-latest}" bash /data/coolify/source/upgrade.sh "${LATEST_VERSION:-latest}" "${LATEST_HELPER_VERSION:-latest}" >/dev/null 2>&1
echo " - Coolify installed successfully."
rm -f $ENV_FILE-$DATE rm -f $ENV_FILE-$DATE
echo "Waiting for 20 seconds for Coolify to be ready..."
echo " - Waiting for 20 seconds for Coolify (database migrations) to be ready."
JOKES=$(curl -s https://v2.jokeapi.dev/joke/Programming?format=txt&type=single&amount=1 || true)
if [ "$JOKES" != "" ]; then
echo -e " - Until then, here's a joke for you:\n"
echo -e "$JOKES\n"
fi
sleep 20 sleep 20
echo "Please visit http://$(curl -4s https://ifconfig.io):8000 to get started." echo -e "\033[0;35m
echo -e "\nCongratulations! Your Coolify instance is ready to use.\n" ____ _ _ _ _ _
/ ___|___ _ __ __ _ _ __ __ _| |_ _ _| | __ _| |_(_) ___ _ __ ___| |
echo -e "Make sure you backup your /data/coolify/source/.env file to a safe location, outside of this server.\n" | | / _ \| '_ \ / _\` | '__/ _\` | __| | | | |/ _\` | __| |/ _ \| '_ \/ __| |
| |__| (_) | | | | (_| | | | (_| | |_| |_| | | (_| | |_| | (_) | | | \__ \_|
\____\___/|_| |_|\__, |_| \__,_|\__|\__,_|_|\__,_|\__|_|\___/|_| |_|___(_)
|___/
\033[0m"
echo -e "\nYour instance is ready to use."
echo -e "Please visit http://$(curl -4s https://ifconfig.io):8000 to get started.\n"
echo -e "WARNING: We recommend you backup your /data/coolify/source/.env file to a safe location, outside of this server."
cp /data/coolify/source/.env /data/coolify/source/.env.backup cp /data/coolify/source/.env /data/coolify/source/.env.backup
echo -e "Your .env file has been copied to /data/coolify/source/.env.backup\n"