3
0

install_dependencies.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. install_pkg_arch()
  3. {
  4. PACMAN_PKGS="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 cmake python3-dev python3-pip python3-venv sqlite tcpdump libtins-dev libpcap-dev'
  38. which sudo >/dev/null
  39. if [ $? != 0 ]; then
  40. # sudo wasn't found, so we use su
  41. SUDO="su -c "
  42. else
  43. SUDO=sudo
  44. fi
  45. # Check first to avoid unnecessary sudo
  46. echo -e "Packages: Checking..."
  47. dpkg -s $APT_PKGS &>/dev/null
  48. if [ $? != 0 ]; then
  49. # Install all missing packages
  50. echo -e "Packages: Installing..."
  51. $SUDO "apt-get install $APT_PKGS"
  52. else
  53. echo -e "Packages: Found."
  54. fi
  55. }
  56. install_pkg_darwin()
  57. {
  58. BREW_PKGS="cmake python coreutils libdnet libtins sqlite"
  59. # Check first to avoid unnecessary update
  60. echo -e "Packages: Checking..."
  61. brew ls --versions $BREW_PKGS &>/dev/null
  62. if [ $? != 0 ]; then
  63. # Install all missing packages
  64. echo -e "Packages: Installing..."
  65. brew install $BREW_PKGS
  66. else
  67. echo -e "Packages: Found."
  68. fi
  69. }
  70. # Make sure the submodules are there
  71. echo -e "Updating submodules"
  72. git submodule update --init
  73. KERNEL=$(uname)
  74. if [ "$KERNEL" = 'Darwin' ]; then
  75. echo -e "Detected OS: macOS"
  76. which brew >/dev/null
  77. if [ $? != 0 ]; then
  78. echo -e "Brew not found, please install it manually!"
  79. exit 1
  80. fi
  81. install_pkg_darwin
  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=//' | sed 's/"//g' | tr '[:upper:]' '[:lower:]')
  86. OS_LIKE=$(awk '/ID_LIKE=/' /etc/*-release | sed 's/ID_LIKE=//' | sed 's/"//g' | tr '[:upper:]' '[:lower:]')
  87. if [ -z "$OS_LIKE" ]; then
  88. # This distribution is missing the os-release file, so try lsb_release
  89. OS_LIKE=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
  90. fi
  91. case $OS_LIKE in
  92. archlinux|arch)
  93. echo -e "Detected OS: Arch Linux"
  94. install_pkg_arch
  95. exit 0
  96. ;;
  97. debian)
  98. echo -e "Detected OS: Debian"
  99. install_pkg_ubuntu
  100. exit 0
  101. ;;
  102. esac
  103. fi
  104. echo -e "Your OS is not supported by this script, please make sure to install the dependencies manually"
  105. exit 0