-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·156 lines (130 loc) · 4.83 KB
/
install.sh
File metadata and controls
executable file
·156 lines (130 loc) · 4.83 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
#!/bin/bash
# OpenCode Monitor Installation Script
# This script automates the installation process for OpenCode Monitor
set -e # Exit on any error
echo "🚀 OpenCode Monitor Installation Script"
echo "======================================"
# Check if we're in the right directory
if [ ! -f "setup.py" ] || [ ! -d "ocmonitor" ]; then
echo "❌ Error: Please run this script from the ocmonitor root directory"
echo " The directory should contain setup.py and ocmonitor/ folder"
exit 1
fi
echo "✅ Found ocmonitor project directory"
# Check Python version
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
if [[ "$(printf '%s\n' "3.8" "$PYTHON_VERSION" | sort -V | head -n1)" == "3.8" ]]; then
echo "✅ Python version $PYTHON_VERSION is supported"
else
echo "❌ Python 3.8 or higher is required"
exit 1
fi
# Create virtual environment if it doesn't exist
VENV_DIR="venv"
if [ ! -d "$VENV_DIR" ]; then
echo "🔨 Creating virtual environment..."
python3 -m venv "$VENV_DIR"
echo "✅ Virtual environment created"
else
echo "✅ Virtual environment already exists"
fi
# Activate virtual environment
echo "🔌 Activating virtual environment..."
source "$VENV_DIR/bin/activate"
# Install dependencies
echo "📥 Installing dependencies..."
pip install -r requirements.txt
# Install package in development mode
echo "🔧 Installing ocmonitor in development mode..."
pip install -e .
# Get the scripts directory
SCRIPTS_DIR="$(pwd)/$VENV_DIR/bin"
echo "📁 Python scripts installed to: $SCRIPTS_DIR"
# Test installation
echo "🧪 Testing installation..."
if [ -f "$SCRIPTS_DIR/ocmonitor" ]; then
echo "✅ ocmonitor command is available in venv"
"$SCRIPTS_DIR/ocmonitor" --version
else
echo "⚠️ ocmonitor command not found"
exit 1
fi
# Install global wrapper
echo ""
echo "🌍 Installing global wrapper..."
PROJECT_DIR="$(pwd)"
# Create the wrapper script content dynamically
cat > ocmonitor-wrapper.sh << 'EOF'
#!/bin/bash
# OpenCode Monitor Global Wrapper Script
# This script allows ocmonitor to be run from anywhere without activating the virtual environment
# Get the directory where this script is located (the project directory)
PROJECT_DIR="PROJECT_DIR_PLACEHOLDER"
# Path to the virtual environment's ocmonitor
OCMONITOR_SCRIPT="$PROJECT_DIR/venv/bin/ocmonitor"
# Check if ocmonitor exists
if [ ! -f "$OCMONITOR_SCRIPT" ]; then
echo "Error: ocmonitor not found at $OCMONITOR_SCRIPT"
echo "Please run install.sh from the project directory"
exit 1
fi
# Execute ocmonitor with all arguments passed to this script
exec "$OCMONITOR_SCRIPT" "$@"
EOF
# Replace placeholder with actual project directory
sed "s|PROJECT_DIR_PLACEHOLDER|$PROJECT_DIR|g" ocmonitor-wrapper.sh > ocmonitor-wrapper.sh.tmp
mv ocmonitor-wrapper.sh.tmp ocmonitor-wrapper.sh
chmod +x ocmonitor-wrapper.sh
# Try to install to user's local bin first (no sudo needed)
LOCAL_BIN="$HOME/.local/bin"
mkdir -p "$LOCAL_BIN"
if cp ocmonitor-wrapper.sh "$LOCAL_BIN/ocmonitor" 2>/dev/null; then
echo "✅ Global command installed to $LOCAL_BIN/ocmonitor"
GLOBAL_INSTALL=true
# Check if LOCAL_BIN is in PATH
if [[ ":$PATH:" != *":$LOCAL_BIN:"* ]]; then
echo ""
echo "⚠️ Warning: $LOCAL_BIN is not in your PATH"
echo ""
echo "📝 Add this to your shell config file (~/.bashrc or ~/.zshrc):"
echo " export PATH=\"$LOCAL_BIN:\$PATH\""
echo ""
echo " Then run: source ~/.bashrc (or source ~/.zshrc)"
fi
else
# Fallback to /usr/local/bin with sudo
INSTALL_DIR="/usr/local/bin"
echo "🔐 Installing to $INSTALL_DIR requires sudo privileges..."
if sudo cp ocmonitor-wrapper.sh "$INSTALL_DIR/ocmonitor" 2>/dev/null; then
echo "✅ Global command installed to $INSTALL_DIR/ocmonitor"
GLOBAL_INSTALL=true
else
echo "⚠️ Could not install globally"
echo " You can manually copy the wrapper:"
echo " cp ocmonitor-wrapper.sh ~/.local/bin/ocmonitor"
echo " or"
echo " sudo cp ocmonitor-wrapper.sh /usr/local/bin/ocmonitor"
GLOBAL_INSTALL=false
fi
fi
echo ""
echo "🎉 Installation complete!"
echo ""
if [ "$GLOBAL_INSTALL" = true ]; then
echo "✅ You can now run 'ocmonitor' from anywhere!"
echo ""
echo "📝 Try these commands:"
echo " ocmonitor --help"
echo " ocmonitor config show"
echo " ocmonitor --version"
else
echo "📝 To use ocmonitor globally, run one of these:"
echo " cp ocmonitor-wrapper.sh ~/.local/bin/ocmonitor"
echo " (make sure ~/.local/bin is in your PATH)"
echo ""
echo " Or activate the virtual environment:"
echo " source $VENV_DIR/bin/activate"
echo " ocmonitor --help"
fi
echo ""
echo "For more detailed usage instructions, see MANUAL_TEST_GUIDE.md"