install_dependencies.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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"
  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. KERNEL=$(uname)
  73. if [ $KERNEL = 'Darwin' ]; then
  74. echo -e "Detected OS: macOS"
  75. which brew
  76. if [ $? != 0 ]; then
  77. echo -e "Brew not found, please install it manually!"
  78. exit 1
  79. fi
  80. install_pkg_darwin
  81. install_pip
  82. exit 0
  83. elif [ $KERNEL = 'Linux' ]; then
  84. # Kernel is Linux, check for supported distributions
  85. OS=$(awk '/DISTRIB_ID=/' /etc/*-release | sed 's/DISTRIB_ID=//' | tr '[:upper:]' '[:lower:]')
  86. if [ $OS = 'arch' ]; then
  87. echo -e "Detected OS: Arch Linux"
  88. install_pkg_arch
  89. install_pip
  90. exit 0
  91. elif [ $OS = 'ubuntu' ]; then
  92. echo -e "Detected OS: Ubuntu"
  93. install_pkg_ubuntu
  94. install_pip
  95. exit 0
  96. fi
  97. fi
  98. echo -e "Your OS is not supported by this script, please make sure to install the dependencies manually"
  99. exit 0