install.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. set -e
  3. # Must be root
  4. if [[ $EUID -ne 0 ]]; then
  5. echo "Error: This script must be run as root."
  6. exit 1
  7. fi
  8. echo "Installing FirewallFalcon Manager..."
  9. # URLs (IPv4 forced to avoid GitHub IPv6 issues)
  10. MENU_URL="https://raw.githubusercontent.com/firewallfalcons/FirewallFalcon-Manager/main/menu.sh"
  11. SSHD_URL="https://raw.githubusercontent.com/firewallfalcons/FirewallFalcon-Manager/main/ssh"
  12. # Install menu
  13. wget -4 -q -O /usr/local/bin/menu "$MENU_URL"
  14. chmod +x /usr/local/bin/menu
  15. echo "Applying FirewallFalcon SSH configuration..."
  16. SSHD_CONFIG="/etc/ssh/sshd_config"
  17. BACKUP="/etc/ssh/sshd_config.backup.$(date +%F-%H%M%S)"
  18. # Backup current SSH config
  19. cp "$SSHD_CONFIG" "$BACKUP"
  20. # Download FirewallFalcon SSH config
  21. wget -4 -q -O "$SSHD_CONFIG" "$SSHD_URL"
  22. chmod 600 "$SSHD_CONFIG"
  23. # Validate SSH config (silent)
  24. if ! sshd -t 2>/dev/null; then
  25. echo "ERROR: SSH configuration is invalid!"
  26. echo "Restoring previous configuration..."
  27. cp "$BACKUP" "$SSHD_CONFIG"
  28. exit 1
  29. fi
  30. echo "SSH configuration validated."
  31. # Restart SSH quietly and safely
  32. restart_ssh() {
  33. if command -v systemctl >/dev/null 2>&1; then
  34. systemctl restart sshd 2>/dev/null \
  35. || systemctl restart ssh 2>/dev/null \
  36. || return 1
  37. elif command -v service >/dev/null 2>&1; then
  38. service sshd restart 2>/dev/null \
  39. || service ssh restart 2>/dev/null \
  40. || return 1
  41. elif command -v rc-service >/dev/null 2>&1; then
  42. rc-service sshd restart 2>/dev/null \
  43. || rc-service ssh restart 2>/dev/null \
  44. || return 1
  45. elif [ -x /etc/init.d/sshd ]; then
  46. /etc/init.d/sshd restart >/dev/null 2>&1
  47. elif [ -x /etc/init.d/ssh ]; then
  48. /etc/init.d/ssh restart >/dev/null 2>&1
  49. else
  50. return 1
  51. fi
  52. }
  53. if restart_ssh; then
  54. echo "SSH service restarted."
  55. else
  56. echo "WARNING: SSH restart not supported on this system."
  57. echo "SSH config applied but service was not restarted automatically."
  58. fi
  59. # Run FirewallFalcon setup
  60. bash /usr/local/bin/menu --install-setup
  61. echo "Installation complete!"
  62. echo "Type 'menu' to start."