configure.sh 5.9 KB

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