|
1 | 1 | #!/bin/bash |
| 2 | +set -e |
2 | 3 |
|
3 | | -# Check if Python 3.8 or higher is available |
4 | | -python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') |
5 | | -required_version="3.8" |
6 | | - |
7 | | -if [ "$(printf '%s\n' "$required_version" "$python_version" | sort -V | head -n1)" = "$required_version" ]; then |
8 | | - # Python version is >= 3.8, proceed with installation |
9 | | - python3 -m pip install -e . |
10 | | -else |
11 | | - echo "Error: Python 3.8 or higher is required (found $python_version)" |
12 | | - exit 1 |
13 | | -fi |
14 | | - |
15 | | -mkdir -p $HELM_PLUGIN_DIR/bin |
16 | | - |
17 | | -# Create Python script with error handling |
18 | | -cat > $HELM_PLUGIN_DIR/bin/helm_values_manager.py << 'EOF' |
19 | | -#!/usr/bin/env python3 |
20 | | -import sys |
21 | | -import os |
22 | | -
|
23 | | -try: |
24 | | - sys.path.insert(0, os.path.join(os.environ["HELM_PLUGIN_DIR"], "lib")) |
25 | | - from helm_values_manager import helm_values_manager |
26 | | -except ImportError as e: |
27 | | - print(f"Error: Failed to import helm_values_manager: {e}", file=sys.stderr) |
28 | | - print("This might be due to missing dependencies or incorrect installation.", file=sys.stderr) |
29 | | - sys.exit(1) |
30 | | -except Exception as e: |
31 | | - print(f"Error: {e}", file=sys.stderr) |
32 | | - sys.exit(1) |
33 | | -
|
34 | | -if __name__ == '__main__': |
35 | | - sys.exit(helm_values_manager()) |
36 | | -EOF |
37 | | - |
38 | | -# Create wrapper script with error handling |
39 | | -cat > $HELM_PLUGIN_DIR/bin/wrapper.sh << 'EOF' |
40 | | -#!/bin/sh |
41 | | -
|
42 | | -# Ensure HELM_PLUGIN_DIR is set |
43 | | -if [ -z "$HELM_PLUGIN_DIR" ]; then |
44 | | - echo "Error: HELM_PLUGIN_DIR environment variable is not set" |
| 4 | +# Check if Python 3.7+ is available |
| 5 | +if ! command -v python3 &> /dev/null; then |
| 6 | + echo "Error: Python 3 is required but not found" |
45 | 7 | exit 1 |
46 | 8 | fi |
47 | 9 |
|
48 | | -# Ensure the Python script exists |
49 | | -if [ ! -f "$HELM_PLUGIN_DIR/bin/helm_values_manager.py" ]; then |
50 | | - echo "Error: helm_values_manager.py not found" |
| 10 | +PYTHON_VERSION=$(python3 -c 'import sys; print(sys.version_info[0] * 10 + sys.version_info[1])') |
| 11 | +if [ "$PYTHON_VERSION" -lt 37 ]; then |
| 12 | + echo "Error: Python 3.7 or higher is required (found $PYTHON_VERSION)" |
51 | 13 | exit 1 |
52 | 14 | fi |
53 | 15 |
|
54 | | -# Run the Python script with proper error handling |
55 | | -python3 "$HELM_PLUGIN_DIR/bin/helm_values_manager.py" "$@" |
56 | | -EOF |
57 | | - |
58 | | -# Create Windows wrapper script |
59 | | -cat > $HELM_PLUGIN_DIR/bin/wrapper.bat << 'EOF' |
60 | | -@echo off |
61 | | -setlocal |
62 | | -
|
63 | | -if "%HELM_PLUGIN_DIR%"=="" ( |
64 | | - echo Error: HELM_PLUGIN_DIR environment variable is not set |
65 | | - exit /b 1 |
66 | | -) |
67 | | -
|
68 | | -if not exist "%HELM_PLUGIN_DIR%\bin\helm_values_manager.py" ( |
69 | | - echo Error: helm_values_manager.py not found |
70 | | - exit /b 1 |
71 | | -) |
72 | | -
|
73 | | -python "%HELM_PLUGIN_DIR%\bin\helm_values_manager.py" %* |
74 | | -EOF |
| 16 | +# Create virtual environment if it doesn't exist |
| 17 | +if [ ! -d "$HELM_PLUGIN_DIR/venv" ]; then |
| 18 | + echo "Creating virtual environment..." |
| 19 | + python3 -m venv "$HELM_PLUGIN_DIR/venv" |
| 20 | +fi |
75 | 21 |
|
76 | | -chmod +x $HELM_PLUGIN_DIR/bin/helm_values_manager.py |
77 | | -chmod +x $HELM_PLUGIN_DIR/bin/wrapper.sh |
| 22 | +# Upgrade pip and install package |
| 23 | +echo "Installing dependencies..." |
| 24 | +"$HELM_PLUGIN_DIR/venv/bin/pip" install --upgrade pip |
| 25 | +"$HELM_PLUGIN_DIR/venv/bin/pip" install -e . || { |
| 26 | + echo "Error: Failed to install package dependencies" |
| 27 | + exit 1 |
| 28 | +} |
78 | 29 |
|
79 | 30 | echo "helm-values-manager plugin installed successfully" |
0 commit comments