-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·142 lines (125 loc) · 3.52 KB
/
setup.sh
File metadata and controls
executable file
·142 lines (125 loc) · 3.52 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Setup script for Linux Log Analyzer
# This script helps set up the environment and dependencies
set -e
echo "=========================================="
echo "Linux Log Analyzer - Setup Script"
echo "=========================================="
echo ""
# Check Python version
echo "Checking Python version..."
python_version=$(python3 --version 2>&1 | awk '{print $2}')
echo "Found Python $python_version"
# Check if Python 3.8+
required_version="3.8"
if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" != "$required_version" ]; then
echo "Error: Python 3.8 or higher is required"
exit 1
fi
echo "✓ Python version is compatible"
echo ""
# Check for systemd
echo "Checking for systemd..."
if command -v journalctl &> /dev/null; then
echo "✓ journalctl found"
else
echo "⚠ Warning: journalctl not found. Systemd log collection will not work."
fi
echo ""
# Create virtual environment
echo "Creating virtual environment..."
if [ -d "venv" ]; then
echo "Virtual environment already exists"
else
python3 -m venv venv
echo "✓ Virtual environment created"
fi
echo ""
# Activate virtual environment
echo "Activating virtual environment..."
source venv/bin/activate
echo "✓ Virtual environment activated"
echo ""
# Upgrade pip
echo "Upgrading pip..."
pip install --upgrade pip
echo "✓ pip upgraded"
echo ""
# Install dependencies
echo "Installing dependencies..."
pip install -r requirements.txt
echo "✓ Dependencies installed"
echo ""
# Check permissions
echo "Checking log file permissions..."
log_files=(
"/var/log/syslog"
"/var/log/auth.log"
"/var/log/kern.log"
)
needs_sudo=false
for log_file in "${log_files[@]}"; do
if [ -f "$log_file" ]; then
if [ -r "$log_file" ]; then
echo "✓ $log_file is readable"
else
echo "✗ $log_file is not readable"
needs_sudo=true
fi
else
echo "⚠ $log_file does not exist"
fi
done
echo ""
# Check journalctl access
echo "Checking journalctl access..."
if journalctl -n 1 &> /dev/null; then
echo "✓ journalctl is accessible"
else
echo "✗ journalctl requires elevated permissions"
needs_sudo=true
fi
echo ""
# Provide permission instructions if needed
if [ "$needs_sudo" = true ]; then
echo "=========================================="
echo "PERMISSION SETUP REQUIRED"
echo "=========================================="
echo ""
echo "Some log files require elevated permissions."
echo "You have two options:"
echo ""
echo "Option 1: Add your user to the systemd-journal group"
echo " sudo usermod -a -G systemd-journal $USER"
echo " sudo usermod -a -G adm $USER"
echo " (Then log out and log back in)"
echo ""
echo "Option 2: Run the application with sudo"
echo " sudo venv/bin/streamlit run app.py"
echo ""
fi
# Create example config if needed
if [ ! -f "config.yaml" ]; then
echo "⚠ config.yaml not found"
echo "Please create config.yaml based on the template"
else
echo "✓ config.yaml found"
fi
echo ""
echo "=========================================="
echo "Setup Complete!"
echo "=========================================="
echo ""
echo "To run the application:"
echo " 1. Activate the virtual environment:"
echo " source venv/bin/activate"
echo ""
echo " 2. Start the Streamlit app:"
echo " streamlit run app.py"
echo ""
echo " 3. Or run the example script:"
echo " python example_usage.py"
echo ""
echo "For more information, see README.md"
echo ""
# Made with Bob