install-dependencies.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/bin/sh
  2. #
  3. # Script that installs the various dependencies of invidious
  4. #
  5. # Dependencies:
  6. # - crystal => Language in which Invidious is developed
  7. # - postgres => Database server
  8. # - git => required to clone Invidious
  9. # - librsvg2-bin => For login captcha (provides 'rsvg-convert')
  10. #
  11. # - libssl-dev => Used by Crystal's SSL module (standard library)
  12. # - libxml2-dev => Used by Crystal's XML module (standard library)
  13. # - libyaml-dev => Used by Crystal's YAML module (standard library)
  14. # - libgmp-dev => Used by Crystal's BigNumbers module (standard library)
  15. # - libevent-dev => Used by crystal's internal scheduler (?)
  16. # - libpcre3-dev => Used by Crystal's regex engine (?)
  17. #
  18. # - libsqlite3-dev => Used to open .db files from NewPipe exports
  19. # - zlib1g-dev => TBD
  20. # - libreadline-dev => TBD
  21. #
  22. #
  23. # Tested on:
  24. # - OpenSUSE Leap 15.3
  25. #
  26. # Load system details
  27. #
  28. if [ -e /etc/os-release ]; then
  29. . /etc/os-release
  30. elif [ -e /usr/lib/os-release ]; then
  31. . /usr/lib/os-release
  32. else
  33. echo "Unsupported Linux system"
  34. exit 2
  35. fi
  36. #
  37. # Some variables
  38. #
  39. repo_base_url="https://download.opensuse.org/repositories/devel:/languages:/crystal/"
  40. repo_end_url="devel:languages:crystal.repo"
  41. apt_gpg_key="/usr/share/keyrings/crystal.gpg"
  42. apt_list_file="/etc/apt/sources.list.d/crystal.list"
  43. yum_repo_file="/etc/yum.repos.d/crystal.repo"
  44. #
  45. # Major install functions
  46. #
  47. make_repo_url() {
  48. echo "${repo_base_url}/${1}/${repo_end_url}"
  49. }
  50. install_apt() {
  51. repo="$1"
  52. echo "Adding Crystal repository"
  53. curl -fsSL "${repo_base_url}/${repo}/Release.key" \
  54. | gpg --dearmor \
  55. | sudo tee "${apt_gpg_key}" > /dev/null
  56. echo "deb [signed-by=${apt_gpg_key}] ${repo_base_url}/${repo}/ /" \
  57. | sudo tee "$apt_list_file"
  58. sudo apt-get update
  59. sudo apt-get install --yes --no-install-recommends \
  60. libssl-dev libxml2-dev libyaml-dev libgmp-dev libevent-dev \
  61. libpcre3-dev libreadline-dev libsqlite3-dev zlib1g-dev \
  62. crystal postgresql-13 git librsvg2-bin make
  63. }
  64. install_yum() {
  65. repo=$(make_repo_url "$1")
  66. echo "Adding Crystal repository"
  67. cat << END | sudo tee "${yum_repo_file}" > /dev/null
  68. [crystal]
  69. name=Crystal
  70. type=rpm-md
  71. baseurl=${repo}/
  72. gpgcheck=1
  73. gpgkey=${repo}/repodata/repomd.xml.key
  74. enabled=1
  75. END
  76. sudo yum -y install \
  77. openssl-devel libxml2-devel libyaml-devel gmp-devel \
  78. readline-devel sqlite-devel \
  79. crystal postgresql postgresql-server git librsvg2-tools make
  80. }
  81. install_pacman() {
  82. # TODO: find an alternative to --no-confirm?
  83. sudo pacman -S --no-confirm \
  84. base-devel librsvg postgresql crystal
  85. }
  86. install_zypper()
  87. {
  88. repo=$(make_repo_url "$1")
  89. echo "Adding Crystal repository"
  90. sudo zypper --non-interactive addrepo -f "$repo"
  91. sudo zypper --non-interactive --gpg-auto-import-keys install --no-recommends \
  92. libopenssl-devel libxml2-devel libyaml-devel gmp-devel libevent-devel \
  93. pcre-devel readline-devel sqlite3-devel zlib-devel \
  94. crystal postgresql postgresql-server git rsvg-convert make
  95. }
  96. #
  97. # System-specific logic
  98. #
  99. case "$ID" in
  100. archlinux) install_pacman;;
  101. centos) install_dnf "CentOS_${VERSION_ID}";;
  102. debian)
  103. case "$VERSION_CODENAME" in
  104. sid) install_apt "Debian_Unstable";;
  105. bookworm) install_apt "Debian_Testing";;
  106. *) install_apt "Debian_${VERSION_ID}";;
  107. esac
  108. ;;
  109. fedora)
  110. if [ "$VERSION" == *"Prerelease"* ]; then
  111. install_dnf "Fedora_Rawhide"
  112. else
  113. install_dnf "Fedora_${VERSION}"
  114. fi
  115. ;;
  116. opensuse-leap) install_zypper "openSUSE_Leap_${VERSION}";;
  117. opensuse-tumbleweed) install_zypper "openSUSE_Tumbleweed";;
  118. rhel) install_dnf "RHEL_${VERSION_ID}";;
  119. ubuntu)
  120. # Small workaround for recently released 22.04
  121. case "$VERSION_ID" in
  122. 22.04) install_apt "xUbuntu_21.04";;
  123. *) install_apt "xUbuntu_${VERSION_ID}";;
  124. esac
  125. ;;
  126. *)
  127. # Try to match on ID_LIKE instead
  128. # Not guaranteed to 100% work
  129. case "$ID_LIKE" in
  130. archlinux) install_pacman;;
  131. centos) install_dnf "CentOS_${VERSION_ID}";;
  132. debian) install_apt "Debian_${VERSION_ID}";;
  133. *)
  134. echo "Error: distribution ${CODENAME} is not supported"
  135. echo "Please install dependencies manually"
  136. exit 2
  137. ;;
  138. esac
  139. ;;
  140. esac