crowdsec.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. YW=$(echo "\033[33m")
  7. BL=$(echo "\033[36m")
  8. RD=$(echo "\033[01;31m")
  9. BGN=$(echo "\033[4;92m")
  10. GN=$(echo "\033[1;92m")
  11. DGN=$(echo "\033[32m")
  12. CL=$(echo "\033[m")
  13. BFR="\\r\\033[K"
  14. HOLD="-"
  15. CM="${GN}✓${CL}"
  16. APP="CrowdSec"
  17. hostname="$(hostname)"
  18. set -o errexit
  19. set -o errtrace
  20. set -o nounset
  21. set -o pipefail
  22. shopt -s expand_aliases
  23. alias die='EXIT=$? LINE=$LINENO error_exit'
  24. trap die ERR
  25. function error_exit() {
  26. trap - ERR
  27. local reason="Unknown failure occured."
  28. local msg="${1:-$reason}"
  29. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  30. echo -e "$flag $msg" 1>&2
  31. exit $EXIT
  32. }
  33. if command -v pveversion >/dev/null 2>&1; then echo -e "⚠️ Can't Install on Proxmox "; exit; fi
  34. while true; do
  35. read -p "This will Install ${APP} on $hostname. Proceed(y/n)?" yn
  36. case $yn in
  37. [Yy]*) break ;;
  38. [Nn]*) exit ;;
  39. *) echo "Please answer yes or no." ;;
  40. esac
  41. done
  42. clear
  43. function header_info {
  44. echo -e "${BL}
  45. _____ _ _____
  46. / ____| | |/ ____|
  47. | | _ __ _____ ____| | (___ ___ ___
  48. | | | __/ _ \ \ /\ / / _ |\___ \ / _ \/ __|
  49. | |____| | | (_) \ V V / (_| |____) | __/ (__
  50. \_____|_| \___/ \_/\_/ \__ _|_____/ \___|\___|
  51. ${CL}"
  52. }
  53. header_info
  54. function msg_info() {
  55. local msg="$1"
  56. echo -ne " ${HOLD} ${YW}${msg}..."
  57. }
  58. function msg_ok() {
  59. local msg="$1"
  60. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  61. }
  62. msg_info "Setting up ${APP} Repository"
  63. apt-get update &>/dev/null
  64. apt-get install -y curl &>/dev/null
  65. apt-get install -y gnupg &>/dev/null
  66. curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | bash &>/dev/null
  67. msg_ok "Setup ${APP} Repository"
  68. msg_info "Installing ${APP}"
  69. apt-get update &>/dev/null
  70. apt-get install -y crowdsec &>/dev/null
  71. msg_ok "Installed ${APP} on $hostname"
  72. msg_info "Installing ${APP} Common Bouncer"
  73. apt-get install -y crowdsec-firewall-bouncer-iptables &>/dev/null
  74. msg_ok "Installed ${APP} Common Bouncer"
  75. msg_ok "Completed Successfully!\n"