install_dependencies.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. install_pkg_arch()
  3. {
  4. PACMAN_PKGS="boost boost-libs cmake python python-pip sqlite tcpdump"
  5. # Check first to avoid unnecessary sudo
  6. echo -e "Packages: Checking..."
  7. pacman -Qi $PACMAN_PKGS >/dev/null
  8. if [ $? != 0 ]; then
  9. # Install all missing packages
  10. echo -e "Packages: Installing..."
  11. sudo pacman -S --needed $PACMAN_PKGS
  12. else
  13. echo -e "Packages: Found."
  14. fi
  15. # libtins is not provided by Arch repos, check seperately
  16. echo -e "Additional Packages: Checking..."
  17. pacman -Qi libtins >/dev/null
  18. if [ $? != 0 ]; then
  19. echo -e "Additional Packages: Installing..."
  20. pushd /tmp
  21. # Download fresh copy of libtins
  22. wget "https://aur.archlinux.org/cgit/aur.git/snapshot/libtins.tar.gz"
  23. tar -xzf libtins.tar.gz
  24. rm libtins.tar.gz
  25. rm -R libtins
  26. pushd libtins
  27. # Build and install
  28. makepkg -si
  29. popd
  30. popd
  31. else
  32. echo -e "Additional Packages: Found."
  33. fi
  34. }
  35. install_pkg_ubuntu()
  36. {
  37. APT_PKGS="build-essential libboost-dev libboost-python-dev cmake python3-dev python3-pip python3-venv sqlite tcpdump libtins-dev libpcap-dev"
  38. # Check first to avoid unnecessary sudo
  39. echo -e "Packages: Checking..."
  40. dpkg -s $APT_PKGS &>/dev/null
  41. if [ $? != 0 ]; then
  42. # Install all missing packages
  43. echo -e "Packages: Installing..."
  44. sudo apt-get install $APT_PKGS
  45. else
  46. echo -e "Packages: Found."
  47. fi
  48. }
  49. install_pkg_darwin()
  50. {
  51. BREW_PKGS="cmake python coreutils libdnet libtins sqlite boost boost-python --with-python3"
  52. # Check first to avoid unnecessary update
  53. echo -e "Packages: Checking..."
  54. brew ls --versions $BREW_PKGS &>/dev/null
  55. if [ $? != 0 ]; then
  56. # Install all missing packages
  57. echo -e "Packages: Installing..."
  58. brew install $BREW_PKGS
  59. else
  60. echo -e "Packages: Found."
  61. fi
  62. }
  63. # Make sure the SQLiteCpp submodule is there
  64. echo -e "Updating SQLiteCpp"
  65. git submodule update --init
  66. KERNEL=$(uname)
  67. if [ "$KERNEL" = 'Darwin' ]; then
  68. echo -e "Detected OS: macOS"
  69. which brew >/dev/null
  70. if [ $? != 0 ]; then
  71. echo -e "Brew not found, please install it manually!"
  72. exit 1
  73. fi
  74. install_pkg_darwin
  75. exit 0
  76. elif [ "$KERNEL" = 'Linux' ]; then
  77. # Kernel is Linux, check for supported distributions
  78. OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | sed 's/"//g' | tr '[:upper:]' '[:lower:]')
  79. OS_LIKE=$(awk '/ID_LIKE=/' /etc/*-release | sed 's/ID_LIKE=//' | sed 's/"//g' | tr '[:upper:]' '[:lower:]')
  80. if [ "$OS_LIKE" = 'archlinux' ]; then
  81. echo -e "Detected OS: Arch Linux"
  82. install_pkg_arch
  83. exit 0
  84. elif [ "$OS_LIKE" = 'debian' ]; then
  85. echo -e "Detected OS: Debian"
  86. install_pkg_ubuntu
  87. exit 0
  88. fi
  89. fi
  90. echo -e "Your OS is not supported by this script, please make sure to install the dependencies manually"
  91. exit 0