-
Notifications
You must be signed in to change notification settings - Fork 258
Expand file tree
/
Copy pathinstaller.sh
More file actions
127 lines (108 loc) · 3.2 KB
/
Copy pathinstaller.sh
File metadata and controls
127 lines (108 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -euo pipefail
# Config
CSF_URL="https://github.com/Black-HOST/csf/releases/latest/download/csf.tgz"
INSTALL_DIR="/usr/src"
CSF_DIR="${INSTALL_DIR}/csf"
# Color Output Helpers
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
NC="\033[0m" # No Color
info() { echo -e "${BLUE}[+]${NC} $1"; }
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
error() { echo -e "${RED}[-]${NC} $1"; }
success() { echo -e "${GREEN}[✓]${NC} $1"; }
# Root Check
info "Checking root permissions..."
if [[ $EUID -ne 0 ]]; then
error "This installer must be run as root."
exit 1
fi
# Detect Package Manager
detect_package_manager() {
if command -v apt-get &> /dev/null; then echo "apt"
elif command -v dnf &> /dev/null; then echo "dnf"
elif command -v yum &> /dev/null; then echo "yum"
else echo ""; fi
}
# Install a package quietly
install_package() {
local pkg="$1"
local PM
PM=$(detect_package_manager)
case "$PM" in
apt)
DEBIAN_FRONTEND=noninteractive apt-get update -qq >/dev/null || true
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq $pkg >/dev/null
info "Debian"
;;
dnf|yum)
"$PM" install -y -q $pkg >/dev/null
info "DNF"
;;
*)
warn "Unsupported package manager. Please ensure '$pkg' is installed manually."
;;
esac
}
# Download file using curl or wget
fetch() {
local url="$1"
local dest="$2"
if command -v curl &> /dev/null; then
curl -fsSL "$url" -o "$dest"
elif command -v wget &> /dev/null; then
wget -q "$url" -O "$dest"
fi
}
# Install Dependencies
install_dependencies() {
local PM
PM=$(detect_package_manager)
info "Installing dependencies..."
if [[ "$PM" == "apt" ]]; then
install_package "wget curl tar perl libwww-perl liblwp-protocol-https-perl libgd-graph-perl iptables host unzip sendmail"
elif [[ "$PM" == "yum" || "$PM" == "dnf" ]]; then
install_package "--allowerasing wget tar curl perl perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph perl-Math-BigInt.noarch iptables bind-utils unzip sendmail"
else
warn "Could not detect package manager. Skipping dependency installation."
fi
}
# Main Installation
install_csf() {
info "Preparing installation directory..."
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
if [[ -f "csf.tgz" ]]; then
info "Removing old csf.tgz..."
rm -f csf.tgz
fi
info "Downloading CSF..."
fetch "$CSF_URL" "csf.tgz"
info "Extracting CSF..."
tar -xzf csf.tgz
if [[ ! -d "$CSF_DIR" ]]; then
error "Extraction failed. Directory $CSF_DIR not found."
exit 1
fi
info "Running CSF install script..."
cd "$CSF_DIR"
sh install.sh
}
# Verify Installation
verify_install() {
info "Verifying installation..."
if [[ -f "/usr/local/csf/bin/csftest.pl" ]]; then
perl /usr/local/csf/bin/csftest.pl
success "Installation script completed."
else
error "Verification failed. /usr/local/csf/bin/csftest.pl not found."
exit 1
fi
}
# Execution Flow
install_dependencies
install_csf
verify_install