浏览代码

Update configure script to support all major linux distributions

Nicolas Meienberger 3 年之前
父节点
当前提交
578490d513
共有 2 个文件被更改,包括 50 次插入15 次删除
  1. 47 12
      scripts/configure.sh
  2. 3 3
      scripts/start.sh

+ 47 - 12
scripts/configure.sh

@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 #!/usr/bin/env bash
 set -e # Exit immediately if a command exits with a non-zero status.
 set -e # Exit immediately if a command exits with a non-zero status.
 
 
-ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
+ROOT_FOLDER="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/..)"
 
 
 echo
 echo
 echo "======================================"
 echo "======================================"
@@ -14,19 +14,54 @@ echo "=============== TIPI ================="
 echo "======================================"
 echo "======================================"
 echo
 echo
 
 
-sudo wget -O "${ROOT_FOLDER}"/scripts/pacapt https://github.com/icy/pacapt/raw/ng/pacapt
-sudo chmod 755 "${ROOT_FOLDER}"/scripts/pacapt
-sudo "${ROOT_FOLDER}"/scripts/pacapt -Sy
-sudo "${ROOT_FOLDER}"/scripts/pacapt -S docker docker-compose jq coreutils curl lsb-release -y
+OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"')"
 
 
-LSB="$(lsb_release -is)"
-
-systemctl start docker.service
-systemctl enable docker.service
+if ! command -v docker >/dev/null; then
+  echo "Docker is already installed"
+else
+  echo "Installing Docker"
+  if [[ "${OS}" == "debian" ]]; then
+    sudo apt-get update
+    sudo apt-get install ca-certificates curl gnupg lsb-release -y
+    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
+    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
+  elif [[ "${OS}" == "ubuntu" ]]; then
+    sudo apt-get update
+    sudo apt-get install ca-certificates curl gnupg lsb-release -y
+    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
+    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
+  elif [[ "${OS}" == "centos" ]]; then
+    sudo yum install -y yum-utils
+    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
+  elif [[ "${OS}" == "fedora" ]]; then
+    sudo dnf -y install dnf-plugins-core
+    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
+  elif [[ "${OS}" == "arch" ]]; then
+    sudo pacman -Sy --noconfirm docker
+    sudo systemctl start docker.service
+    sudo systemctl enable docker.service
+  else
+    echo "Your OS ${OS} is not supported by this script. Please install docker and docker-compose manually."
+    exit 1
+  fi
+fi
 
 
-# if [[ "${LSB}" == "Arch" ]]; then
-#   sudo "${ROOT_FOLDER}"/scripts/pacapt -S hostname -y
-# fi
+if ! command -v docker-compose >/dev/null; then
+  sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
+  sudo chmod +x /usr/local/bin/docker-compose
+fi
 
 
 # Create configured status
 # Create configured status
 touch "${ROOT_FOLDER}/state/configured"
 touch "${ROOT_FOLDER}/state/configured"

+ 3 - 3
scripts/start.sh

@@ -56,7 +56,7 @@ ROOT_FOLDER="$($readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
 STATE_FOLDER="${ROOT_FOLDER}/state"
 STATE_FOLDER="${ROOT_FOLDER}/state"
 SED_ROOT_FOLDER="$(echo $ROOT_FOLDER | sed 's/\//\\\//g')"
 SED_ROOT_FOLDER="$(echo $ROOT_FOLDER | sed 's/\//\\\//g')"
 
 
-NETWORK_INTERFACE="$(ip route | grep default | awk '{print $5}')"
+NETWORK_INTERFACE="$(ip route | grep default | awk '{print $5}' | uniq)"
 INTERNAL_IP="$(ip addr show "${NETWORK_INTERFACE}" | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
 INTERNAL_IP="$(ip addr show "${NETWORK_INTERFACE}" | grep "inet " | awk '{print $2}' | cut -d/ -f1)"
 # INTERNAL_IP="$(hostname -I | awk '{print $1}')"
 # INTERNAL_IP="$(hostname -I | awk '{print $1}')"
 DNS_IP=9.9.9.9 # Default to Quad9 DNS
 DNS_IP=9.9.9.9 # Default to Quad9 DNS
@@ -115,7 +115,7 @@ fi
 
 
 # Get current dns from host
 # Get current dns from host
 if [[ -f "/etc/resolv.conf" ]]; then
 if [[ -f "/etc/resolv.conf" ]]; then
-  TEMP=$(cat /etc/resolv.conf | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -n 1)
+  TEMP=$(grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' /etc/resolv.conf | head -n 1)
 fi
 fi
 
 
 # Get dns ip if pihole is installed
 # Get dns ip if pihole is installed
@@ -143,7 +143,7 @@ ENV_FILE=$(mktemp)
 
 
 JWT_SECRET=$(derive_entropy "jwt")
 JWT_SECRET=$(derive_entropy "jwt")
 
 
-for template in "${ENV_FILE}"; do
+for template in ${ENV_FILE}; do
   sed -i "s/<dns_ip>/${DNS_IP}/g" "${template}"
   sed -i "s/<dns_ip>/${DNS_IP}/g" "${template}"
   sed -i "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
   sed -i "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
   sed -i "s/<tz>/${TZ}/g" "${template}"
   sed -i "s/<tz>/${TZ}/g" "${template}"