install_dependencies.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. echo -e "Installing: Packages"
  52. brew install cmake python coreutils libdnet libtins boost boost-python --with-python3
  53. }
  54. install_pip()
  55. {
  56. PYTHON_MODULES="lea numpy matplotlib scapy-python3 scipy coverage"
  57. echo -e "Python modules: Checking..."
  58. # Check first to avoid unnecessary sudo
  59. echo $PYTHON_MODULES | xargs -n 1 pip3 show >/dev/null
  60. if [ $? == 0 ]; then
  61. echo -e "Python modules: Found."
  62. return
  63. fi
  64. # Install all missing packages
  65. echo -e "Python modules: Installing..."
  66. if [ $KERNEL == 'Darwin' ]; then
  67. pip3 install $PYTHON_MODULES
  68. else
  69. sudo pip3 install $PYTHON_MODULES
  70. fi
  71. }
  72. # Make sure the SQLiteCpp submodule is there
  73. echo -e "Updating SQLiteCpp"
  74. git submodule update --init
  75. KERNEL=$(uname)
  76. if [ "$KERNEL" = 'Darwin' ]; then
  77. echo -e "Detected OS: macOS"
  78. which brew
  79. if [ $? != 0 ]; then
  80. echo -e "Brew not found, please install it manually!"
  81. exit 1
  82. fi
  83. install_pkg_darwin
  84. install_pip
  85. exit 0
  86. elif [ "$KERNEL" = 'Linux' ]; then
  87. # Kernel is Linux, check for supported distributions
  88. OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]')
  89. if [ "$OS" = 'arch' ]; then
  90. echo -e "Detected OS: Arch Linux"
  91. install_pkg_arch
  92. install_pip
  93. exit 0
  94. elif [ "$OS" = 'ubuntu' ]; then
  95. echo -e "Detected OS: Ubuntu"
  96. install_pkg_ubuntu
  97. install_pip
  98. exit 0
  99. fi
  100. fi
  101. echo -e "Your OS is not supported by this script, please make sure to install the dependencies manually"
  102. exit 0