-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.sh
More file actions
executable file
·158 lines (132 loc) · 4.01 KB
/
Copy pathcli.sh
File metadata and controls
executable file
·158 lines (132 loc) · 4.01 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
#!/usr/bin/env bash
# CLI launcher for Internal Certificate Manager
# This script checks dependencies, sets up virtual environment, and launches the CLI
set -e # Exit on error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}==>${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to get Python version
get_python_version() {
"$1" --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1
}
# Function to compare versions (returns 0 if version1 >= version2)
version_gte() {
printf '%s\n%s' "$2" "$1" | sort -V -C
}
echo ""
print_status "Internal Certificate Manager - CLI"
echo ""
# Check for Python 3
print_status "Checking for Python..."
PYTHON_CMD=""
if command_exists python3; then
PYTHON_CMD="python3"
elif command_exists python; then
# Check if python is Python 3
PYTHON_VERSION=$(get_python_version python)
if [[ "$PYTHON_VERSION" == 3.* ]]; then
PYTHON_CMD="python"
fi
fi
if [ -z "$PYTHON_CMD" ]; then
print_error "Python 3 is not installed or not in PATH"
echo " Please install Python 3.8 or later from https://www.python.org/"
exit 1
fi
PYTHON_VERSION=$(get_python_version "$PYTHON_CMD")
print_success "Found Python $PYTHON_VERSION at $(which $PYTHON_CMD)"
# Check Python version is 3.8+
if ! version_gte "$PYTHON_VERSION" "3.8.0"; then
print_error "Python 3.8 or later is required (found $PYTHON_VERSION)"
exit 1
fi
# Check for OpenSSL
print_status "Checking for OpenSSL..."
if command_exists openssl; then
OPENSSL_VERSION=$(openssl version | awk '{print $2}')
print_success "Found OpenSSL $OPENSSL_VERSION"
else
print_warning "OpenSSL not found in PATH"
echo " OpenSSL is recommended but not strictly required for runtime"
echo " The Python cryptography library will use its bundled OpenSSL"
fi
# Check for virtual environment
print_status "Checking for virtual environment..."
if [ -d ".venv" ]; then
print_success "Virtual environment exists"
else
print_status "Creating virtual environment..."
"$PYTHON_CMD" -m venv .venv
print_success "Virtual environment created"
fi
# Activate virtual environment
print_status "Activating virtual environment..."
if [ -f ".venv/bin/activate" ]; then
source .venv/bin/activate
print_success "Virtual environment activated"
else
print_error "Failed to find activation script"
exit 1
fi
# Verify we're in the virtual environment
if [ -z "$VIRTUAL_ENV" ]; then
print_error "Failed to activate virtual environment"
exit 1
fi
# Upgrade pip
print_status "Upgrading pip..."
python -m pip install --upgrade pip --quiet
print_success "pip upgraded"
# Check if requirements need to be installed/upgraded
print_status "Checking requirements..."
REQUIREMENTS_FILE="requirements.txt"
if [ ! -f "$REQUIREMENTS_FILE" ]; then
print_error "requirements.txt not found"
exit 1
fi
# Check if requirements are already satisfied
NEEDS_INSTALL=false
# Try to check if packages are installed
if ! python -c "import cryptography, prompt_toolkit" 2>/dev/null; then
NEEDS_INSTALL=true
fi
if [ "$NEEDS_INSTALL" = true ]; then
print_status "Installing requirements..."
pip install -r "$REQUIREMENTS_FILE"
print_success "Requirements installed"
else
# Check for outdated packages
OUTDATED=$(pip list --outdated --format=columns 2>/dev/null | grep -E '(cryptography|prompt-toolkit)' || true)
if [ -n "$OUTDATED" ]; then
print_status "Upgrading outdated packages..."
pip install --upgrade -r "$REQUIREMENTS_FILE"
print_success "Requirements upgraded"
else
print_success "All requirements are up to date"
fi
fi
# Launch CLI
echo ""
print_status "Launching CLI..."
echo ""
python -m cert_manager.cli