install.sh 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. echo "Installing runtipi..."
  6. ARCHITECTURE="$(uname -m)"
  7. # Not supported on 32 bits systems
  8. if [[ "$ARCHITECTURE" == "armv7"* ]] || [[ "$ARCHITECTURE" == "i686" ]] || [[ "$ARCHITECTURE" == "i386" ]]; then
  9. echo "runtipi is not supported on 32 bits systems"
  10. exit 1
  11. fi
  12. ### --------------------------------
  13. ### CLI arguments
  14. ### --------------------------------
  15. UPDATE="false"
  16. VERSION="latest"
  17. while [ -n "${1-}" ]; do
  18. case "$1" in
  19. --update) UPDATE="true" ;;
  20. --version)
  21. shift # Move to the next parameter
  22. VERSION="$1" # Assign the value to VERSION
  23. if [ -z "$VERSION" ]; then
  24. echo "Option --version requires a value" && exit 1
  25. fi
  26. ;;
  27. --)
  28. shift # The double dash makes them parameters
  29. break
  30. ;;
  31. *) echo "Option $1 not recognized" && exit 1 ;;
  32. esac
  33. shift
  34. done
  35. OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"')"
  36. SUB_OS="$(cat /etc/[A-Za-z]*[_-][rv]e[lr]* | grep "^ID_LIKE=" | cut -d= -f2 | uniq | tr '[:upper:]' '[:lower:]' | tr -d '"' || echo 'unknown')"
  37. function install_generic() {
  38. local dependency="${1}"
  39. local os="${2}"
  40. if [[ "${os}" == "debian" ]]; then
  41. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${dependency}"
  42. return 0
  43. elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
  44. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${dependency}"
  45. return 0
  46. elif [[ "${os}" == "centos" ]]; then
  47. sudo yum install -y --allowerasing "${dependency}"
  48. return 0
  49. elif [[ "${os}" == "fedora" ]]; then
  50. sudo dnf -y install "${dependency}"
  51. return 0
  52. elif [[ "${os}" == "arch" ]]; then
  53. if ! sudo pacman -Sy --noconfirm "${dependency}" ; then
  54. if command -v yay > /dev/null 2>&1 ; then
  55. sudo -u $SUDO_USER yay -Sy --noconfirm "${dependency}"
  56. else
  57. echo "Could not install \"${dependency}\", either using pacman or the yay AUR helper. Please try installing it manually."
  58. return 1
  59. fi
  60. fi
  61. return 0
  62. else
  63. return 1
  64. fi
  65. }
  66. function install_docker() {
  67. local os="${1}"
  68. echo "Installing docker for os ${os}"
  69. if [[ "${os}" == "debian" ]]; then
  70. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl gnupg lsb-release
  71. sudo mkdir -p /etc/apt/keyrings
  72. curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  73. 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
  74. sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
  75. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  76. return 0
  77. elif [[ "${os}" == "ubuntu" || "${os}" == "pop" ]]; then
  78. sudo DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl gnupg lsb-release
  79. sudo mkdir -p /etc/apt/keyrings
  80. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  81. 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
  82. sudo DEBIAN_FRONTEND=noninteractive apt-get update -y
  83. sudo DEBIAN_FRONTEND=noninteractive 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 yum-utils
  87. sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
  88. sudo yum install -y --allowerasing docker-ce docker-ce-cli containerd.io docker-compose-plugin
  89. sudo systemctl start docker
  90. sudo systemctl enable docker
  91. return 0
  92. elif [[ "${os}" == "fedora" ]]; then
  93. sudo dnf -y install dnf-plugins-core
  94. sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
  95. sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
  96. sudo systemctl start docker
  97. sudo systemctl enable docker
  98. return 0
  99. elif [[ "${os}" == "arch" ]]; then
  100. sudo pacman -Sy --noconfirm docker docker-compose
  101. sudo systemctl start docker.service
  102. sudo systemctl enable docker.service
  103. return 0
  104. else
  105. return 1
  106. fi
  107. }
  108. if ! command -v docker >/dev/null; then
  109. echo "Installing docker"
  110. install_docker "${OS}"
  111. docker_result=$?
  112. if [[ docker_result -eq 0 ]]; then
  113. echo "Docker installed"
  114. else
  115. echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
  116. install_docker "${SUB_OS}"
  117. docker_sub_result=$?
  118. if [[ docker_sub_result -eq 0 ]]; then
  119. echo "Docker installed"
  120. else
  121. echo "Your system ${SUB_OS} is not supported please install docker manually"
  122. exit 1
  123. fi
  124. fi
  125. fi
  126. function check_dependency_and_install() {
  127. local dependency="${1}"
  128. if ! command -v "${dependency}" >/dev/null; then
  129. echo "Installing ${dependency}"
  130. install_generic "${dependency}" "${OS}"
  131. install_result=$?
  132. if [[ install_result -eq 0 ]]; then
  133. echo "${dependency} installed"
  134. else
  135. echo "Your system ${OS} is not supported trying with sub_os ${SUB_OS}"
  136. install_generic "${dependency}" "${SUB_OS}"
  137. install_sub_result=$?
  138. if [[ install_sub_result -eq 0 ]]; then
  139. echo "${dependency} installed"
  140. else
  141. echo "Your system ${SUB_OS} is not supported please install ${dependency} manually"
  142. exit 1
  143. fi
  144. fi
  145. fi
  146. }
  147. # Example
  148. # check_dependency_and_install "openssl"
  149. # If version was not given it will install the latest version
  150. if [[ "${VERSION}" == "latest" ]]; then
  151. LATEST_VERSION=$(curl -s https://api.github.com/repos/meienberger/runtipi/releases/latest | grep tag_name | cut -d '"' -f4)
  152. VERSION="${LATEST_VERSION}"
  153. fi
  154. ASSET="runtipi-cli-linux-x64"
  155. if [ "$ARCHITECTURE" == "arm64" ] || [ "$ARCHITECTURE" == "aarch64" ]; then
  156. ASSET="runtipi-cli-linux-arm64"
  157. fi
  158. URL="https://github.com/meienberger/runtipi/releases/download/$VERSION/$ASSET"
  159. if [[ "${UPDATE}" == "false" ]]; then
  160. mkdir -p runtipi
  161. cd runtipi || exit
  162. fi
  163. curl --location "$URL" -o ./runtipi-cli
  164. chmod +x ./runtipi-cli
  165. # Check if user is in docker group
  166. if [ "$(id -u)" -ne 0 ]; then
  167. if ! groups | grep -q docker; then
  168. sudo usermod -aG docker "$USER"
  169. newgrp docker
  170. fi
  171. fi
  172. # Check if git is installed
  173. if ! command -v git >/dev/null; then
  174. echo "Git is not installed. Please install git and restart the script."
  175. exit 1
  176. fi
  177. ./runtipi-cli start