-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·88 lines (74 loc) · 2.38 KB
/
install.sh
File metadata and controls
executable file
·88 lines (74 loc) · 2.38 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
#!/bin/bash
# udwall Install Script
set -e
# Parse version argument (e.g., --v0.0.2)
# 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/udwall/releases/latest | sed 's|.*/tag/||')
echo "✅ Latest version found: $VERSION"
fi
REPO_URL="https://raw.githubusercontent.com/HexmosTech/udwall/$VERSION"
INSTALL_PATH="/usr/local/bin/udwall"
CONFIG_DIR="/etc/udwall"
CONFIG_FILE="$CONFIG_DIR/udwall.conf"
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" "ufw" "curl")
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_script() {
echo "⬇️ Downloading udwall..."
# Download udwall directly to /usr/local/bin/udwall
if ! curl -fsSL "$REPO_URL/udwall" -o "$INSTALL_PATH"; then
echo "❌ Error: Failed to download udwall from GitHub."
echo "ℹ️ Please check your internet connection or if the repository/file exists."
exit 1
fi
# Make executable
echo "🔑 Setting permissions..."
chmod +x "$INSTALL_PATH"
}
setup_config() {
if [ ! -f "$CONFIG_FILE" ]; then
echo "⚙️ Setting up default configuration at $CONFIG_FILE"
mkdir -p "$CONFIG_DIR"
# Download default config
if ! curl -fsSL "$REPO_URL/udwall.conf.example" -o "$CONFIG_FILE"; then
echo "⚠️ Warning: Failed to download default config. You may need to create one manually."
fi
else
echo "⚠️ Configuration file already exists at $CONFIG_FILE. Skipping overwrite."
fi
}
main() {
echo "🚀 Installing udwall..."
check_root
check_dependencies
fetch_script
setup_config
echo "✅ Installation complete!"
echo "Run 'sudo udwall --help' to get started."
}
main