-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
128 lines (108 loc) · 3.69 KB
/
install.sh
File metadata and controls
128 lines (108 loc) · 3.69 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
128
#!/bin/bash
# cavlite Install Script
set -e
# Parse version argument (e.g., --v0.0.2)
VERSION=""
if [ $# -gt 0 ] && [[ "$1" == --v* ]]; then
VERSION="${1#--}" # Remove leading --
fi
if [ -z "$VERSION" ]; then
echo "🔍 Checking for latest version..."
VERSION=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/HexmosTech/cavlite/releases/latest | sed 's|.*/tag/||')
echo "✅ Latest version found: $VERSION"
fi
REPO_URL="https://github.com/HexmosTech/cavlite/releases/download/$VERSION"
INSTALL_PATH="/usr/local/bin/cavlite"
LIB_DIR="/usr/local/lib/cavlite"
CONFIG_DIR="/etc/cavlite"
CONFIG_FILE="$CONFIG_DIR/cavlite.conf"
CLAMAV_CONFIG_DIR="/etc/clamav"
# Determine backup directory
if [ -n "$SUDO_USER" ]; then
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
BACKUP_DIR="$USER_HOME/.cavlite/backup/clamav"
else
BACKUP_DIR="$HOME/.cavlite/backup/clamav"
fi
check_root() {
if [ "$EUID" -ne 0 ]; then
echo "❌ Please run as root (sudo ./install.sh)"
exit 1
fi
}
check_dependencies() {
echo "🔍 Checking dependencies..."
local dependencies=("python3" "curl" "clamscan" "lynis")
local missing=0
for dep in "${dependencies[@]}"; do
if ! command -v "$dep" &> /dev/null; then
echo "❌ Error: $dep is not installed."
echo "ℹ️ Please install $dep and try again."
missing=1
fi
done
if [ $missing -eq 1 ]; then
exit 1
fi
echo "✅ Dependencies found."
}
fetch_files() {
echo "⬇️ Downloading cavlite..."
# Download cavlite
if ! curl -fsSL "$REPO_URL/cavlite" -o "$INSTALL_PATH"; then
echo "❌ Error: Failed to download cavlite from GitHub."
exit 1
fi
chmod +x "$INSTALL_PATH"
# Setup Library Directory and Filter Script
echo "⚙️ Setting up library files..."
mkdir -p "$LIB_DIR"
if ! curl -fsSL "$REPO_URL/filter" -o "$LIB_DIR/filter"; then
echo "⚠️ Warning: Failed to download filter script."
fi
chmod +x "$LIB_DIR/filter"
}
setup_config() {
# Setup cavlite config
if [ ! -f "$CONFIG_FILE" ]; then
echo "⚙️ Setting up default configuration at $CONFIG_FILE"
mkdir -p "$CONFIG_DIR"
if ! curl -fsSL "$REPO_URL/cavlite.conf" -o "$CONFIG_FILE"; then
echo "⚠️ Warning: Failed to download default config."
fi
else
echo "⚠️ Configuration file already exists at $CONFIG_FILE. Skipping overwrite."
fi
# Setup ClamAV configs
echo "⚙️ Configuring ClamAV..."
# Create timestamped backup directory
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_PATH="$BACKUP_DIR/$TIMESTAMP"
mkdir -p "$BACKUP_PATH"
# Backup and replace clamd.conf
if [ -f "$CLAMAV_CONFIG_DIR/clamd.conf" ]; then
echo "📦 Backing up clamd.conf to $BACKUP_PATH/"
cp "$CLAMAV_CONFIG_DIR/clamd.conf" "$BACKUP_PATH/clamd.conf"
fi
if ! curl -fsSL "$REPO_URL/clamd.conf" -o "$CLAMAV_CONFIG_DIR/clamd.conf"; then
echo "⚠️ Warning: Failed to download clamd.conf."
fi
# Backup and replace freshclam.conf
if [ -f "$CLAMAV_CONFIG_DIR/freshclam.conf" ]; then
echo "📦 Backing up freshclam.conf to $BACKUP_PATH/"
cp "$CLAMAV_CONFIG_DIR/freshclam.conf" "$BACKUP_PATH/freshclam.conf"
fi
if ! curl -fsSL "$REPO_URL/freshclam.conf" -o "$CLAMAV_CONFIG_DIR/freshclam.conf"; then
echo "⚠️ Warning: Failed to download freshclam.conf."
fi
}
main() {
echo "🚀 Installing cavlite..."
check_root
check_dependencies
fetch_files
setup_config
echo "✅ Installation complete!"
echo "Run 'sudo cavlite --help' to get started."
}
main