-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·241 lines (209 loc) · 6.06 KB
/
install.sh
File metadata and controls
executable file
·241 lines (209 loc) · 6.06 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Helper functions
print_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
# Detect OS
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
OS_VERSION=$VERSION_ID
else
OS="unknown"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
OS_VERSION=$(sw_vers -productVersion)
else
OS="unknown"
fi
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check Python version
check_python() {
print_info "Checking for Python installation..."
if command_exists python3; then
PYTHON_CMD="python3"
PYTHON_VERSION=$($PYTHON_CMD --version 2>&1 | awk '{print $2}')
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2)
if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 10 ]; then
print_success "Python $PYTHON_VERSION found"
return 0
else
print_error "Python 3.10+ required, found $PYTHON_VERSION"
return 1
fi
else
print_error "Python 3 not found"
return 1
fi
}
# Install Python based on OS
install_python() {
print_info "Installing Python 3..."
case $OS in
ubuntu|debian)
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-venv
;;
fedora|rhel|centos)
sudo dnf install -y python3 python3-pip
;;
arch|manjaro)
sudo pacman -S --noconfirm python python-pip
;;
macos)
if command_exists brew; then
brew install python@3.12
else
print_error "Homebrew not found. Please install Python 3.10+ manually from https://www.python.org/downloads/"
exit 1
fi
;;
*)
print_error "Unable to auto-install Python on $OS. Please install Python 3.10+ manually."
exit 1
;;
esac
if check_python; then
print_success "Python installed successfully"
else
print_error "Python installation failed"
exit 1
fi
}
# Check if pipx is installed
check_pipx() {
if command_exists pipx; then
print_success "pipx found"
return 0
else
print_info "pipx not found"
return 1
fi
}
# Install pipx
install_pipx() {
print_info "Installing pipx..."
if ! check_python; then
install_python
fi
# Install pipx using pip
$PYTHON_CMD -m pip install --user pipx
# Ensure pipx is in PATH
$PYTHON_CMD -m pipx ensurepath
# Source the shell config to update PATH in current session
if [ -f "$HOME/.bashrc" ]; then
export PATH="$HOME/.local/bin:$PATH"
elif [ -f "$HOME/.zshrc" ]; then
export PATH="$HOME/.local/bin:$PATH"
fi
if check_pipx; then
print_success "pipx installed successfully"
else
print_warning "pipx installed but not in PATH. Please restart your shell or run:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
exit 1
fi
}
# Install sot using pipx
install_sot() {
print_info "Installing sot via pipx..."
if pipx install sot; then
print_success "sot installed successfully!"
return 0
else
print_error "Failed to install sot"
return 1
fi
}
# Verify installation
verify_installation() {
print_info "Verifying installation..."
if command_exists sot; then
SOT_VERSION=$(sot --version 2>&1 | head -1)
print_success "Installation verified: $SOT_VERSION"
return 0
else
print_warning "sot command not found in PATH"
print_info "You may need to restart your shell or run:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
return 1
fi
}
# Main installation flow
main() {
echo ""
echo "════════════════════════════════════"
echo " Thanks for trying out SOT"
echo " System Observation Tool"
echo "════════════════════════════════════"
echo ""
detect_os
print_info "Detected OS: $OS"
# Check and install Python if needed
if ! check_python; then
print_warning "Python 3.10+ is required"
read -p "Would you like to install Python? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
install_python
else
print_error "Python is required to continue"
exit 1
fi
fi
# Check and install pipx if needed
if ! check_pipx; then
print_warning "pipx is required for installation"
read -p "Would you like to install pipx? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
install_pipx
else
print_error "pipx is required to continue"
exit 1
fi
fi
# Install sot
if install_sot; then
echo ""
print_success "════════════════════════════════════════"
print_success " Installation completed successfully!"
print_success "════════════════════════════════════════"
echo ""
if verify_installation; then
print_info "Run 'sot' to start the application"
else
print_warning "Please restart your shell and then run 'sot'"
fi
echo ""
else
print_error "Installation failed"
exit 1
fi
}
# Run main function
main