configure.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/usr/bin/env bash
  2. OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"')"
  3. SUB_OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID_LIKE=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"')"
  4. function install_generic() {
  5. local dependency="${1}"
  6. local os="${2}"
  7. if [[ "${os}" == "debian" ]]; then
  8. sudo apt-get update
  9. sudo apt-get install -y "${dependency}"
  10. return 0
  11. elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
  12. sudo apt-get update
  13. sudo apt-get install -y "${dependency}"
  14. return 0
  15. elif [[ "${os}" == "centos" ]]; then
  16. sudo yum install -y --allowerasing "${dependency}"
  17. return 0
  18. elif [[ "${os}" == "fedora" ]]; then
  19. sudo dnf -y install "${dependency}"
  20. return 0
  21. elif [[ "${os}" == "arch" ]]; then
  22. sudo pacman -Sy --noconfirm "${dependency}"
  23. return 0
  24. else
  25. return 1
  26. fi
  27. }
  28. function install_docker() {
  29. local os="${1}"
  30. echo "Installing docker for os ${os}" >/dev/tty
  31. if [[ "${os}" == "debian" ]]; then
  32. sudo apt-get update
  33. sudo apt-get upgrade
  34. sudo apt-get install -y ca-certificates curl gnupg lsb-release
  35. sudo mkdir -p /etc/apt/keyrings
  36. curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  37. 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
  38. sudo apt-get update
  39. sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  40. return 0
  41. elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
  42. sudo apt-get update
  43. sudo apt-get upgrade
  44. sudo apt-get install -y ca-certificates curl gnupg lsb-release
  45. sudo mkdir -p /etc/apt/keyrings
  46. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  47. 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
  48. sudo apt-get update
  49. sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  50. return 0
  51. elif [[ "${os}" == "centos" ]]; then
  52. sudo yum install -y yum-utils
  53. sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  54. sudo yum install -y --allowerasing docker-ce docker-ce-cli containerd.io docker-compose-plugin
  55. sudo systemctl start docker
  56. sudo systemctl enable docker
  57. return 0
  58. elif [[ "${os}" == "fedora" ]]; then
  59. sudo dnf -y install dnf-plugins-core
  60. sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
  61. sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  62. sudo systemctl start docker
  63. sudo systemctl enable docker
  64. return 0
  65. elif [[ "${os}" == "arch" ]]; then
  66. sudo pacman -Sy --noconfirm docker docker-compose
  67. sudo systemctl start docker.service
  68. sudo systemctl enable docker.service
  69. return 0
  70. else
  71. return 1
  72. fi
  73. }
  74. function update_docker() {
  75. local os="${1}"
  76. echo "Updating Docker for os ${os}" >/dev/tty
  77. if [[ "${os}" == "debian" ]]; then
  78. sudo apt-get update
  79. sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  80. return 0
  81. elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
  82. sudo apt-get update
  83. sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  84. return 0
  85. elif [[ "${os}" == "centos" ]]; then
  86. sudo yum install -y --allowerasing docker-ce docker-ce-cli containerd.io docker-compose-plugin
  87. return 0
  88. elif [[ "${os}" == "fedora" ]]; then
  89. sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  90. return 0
  91. elif [[ "${os}" == "arch" ]]; then
  92. sudo pacman -Sy --noconfirm docker docker-compose
  93. return 0
  94. else
  95. return 1
  96. fi
  97. }
  98. if command -v docker >/dev/null; then
  99. echo "Docker is already installed, ensuring Docker is fully up to date"
  100. update_docker "${OS}"
  101. docker_result=$?
  102. if [[ docker_result -eq 0 ]]; then
  103. echo "Docker is fully up to date"
  104. else
  105. echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
  106. install_docker "${SUB_OS}"
  107. docker_sub_result=$?
  108. if [[ docker_sub_result -eq 0 ]]; then
  109. echo "Docker is fully up to date"
  110. else
  111. echo "Your system ${SUB_OS} is not supported please update Docker manually"
  112. exit 1
  113. fi
  114. fi
  115. else
  116. install_docker "${OS}"
  117. docker_result=$?
  118. if [[ docker_result -eq 0 ]]; then
  119. echo "Docker installed"
  120. else
  121. echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
  122. install_docker "${SUB_OS}"
  123. docker_sub_result=$?
  124. if [[ docker_sub_result -eq 0 ]]; then
  125. echo "Docker installed"
  126. else
  127. echo "Your system ${SUB_OS} is not supported please install docker manually"
  128. exit 1
  129. fi
  130. fi
  131. fi
  132. function check_dependency_and_install() {
  133. local dependency="${1}"
  134. if ! command -v fswatch >/dev/null; then
  135. echo "Installing ${dependency}"
  136. install_generic "${dependency}" "${OS}"
  137. install_result=$?
  138. if [[ install_result -eq 0 ]]; then
  139. echo "${dependency} installed"
  140. else
  141. echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
  142. install_generic "${dependency}" "${SUB_OS}"
  143. install_sub_result=$?
  144. if [[ install_sub_result -eq 0 ]]; then
  145. echo "${dependency} installed"
  146. else
  147. echo "Your system ${SUB_OS} is not supported please install ${dependency} manually"
  148. exit 1
  149. fi
  150. fi
  151. fi
  152. }
  153. check_dependency_and_install "jq"
  154. check_dependency_and_install "fswatch"
  155. check_dependency_and_install "openssl"