coolify/scripts/install.sh

174 lines
6.2 KiB
Bash
Raw Normal View History

2023-04-27 11:29:02 +02:00
#!/bin/bash
2023-06-23 13:24:06 +02:00
## Do not modify this file. You will lose the ability to install and auto-update!
2023-04-28 14:39:14 +02:00
VERSION="1.1.0"
2023-09-05 15:43:56 +02:00
DOCKER_VERSION="24.0"
2023-05-03 09:57:06 +02:00
2023-06-06 09:22:48 +02:00
CDN="https://cdn.coollabs.io/coolify"
2023-04-28 15:30:42 +02:00
OS_TYPE=$(cat /etc/os-release | grep -w "ID" | cut -d "=" -f 2 | tr -d '"')
OS_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2 | tr -d '"')
2023-06-06 09:22:48 +02:00
LATEST_VERSION=$(curl --silent $CDN/versions.json | grep -i version | sed -n '2p' | xargs | awk '{print $2}' | tr -d ',')
DATE=$(date +"%Y%m%d-%H%M%S")
2023-04-27 14:45:45 +02:00
2023-05-03 09:01:58 +02:00
if [ $EUID != 0 ]; then
2023-04-27 11:29:02 +02:00
echo "Please run as root"
exit
fi
2023-11-28 10:46:00 +01:00
case "$OS_TYPE" in
ubuntu | debian | raspbian | centos | fedora | rhel | ol | rocky | sles | opensuse-leap | opensuse-tumbleweed) ;;
*)
echo "This script only supports Debian, Redhat or Sles based operating systems for now."
2023-06-16 21:42:11 +02:00
exit
;;
esac
2023-06-16 21:42:11 +02:00
2023-06-23 13:22:29 +02:00
# Ovewrite LATEST_VERSION if user pass a version number
if [ "$1" != "" ]; then
LATEST_VERSION=$1
fi
2023-06-16 21:42:11 +02:00
echo -e "-------------"
echo -e "Welcome to Coolify v4 beta installer!"
echo -e "This script will install everything for you."
echo -e "(Source code: https://github.com/coollabsio/coolify/blob/main/scripts/install.sh)\n"
echo -e "-------------"
echo "OS: $OS_TYPE $OS_VERSION"
echo "Coolify version: $LATEST_VERSION"
echo -e "-------------"
echo "Installing required packages..."
case "$OS_TYPE" in
ubuntu | debian | raspbian)
apt update -y >/dev/null 2>&1
apt install -y curl wget git jq >/dev/null 2>&1
;;
centos | fedora | rhel | ol | rocky)
dnf install -y curl wget git jq >/dev/null 2>&1
;;
sles | opensuse-leap | opensuse-tumbleweed)
zypper refresh >/dev/null 2>&1
zypper install -y curl wget git jq >/dev/null 2>&1
;;
*)
echo "This script only supports Debian, Redhat or Sles based operating systems for now."
exit
;;
esac
2023-04-27 11:29:02 +02:00
if ! [ -x "$(command -v docker)" ]; then
echo "Docker is not installed. Installing Docker."
2023-05-03 09:57:06 +02:00
curl https://releases.rancher.com/install-docker/${DOCKER_VERSION}.sh | sh
if [ -x "$(command -v docker)" ]; then
echo "Docker installed successfully."
else
echo "Docker installation failed with Rancher script. Trying with official script."
curl https://get.docker.com | sh -s -- --version ${DOCKER_VERSION}
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
fi
2023-11-28 10:46:00 +01:00
fi
2023-04-27 11:29:02 +02:00
fi
2023-06-16 21:42:11 +02:00
echo -e "-------------"
2023-06-19 13:08:34 +02:00
echo -e "Check Docker Configuration..."
2023-06-16 21:42:11 +02:00
mkdir -p /etc/docker
2023-06-19 13:08:34 +02:00
test -s /etc/docker/daemon.json && cp /etc/docker/daemon.json /etc/docker/daemon.json.original-$DATE || cat >/etc/docker/daemon.json <<EOL
2023-06-16 21:42:11 +02:00
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
EOL
cat >/etc/docker/daemon.json.coolify <<EOL
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
EOL
cat <<<$(jq . /etc/docker/daemon.json.coolify) >/etc/docker/daemon.json.coolify
cat <<<$(jq -s '.[0] * .[1]' /etc/docker/daemon.json /etc/docker/daemon.json.coolify) >/etc/docker/daemon.json
2023-09-28 13:05:17 +02:00
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))
if [ "$DIFF" != "" ]; then
echo "Docker configuration updated, restart docker daemon..."
systemctl restart docker
else
echo "Docker configuration is up to date."
fi
else
2023-06-19 13:08:34 +02:00
echo "Docker configuration updated, restart docker daemon..."
systemctl restart docker
fi
2023-06-16 21:42:11 +02:00
echo -e "-------------"
2023-04-27 11:29:02 +02:00
2023-05-25 13:29:15 +02:00
mkdir -p /data/coolify/ssh/keys
mkdir -p /data/coolify/ssh/mux
2023-04-27 11:29:02 +02:00
mkdir -p /data/coolify/source
2023-05-26 09:53:30 +02:00
mkdir -p /data/coolify/proxy/dynamic
2023-04-27 11:29:02 +02:00
chown -R 9999:root /data/coolify
chmod -R 700 /data/coolify
2023-04-27 11:29:02 +02:00
2023-04-28 15:30:42 +02:00
echo "Downloading required files from CDN..."
2023-04-28 13:50:27 +02:00
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/.env.production -o /data/coolify/source/.env.production
curl -fsSL $CDN/upgrade.sh -o /data/coolify/source/upgrade.sh
2023-04-27 11:29:02 +02:00
# Copy .env.example if .env does not exist
if [ ! -f /data/coolify/source/.env ]; then
2023-04-27 14:50:42 +02:00
cp /data/coolify/source/.env.production /data/coolify/source/.env
2023-06-16 21:42:11 +02:00
sed -i "s|APP_ID=.*|APP_ID=$(openssl rand -hex 16)|g" /data/coolify/source/.env
2023-04-27 11:29:02 +02:00
sed -i "s|APP_KEY=.*|APP_KEY=base64:$(openssl rand -base64 32)|g" /data/coolify/source/.env
sed -i "s|DB_PASSWORD=.*|DB_PASSWORD=$(openssl rand -base64 32)|g" /data/coolify/source/.env
2023-05-10 09:26:25 +02:00
sed -i "s|REDIS_PASSWORD=.*|REDIS_PASSWORD=$(openssl rand -base64 32)|g" /data/coolify/source/.env
2023-12-05 12:13:57 +01:00
# sed -i "s|PUSHER_APP_ID=.*|PUSHER_APP_ID=$(openssl rand -hex 32)|g" /data/coolify/source/.env
# sed -i "s|PUSHER_APP_KEY=.*|PUSHER_APP_KEY=$(openssl rand -hex 32)|g" /data/coolify/source/.env
# sed -i "s|PUSHER_APP_SECRET=.*|PUSHER_APP_SECRET=$(openssl rand -hex 32)|g" /data/coolify/source/.env
2023-04-27 11:29:02 +02:00
fi
2023-06-12 14:47:42 +02:00
# Merge .env and .env.production. New values will be added to .env
2023-06-16 21:42:11 +02:00
sort -u -t '=' -k 1,1 /data/coolify/source/.env /data/coolify/source/.env.production | sed '/^$/d' >/data/coolify/source/.env.temp && mv /data/coolify/source/.env.temp /data/coolify/source/.env
2023-06-12 14:47:42 +02:00
2023-06-23 09:47:36 +02:00
# Generate an ssh key (ed25519) at /data/coolify/ssh/keys/id.root@host.docker.internal
2023-05-25 13:29:15 +02:00
if [ ! -f /data/coolify/ssh/keys/id.root@host.docker.internal ]; then
2023-06-23 09:47:36 +02:00
ssh-keygen -t ed25519 -a 100 -f /data/coolify/ssh/keys/id.root@host.docker.internal -q -N "" -C root@coolify
2023-05-25 13:29:15 +02:00
chown 9999 /data/coolify/ssh/keys/id.root@host.docker.internal
2023-04-27 11:29:02 +02:00
fi
addSshKey() {
2023-06-16 21:42:11 +02:00
cat /data/coolify/ssh/keys/id.root@host.docker.internal.pub >>~/.ssh/authorized_keys
2023-04-27 11:29:02 +02:00
chmod 600 ~/.ssh/authorized_keys
}
2023-04-27 14:45:45 +02:00
if [ ! -f ~/.ssh/authorized_keys ]; then
2023-04-27 11:29:02 +02:00
mkdir -p ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys
addSshKey
fi
2023-04-27 14:45:45 +02:00
2023-04-27 11:29:02 +02:00
if [ -z "$(grep -w "root@coolify" ~/.ssh/authorized_keys)" ]; then
addSshKey
fi
2023-04-28 15:30:42 +02:00
bash /data/coolify/source/upgrade.sh ${LATEST_VERSION:-latest}
2023-06-16 21:42:11 +02:00
echo -e "\nCongratulations! Your Coolify instance is ready to use.\n"
echo "Please visit http://$(curl -4s https://ifconfig.io):8000 to get started."