crowdsec.sh 2.0 KB

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