install_dependencies.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 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. install_pip()
  64. {
  65. PYTHON_MODULES="pyxdg lea numpy matplotlib scapy-python3 scipy coverage memory_profiler"
  66. echo -e "Python modules: Checking..."
  67. # Check first to avoid unnecessary sudo
  68. echo $PYTHON_MODULES | xargs -n 1 pip3 show >/dev/null
  69. if [ $? == 0 ]; then
  70. echo -e "Python modules: Found."
  71. return
  72. fi
  73. # Install all missing packages
  74. echo -e "Python modules: Installing..."
  75. if [ $KERNEL == 'Darwin' ]; then
  76. pip3 install $PYTHON_MODULES
  77. else
  78. sudo pip3 install $PYTHON_MODULES
  79. fi
  80. }
  81. # Make sure the SQLiteCpp submodule is there
  82. echo -e "Updating SQLiteCpp"
  83. git submodule update --init
  84. KERNEL=$(uname)
  85. if [ "$KERNEL" = 'Darwin' ]; then
  86. echo -e "Detected OS: macOS"
  87. which brew >/dev/null
  88. if [ $? != 0 ]; then
  89. echo -e "Brew not found, please install it manually!"
  90. exit 1
  91. fi
  92. install_pkg_darwin
  93. install_pip
  94. exit 0
  95. elif [ "$KERNEL" = 'Linux' ]; then
  96. # Kernel is Linux, check for supported distributions
  97. OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | sed 's/"//g' | tr '[:upper:]' '[:lower:]')
  98. OS_LIKE=$(awk '/ID_LIKE=/' /etc/*-release | sed 's/ID_LIKE=//' | sed 's/"//g' | tr '[:upper:]' '[:lower:]')
  99. if [ "$OS_LIKE" = 'archlinux' ]; then
  100. echo -e "Detected OS: Arch Linux"
  101. install_pkg_arch
  102. install_pip
  103. exit 0
  104. elif [ "$OS_LIKE" = 'debian' ]; then
  105. echo -e "Detected OS: Debian"
  106. install_pkg_ubuntu
  107. install_pip
  108. exit 0
  109. fi
  110. fi
  111. echo -e "Your OS is not supported by this script, please make sure to install the dependencies manually"
  112. exit 0