-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
357 lines (309 loc) · 11.1 KB
/
install.sh
File metadata and controls
357 lines (309 loc) · 11.1 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/bin/bash
#############################################################################
# pyp C++ Virtual Environment Manager - Installation Script
# A lightweight, high-performance Python venv manager built in C++
#############################################################################
# Colors for beautiful output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
RESET='\033[0m'
# Configuration
APP_NAME="pyp"
BINARY_NAME="pyp"
SOURCE_FILE="main.cpp"
INSTALL_DIR="${HOME}/.local/bin"
CONFIG_DIR="${HOME}"
CONFIG_FILE="${HOME}/.pyp_config.json"
BACKUP_FILE="${HOME}/.pyp_config.json.backup"
# Version info
VERSION="2.0.0"
echo -e "${BOLD}${CYAN}"
echo " ____ _____ _ ____ _____ ___ ___ _ _ ____ "
echo " | _ \\| ____| / \\ / ___| |_ _|_ _|_ _| | | | _ \\ "
echo " | |_) | _| / _ \\ \\___ \\ | | | | | | | | | |_) |"
echo " | __/| |___ / ___ \\ ___) | | | | | | | |_| | __/ "
echo " |_| |_____/_/ \\_\\____/ |_| |___|___| (_)_| |_| "
echo -e "${RESET}"
echo -e "${BOLD} Python Virtual Environment Manager - C++ Edition${RESET}"
echo -e " Version ${VERSION}"
echo ""
echo ""
# Function to print status messages
print_status() {
echo -e "${BLUE}[*]${RESET} $1"
}
print_success() {
echo -e "${GREEN}[✓]${RESET} $1"
}
print_warning() {
echo -e "${YELLOW}[!]${RESET} $1"
}
print_error() {
echo -e "${RED}[✗]${RESET} $1"
}
# Check if running with proper permissions
check_permissions() {
print_status "Checking installation permissions..."
# Check if we can write to install directory
if [ ! -d "${INSTALL_DIR}" ]; then
print_status "Creating installation directory: ${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}"
fi
if [ ! -w "${INSTALL_DIR}" ]; then
print_error "Cannot write to ${INSTALL_DIR}"
print_warning "Try running with sudo or manually create the directory"
INSTALL_DIR="/usr/local/bin"
fi
print_success "Installation directory: ${INSTALL_DIR}"
}
# Check for C++ compiler
check_compiler() {
print_status "Checking for C++ compiler..."
if command -v g++ &> /dev/null; then
COMPILER="g++"
COMPILER_VERSION=$(g++ --version | head -n1)
print_success "Found ${COMPILER}: ${COMPILER_VERSION}"
elif command -v clang++ &> /dev/null; then
COMPILER="clang++"
COMPILER_VERSION=$(clang++ --version | head -n1)
print_success "Found ${COMPILER}: ${COMPILER_VERSION}"
else
print_error "No C++ compiler found!"
print_warning "Please install g++ or clang++"
echo ""
echo "On Ubuntu/Debian: sudo apt install build-essential"
echo "On Fedora/RHEL: sudo dnf install gcc-c++"
echo "On Arch: sudo pacman -S base-devel"
echo "On macOS: xcode-select --install"
exit 1
fi
}
# Detect C++ standard library support
check_cpp_features() {
print_status "Checking C++ feature support..."
# Check for C++17 filesystem support
echo '#include <filesystem>
int main() { std::filesystem::path p("."); return 0; }' > /tmp/test_filesystem.cpp
if ${COMPILER} -std=c++17 -o /tmp/test_filesystem /tmp/test_filesystem.cpp 2>/dev/null; then
print_success "C++17 filesystem support available"
CXXFLAGS="-std=c++17 -O2 -Wall -Wextra"
rm -f /tmp/test_filesystem /tmp/test_filesystem.cpp
else
print_warning "C++17 filesystem not fully supported, using experimental"
# Try experimental filesystem
echo '#include <experimental/filesystem>
int main() { std::experimental::filesystem::path p("."); return 0; }' > /tmp/test_filesystem.cpp
if ${COMPILER} -std=c++17 -o /tmp/test_filesystem /tmp/test_filesystem.cpp 2>/dev/null; then
CXXFLAGS="-std=c++17 -O2 -Wall -Wextra"
print_success "Using experimental filesystem"
rm -f /tmp/test_filesystem /tmp/test_filesystem.cpp
else
print_warning "Filesystem support limited, using fallback compilation"
CXXFLAGS="-std=c++14 -O2 -Wall -Wextra"
rm -f /tmp/test_filesystem /tmp/test_filesystem.cpp
fi
fi
}
# Backup existing configuration
backup_config() {
if [ -f "${CONFIG_FILE}" ]; then
print_status "Backing up existing configuration..."
cp "${CONFIG_FILE}" "${BACKUP_FILE}"
print_success "Backup created: ${BACKUP_FILE}"
fi
}
# Compile the application
compile_app() {
print_status "Compiling ${APP_NAME}..."
# Check if source file exists
if [ ! -f "${SOURCE_FILE}" ]; then
print_error "Source file not found: ${SOURCE_FILE}"
exit 1
fi
# Remove old binary if exists
if [ -f "${BINARY_NAME}" ]; then
print_status "Removing old binary..."
rm -f "${BINARY_NAME}"
fi
# Compile command
COMPILE_CMD="${COMPILER} ${CXXFLAGS} -o ${BINARY_NAME} ${SOURCE_FILE}"
echo -e "${CYAN}Running: ${COMPILE_CMD}${RESET}"
if ${COMPILE_CMD}; then
print_success "Compilation successful!"
# Show binary info
if command -v file &> /dev/null; then
echo -e "${CYAN}Binary info:${RESET}"
file "${BINARY_NAME}" | sed 's/^/ /'
fi
if command -v ls &> /dev/null; then
BINARY_SIZE=$(ls -lh "${BINARY_NAME}" | awk '{print $5}')
echo -e "${CYAN}Binary size: ${RESET}${BINARY_SIZE}"
fi
else
print_error "Compilation failed!"
exit 1
fi
}
# Install the binary
install_binary() {
print_status "Installing ${APP_NAME} to ${INSTALL_DIR}..."
# Create symlink or copy binary
if [ -f "${INSTALL_DIR}/${BINARY_NAME}" ]; then
print_status "Removing old installation..."
rm -f "${INSTALL_DIR}/${BINARY_NAME}"
fi
# Try to create symlink first (preferred)
if ln -s "$(pwd)/${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}" 2>/dev/null; then
print_success "Created symlink: ${INSTALL_DIR}/${BINARY_NAME}"
else
# Fall back to copy
if cp "${BINARY_NAME}" "${INSTALL_DIR}/${BINARY_NAME}"; then
chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
print_success "Installed binary: ${INSTALL_DIR}/${BINARY_NAME}"
else
print_error "Failed to install binary!"
exit 1
fi
fi
}
# Update PATH if needed
update_path() {
print_status "Checking PATH configuration..."
if [[ ":${PATH}:" != *":${INSTALL_DIR}:"* ]]; then
print_warning "${INSTALL_DIR} is not in your PATH"
print_status "Adding to PATH in shell configuration..."
# Detect shell
if [ -n "$ZSH_VERSION" ]; then
SHELL_CONFIG="${HOME}/.zshrc"
PATH_LINE="export PATH=\"${INSTALL_DIR}:\$PATH\""
elif [ -n "$BASH_VERSION" ]; then
SHELL_CONFIG="${HOME}/.bashrc"
PATH_LINE="export PATH=\"${INSTALL_DIR}:\$PATH\""
else
SHELL_CONFIG="${HOME}/.profile"
PATH_LINE="export PATH=\"${INSTALL_DIR}:\$PATH\""
fi
if [ -f "$SHELL_CONFIG" ]; then
if ! grep -q "${INSTALL_DIR}" "$SHELL_CONFIG" 2>/dev/null; then
echo "" >> "$SHELL_CONFIG"
echo "# pyp PATH addition" >> "$SHELL_CONFIG"
echo "$PATH_LINE" >> "$SHELL_CONFIG"
print_success "Added to ${SHELL_CONFIG}"
fi
else
touch "$SHELL_CONFIG"
echo "$PATH_LINE" >> "$SHELL_CONFIG"
print_success "Created ${SHELL_CONFIG} with PATH configuration"
fi
print_warning "You may need to restart your shell or run:"
echo -e " ${GREEN}source ${SHELL_CONFIG}${RESET}"
else
print_success "${INSTALL_DIR} is already in PATH"
fi
}
# Verify installation
verify_installation() {
print_status "Verifying installation..."
# Try to run pyp
if "${INSTALL_DIR}/${BINARY_NAME}" --version &> /dev/null; then
print_success "Installation verified!"
echo ""
echo -e "${BOLD}Run the following to start using pyp:${RESET}"
echo -e " ${GREEN}source ${SHELL_CONFIG}${RESET}"
echo -e " ${GREEN}pyp --help${RESET}"
else
print_error "Installation verification failed!"
print_warning "You may need to restart your shell"
fi
}
# Show usage information
show_usage() {
echo -e "${BOLD}Usage:${RESET}"
echo " ./install.sh [OPTIONS]"
echo ""
echo -e "${BOLD}Options:${RESET}"
echo " --help Show this help message"
echo " --install-dir Specify installation directory (default: ${HOME}/.local/bin)"
echo " --no-path Skip PATH configuration"
echo " --force Force reinstallation"
echo " --uninstall Run uninstallation instead"
echo ""
echo -e "${BOLD}Examples:${RESET}"
echo " ./install.sh # Default installation"
echo " ./install.sh --install-dir /usr/local/bin # Custom directory"
echo " ./install.sh --no-path # Skip PATH update"
}
# Parse command line arguments
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--help)
show_usage
exit 0
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
--no-path)
SKIP_PATH=true
shift
;;
--force)
FORCE=true
shift
;;
--uninstall)
echo -e "${BOLD}Running uninstallation...${RESET}"
if [ -f "./uninstall.sh" ]; then
./uninstall.sh
else
print_error "uninstall.sh not found!"
fi
exit 0
;;
*)
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
}
# Main installation flow
main() {
SKIP_PATH=false
FORCE=false
parse_args "$@"
echo -e "${BOLD}========================================${RESET}"
echo -e "${BOLD} pyp Installation Script${RESET}"
echo -e "${BOLD}========================================${RESET}"
echo ""
check_permissions
check_compiler
check_cpp_features
backup_config
compile_app
install_binary
if [ "$SKIP_PATH" != true ]; then
update_path
fi
verify_installation
echo ""
echo -e "${BOLD}${GREEN}========================================${RESET}"
echo -e "${BOLD}${GREEN} Installation Complete!${RESET}"
echo -e "${BOLD}${GREEN}========================================${RESET}"
echo ""
echo -e "${BOLD}Quick Start:${RESET}"
echo -e " ${CYAN}pyp --help${RESET} # Show help"
echo -e " ${CYAN}pyp -b myenv${RESET} # Create environment"
echo -e " ${CYAN}pyp -a myenv${RESET} # Activate environment"
echo -e " ${CYAN}pyp -l${RESET} # List environments"
echo ""
}
# Run main function
main "$@"