2022-04-15 12:26:17 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-03-29 17:41:49 +00:00
|
|
|
|
2022-10-03 06:22:04 +00:00
|
|
|
OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"')"
|
|
|
|
SUB_OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID_LIKE=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"')"
|
|
|
|
|
|
|
|
function install_generic() {
|
|
|
|
local dependency="${1}"
|
|
|
|
local os="${2}"
|
|
|
|
|
|
|
|
if [[ "${os}" == "debian" ]]; then
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y "${dependency}"
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y "${dependency}"
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "centos" ]]; then
|
|
|
|
sudo yum install -y --allowerasing "${dependency}"
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "fedora" ]]; then
|
|
|
|
sudo dnf -y install "${dependency}"
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "arch" ]]; then
|
|
|
|
sudo pacman -Sy --noconfirm "${dependency}"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-06-11 11:22:33 +00:00
|
|
|
function install_docker() {
|
|
|
|
local os="${1}"
|
2022-06-20 07:15:37 +00:00
|
|
|
echo "Installing docker for os ${os}" >/dev/tty
|
2022-05-26 16:33:15 +00:00
|
|
|
|
2022-09-09 17:39:32 +00:00
|
|
|
if [[ "${os}" == "debian" ]]; then
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo apt-get update
|
2022-07-18 19:15:01 +00:00
|
|
|
sudo apt-get upgrade
|
2022-09-10 14:42:09 +00:00
|
|
|
sudo apt-get install -y ca-certificates curl gnupg lsb-release
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo mkdir -p /etc/apt/keyrings
|
|
|
|
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
|
|
|
sudo apt-get update
|
2022-06-08 21:18:00 +00:00
|
|
|
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
2022-06-20 07:15:37 +00:00
|
|
|
return 0
|
2022-09-13 12:46:10 +00:00
|
|
|
elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo apt-get update
|
2022-07-18 19:15:01 +00:00
|
|
|
sudo apt-get upgrade
|
2022-09-10 14:42:09 +00:00
|
|
|
sudo apt-get install -y ca-certificates curl gnupg lsb-release
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo mkdir -p /etc/apt/keyrings
|
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
|
|
|
|
sudo apt-get update
|
2022-06-08 21:18:00 +00:00
|
|
|
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
2022-06-20 07:15:37 +00:00
|
|
|
return 0
|
2022-09-09 17:39:32 +00:00
|
|
|
elif [[ "${os}" == "centos" ]]; then
|
2022-09-10 14:42:09 +00:00
|
|
|
sudo yum install -y yum-utils
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
|
|
|
|
sudo yum install -y --allowerasing docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
sudo systemctl start docker
|
|
|
|
sudo systemctl enable docker
|
2022-06-20 07:15:37 +00:00
|
|
|
return 0
|
2022-09-09 17:39:32 +00:00
|
|
|
elif [[ "${os}" == "fedora" ]]; then
|
2022-09-10 14:42:09 +00:00
|
|
|
sudo dnf -y install dnf-plugins-core
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
|
|
|
|
sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
sudo systemctl start docker
|
|
|
|
sudo systemctl enable docker
|
2022-06-20 07:15:37 +00:00
|
|
|
return 0
|
2022-09-09 17:39:32 +00:00
|
|
|
elif [[ "${os}" == "arch" ]]; then
|
2022-09-19 13:39:34 +00:00
|
|
|
sudo pacman -Sy --noconfirm docker docker-compose
|
2022-05-31 16:58:45 +00:00
|
|
|
sudo systemctl start docker.service
|
|
|
|
sudo systemctl enable docker.service
|
2022-06-20 07:15:37 +00:00
|
|
|
return 0
|
2022-06-11 11:22:33 +00:00
|
|
|
else
|
2022-06-20 07:15:37 +00:00
|
|
|
return 1
|
2022-06-11 11:22:33 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-09-19 13:15:44 +00:00
|
|
|
function update_docker() {
|
|
|
|
local os="${1}"
|
|
|
|
echo "Updating Docker for os ${os}" >/dev/tty
|
|
|
|
|
|
|
|
if [[ "${os}" == "debian" ]]; then
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "centos" ]]; then
|
|
|
|
sudo yum install -y --allowerasing docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "fedora" ]]; then
|
|
|
|
sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
|
|
|
return 0
|
|
|
|
elif [[ "${os}" == "arch" ]]; then
|
|
|
|
sudo pacman -Sy --noconfirm docker docker-compose
|
2022-09-09 17:24:15 +00:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-06-11 11:22:33 +00:00
|
|
|
if command -v docker >/dev/null; then
|
2022-09-19 13:15:44 +00:00
|
|
|
echo "Docker is already installed, ensuring Docker is fully up to date"
|
|
|
|
|
|
|
|
update_docker "${OS}"
|
|
|
|
docker_result=$?
|
|
|
|
|
|
|
|
if [[ docker_result -eq 0 ]]; then
|
|
|
|
echo "Docker is fully up to date"
|
|
|
|
else
|
|
|
|
echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
|
|
|
|
install_docker "${SUB_OS}"
|
|
|
|
docker_sub_result=$?
|
|
|
|
|
|
|
|
if [[ docker_sub_result -eq 0 ]]; then
|
|
|
|
echo "Docker is fully up to date"
|
|
|
|
else
|
|
|
|
echo "Your system ${SUB_OS} is not supported please update Docker manually"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2022-06-11 11:22:33 +00:00
|
|
|
else
|
2022-06-20 07:15:37 +00:00
|
|
|
install_docker "${OS}"
|
|
|
|
docker_result=$?
|
|
|
|
|
|
|
|
if [[ docker_result -eq 0 ]]; then
|
2022-09-19 13:15:44 +00:00
|
|
|
echo "Docker installed"
|
2022-05-31 16:58:45 +00:00
|
|
|
else
|
2022-06-20 07:15:37 +00:00
|
|
|
echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
|
|
|
|
install_docker "${SUB_OS}"
|
|
|
|
docker_sub_result=$?
|
2022-06-11 11:22:33 +00:00
|
|
|
|
2022-06-20 07:15:37 +00:00
|
|
|
if [[ docker_sub_result -eq 0 ]]; then
|
2022-09-19 13:15:44 +00:00
|
|
|
echo "Docker installed"
|
2022-06-11 11:22:33 +00:00
|
|
|
else
|
2022-06-20 07:15:37 +00:00
|
|
|
echo "Your system ${SUB_OS} is not supported please install docker manually"
|
2022-06-11 11:22:33 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2022-05-31 16:58:45 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-05-26 16:27:36 +00:00
|
|
|
|
2022-10-03 06:22:04 +00:00
|
|
|
function check_dependency_and_install() {
|
|
|
|
local dependency="${1}"
|
2022-09-09 17:24:15 +00:00
|
|
|
|
2022-10-03 06:22:04 +00:00
|
|
|
if ! command -v fswatch >/dev/null; then
|
|
|
|
echo "Installing ${dependency}"
|
|
|
|
install_generic "${dependency}" "${OS}"
|
|
|
|
install_result=$?
|
2022-09-09 17:24:15 +00:00
|
|
|
|
2022-10-03 06:22:04 +00:00
|
|
|
if [[ install_result -eq 0 ]]; then
|
|
|
|
echo "${dependency} installed"
|
2022-09-09 17:24:15 +00:00
|
|
|
else
|
2022-10-03 06:22:04 +00:00
|
|
|
echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
|
|
|
|
install_generic "${dependency}" "${SUB_OS}"
|
|
|
|
install_sub_result=$?
|
|
|
|
|
|
|
|
if [[ install_sub_result -eq 0 ]]; then
|
|
|
|
echo "${dependency} installed"
|
|
|
|
else
|
|
|
|
echo "Your system ${SUB_OS} is not supported please install ${dependency} manually"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-09-09 17:24:15 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-10-03 06:22:04 +00:00
|
|
|
}
|
2022-09-29 20:28:41 +00:00
|
|
|
|
2022-10-03 06:22:04 +00:00
|
|
|
check_dependency_and_install "jq"
|
|
|
|
check_dependency_and_install "fswatch"
|
|
|
|
check_dependency_and_install "openssl"
|