dependency_setup.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/sh
  2. set -e
  3. if [ "$(id -u)" != 0 ]; then
  4. SUDO="${SUDO:-$(command -v sudo)}"
  5. else
  6. SUDO="${SUDO:-}"
  7. fi
  8. brew_sh="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
  9. setup_mac() {
  10. if ! command -v brew >/dev/null; then
  11. echo "brew not found, installing..." >&2
  12. bash -c "$(curl -fL "${brew_sh}")" || return 1
  13. fi
  14. for i in cmake gcc jq pkgconf llvm@13; do
  15. echo "Installing $i with brew..." >&2
  16. brew install "$i" || return 1
  17. done
  18. }
  19. setup_apt() {
  20. apt_deps="git make jq gcc pkg-config libmpg123-dev"
  21. $1 install $apt_deps || return 1
  22. }
  23. setup_pacman() {
  24. pacman_deps="git make jq gcc pkgconf mpg123"
  25. $1 -Sy $pacman_deps || return 1
  26. }
  27. setup_xbps() {
  28. xbps_deps="git make jq gcc pkg-config"
  29. $1 -S $xbps_deps || return 1
  30. }
  31. setup_dnf() {
  32. dnf_deps="git make jq gcc pkg-config findutils lato-fonts"
  33. $1 install -y $dnf_deps || return 1
  34. }
  35. setup_apk() {
  36. apk_deps="git make jq gcc musl-dev"
  37. $1 add $apk_deps || return 1
  38. }
  39. setup_zypper() {
  40. zypper_deps="git make jq gcc pkg-config findutils"
  41. $1 install -y $zypper_deps || return 1
  42. }
  43. setup_emerge() {
  44. emerge_deps="dev-vcs/git app-misc/jq dev-util/pkgconf"
  45. $1 $emerge_deps || return 1
  46. }
  47. setup_pkg() {
  48. pkg_deps="git bash jq gcc findutils cantarell-fonts devel/pkgconf gmake devel/automake pulseaudio-module-sndio"
  49. $1 install -y $pkg_deps || return 1
  50. }
  51. setup_pkg_add() {
  52. pkg_add_deps="git bash jq gcc-11.2.0p6 findutils cantarell-fonts pkgconf gmake automake-1.15.1"
  53. $1 -I $pkg_add_deps || return 1
  54. }
  55. setup_pkgin() {
  56. pkgin_deps="git bash jq gcc12 findutils cantarell-fonts pkgconf gmake automake"
  57. $1 -y install $pkgin_deps || return 1
  58. }
  59. case "$(uname -s)" in
  60. Linux)
  61. if command -v apt >/dev/null; then
  62. echo "Setting up for apt" >&2
  63. setup_apt "$SUDO $(command -v apt)" || exit 1
  64. echo "Dependencies installed!" >&2
  65. exit 0
  66. fi
  67. if command -v apt-get >/dev/null; then
  68. echo "Setting up for apt-get" >&2
  69. setup_apt "$SUDO $(command -v apt-get)" || exit 1
  70. echo "Dependencies installed!" >&2
  71. exit 0
  72. fi
  73. if command -v pacman; then
  74. echo "Setting up for pacman" >&2
  75. setup_pacman "$SUDO $(command -v pacman)" || exit 1
  76. echo "Dependencies installed!" >&2
  77. exit 0
  78. fi
  79. if command -v xbps-install; then
  80. echo "Setting up for xbps" >&2
  81. setup_xbps "$SUDO $(command -v xbps-install)" || exit 1
  82. echo "Dependencies installed!" >&2
  83. exit 0
  84. fi
  85. if command -v dnf; then
  86. echo "Setting up for dnf" >&2
  87. setup_dnf "$SUDO $(command -v dnf)" || exit 1
  88. echo "Dependencies installed!" >&2
  89. exit 0
  90. fi
  91. if command -v apk; then
  92. echo "Setting up for apk" >&2
  93. setup_apk "$SUDO $(command -v apk)" || exit 1
  94. echo "Dependencies installed!" >&2
  95. exit 0
  96. fi
  97. if command -v zypper; then
  98. echo "Setting up for zypper" >&2
  99. setup_zypper "$SUDO $(command -v zypper)" || exit 1
  100. echo "Dependencies installed!" >&2
  101. exit 0
  102. fi
  103. if command -v emerge; then
  104. echo "Setting up for emerge" >&2
  105. setup_emerge "$SUDO $(command -v emerge)" || exit 1
  106. echo "Dependencies installed!" >&2
  107. exit 0
  108. fi
  109. echo "Error: Could not recognize your package manager." >&2
  110. exit 1
  111. ;;
  112. *BSD*)
  113. if command -v pkgin; then
  114. echo "Setting up for pkgin/NetBSD" >&2
  115. setup_pkgin "$SUDO $(command -v pkgin)" || exit 1
  116. elif command -v pkg; then
  117. echo "Setting up for pkg/FreeBSD" >&2
  118. setup_pkg "$SUDO $(command -v pkg)" || exit 1
  119. elif command -v pkg_add; then
  120. echo "Setting up for pkg_add/OpenBSD" >&2
  121. setup_pkg_add "$SUDO $(command -v pkg_add)" || exit 1
  122. echo "Rust support is not yet ready for OpenBSD, see https://github.com/rust-lang/rustup/issues/2168#issuecomment-1505185711"
  123. echo "You may try to compile rustc and cargo yourself or get the latest with:"
  124. echo "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly --default-host x86_64-unknown-openbsd"
  125. fi
  126. if command -v pkg || command -v pkg_add || command -v pkgin; then
  127. echo "Dependencies installed!" >&2
  128. cat <<'ENDOFCAT' >&2
  129. =======================
  130. Few more things may be needed:
  131. Install rust from https://www.rust-lang.org/tools/install
  132. Execute: rustup target add wasm32-unknown-unknown
  133. And apply few patches ...
  134. cd ..
  135. git clone --recurse-submodules -j8 https://github.com/stainless-steel/mpg123-sys
  136. cd ./mpg123-sys
  137. sed -e's/$(RM)/rm -f/g' -i.bak source/Makefile.in
  138. patch -p0 build.rs <<'EOF'
  139. 43a44
  140. > .arg(&format!("--with-audio=sndio"))
  141. EOF
  142. cargo build # to see if it works fine
  143. cd ../darkfi
  144. patch -p0 Cargo.toml <<'EOF'
  145. 329a330
  146. > mpg123-sys = { path = "../mpg123-sys" }
  147. EOF
  148. gmake test # no errors expected
  149. gmake
  150. ls -al darkfid ircd dnetview faucetd vanityaddr # list of built executables
  151. ENDOFCAT
  152. exit 0
  153. fi
  154. echo "Error: Could not recognize your package manager." >&2
  155. exit 1
  156. ;;
  157. Darwin)
  158. echo "Setting up for OSX" >&2
  159. setup_mac || exit 1
  160. echo "Dependencies installed!" >&2
  161. exit 0
  162. ;;
  163. ""|*)
  164. echo "Unsupported OS, sorry." >&2
  165. exit 1
  166. ;;
  167. esac