-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·152 lines (122 loc) · 5.63 KB
/
install.sh
File metadata and controls
executable file
·152 lines (122 loc) · 5.63 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
#!/bin/bash
# shell-agent
# install.sh
# Exit immediately if a command exits with a non-zero status.
set -e
# Configuration
REPO_URL="https://github.com/ToastCoder/shell-agent"
INSTALL_DIR="$HOME/.local/share/shell-agent"
PYTHON_APP_SCRIPT="main.py"
RUN_SCRIPT_NAME="shell-agent"
RUN_SCRIPT_PATH="${INSTALL_DIR}/${RUN_SCRIPT_NAME}"
# Directory where we will temporarily clone the repo content
TEMP_CLONE_DIR=$(mktemp -d)
echo "=================================================================================================="
echo "Shell-Agent Installer Initiated (System Deployment)"
echo "======================================================================================================"
# Check for Dependencies and Clone Repository
echo "Checking for dependencies and cloning repository from ${REPO_URL}..."
# Use git for cloning, which is the most reliable method.
git clone "${REPO_URL}" "${TEMP_CLONE_DIR}/shell-agent"
if [ $? -ne 0 ]; then
echo "Error: Failed to clone the repository. Ensure you have 'git' installed and network access."
exit 1
fi
# Set the working directory for all subsequent operations
cd "${TEMP_CLONE_DIR}/shell-agent"
# Clean up existing installation if present
if [ -d "${INSTALL_DIR}" ]; then
echo "Found existing installation directory. Backing up and clearing: ${INSTALL_DIR}..."
# Backup the old installation first
mkdir -p "$HOME/.local/share/shell-agent.bak_$(date +%Y%m%d%H%M%d%H%M%S)"
cp -r "${INSTALL_DIR}" "$HOME/.local/share/shell-agent.bak_*"
rm -rf "${INSTALL_DIR}"
fi
# Setup the Directory Structure and Copy Files
echo "Creating isolated installation directory: ${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}"
echo "Copying all core project files to ${INSTALL_DIR}..."
# Use rsync to copy the entire working project state into the isolated location
rsync -av --delete "$PWD/" "${INSTALL_DIR}/"
# 4. Virtual Environment Setup and Dependency Installation
echo "------------------------------------------------------------------------"
echo "Initializing Virtual Environment and Installing Dependencies..."
echo "------------------------------------------------------------------------"
# Create the virtual environment inside the installed directory
echo "Step 4a: Creating virtual environment in ${INSTALL_DIR}/.venv..."
python3 -m venv "${INSTALL_DIR}/.venv"
if [ $? -ne 0 ]; then
echo "Error: Failed to create virtual environment. Check python3 availability."
exit 1
fi
# Activate the environment (must be done before pip can work correctly)
echo "Step 4b: Activating environment and installing dependencies..."
source "${INSTALL_DIR}/.venv/bin/activate"
# Install dependencies using the local requirements.txt
pip install -r requirements.txt
if [ $? -ne 0 ]; then
echo "Error: Dependency installation failed. Check requirements.txt and network connectivity."
deactivate
exit 1
fi
# Deactivate the environment after successful installation
deactivate
# Create and Configure run.sh Wrapper Script (The new global entry point)
echo "Creating wrapper script: ${RUN_SCRIPT_NAME}..."
cat > "${RUN_SCRIPT_PATH}" << EOF
#!/bin/bash
# This script is the main global entry point for Shell-Agent.
# It ensures the environment is sourced from the local installation path.
# Determine the absolute path of the directory containing this script.
SCRIPT_DIR=\$(dirname "\$BASH_SOURCE")
INSTALL_DIR=\$(dirname "\$SCRIPT_DIR")
# Activate the virtual environment using the full path to ensure sourcing works.
source "\${INSTALL_DIR}/.venv/bin/activate" 2>/dev/null
# Execute the main application logic.
python "\${INSTALL_DIR}/shell-agent/main.py"
EOF
# Make the entry point executable
chmod +x "${RUN_SCRIPT_PATH}"
# Add to PATH (Platform-Agnostic Shell Detection)
echo "Determining default shell and updating profile..."
USER_SHELL_PROFILE=""
SHELL_BIN="$SHELL"
if [ -z "$SHELL_BIN" ]; then
echo "Warning: Cannot determine your default shell (\$SHELL). Manual action required."
exit 0
fi
# Determine the config file based on the shell binary path
case "$SHELL_BIN" in
*/zsh)
USER_SHELL_PROFILE="$HOME/.zshrc"
;;
*/bash)
USER_SHELL_PROFILE="$HOME/.bashrc"
;;
*)
echo "Warning: Detected shell '$SHELL_BIN'. Cannot automatically determine profile. Manual action required."
USER_SHELL_PROFILE=""
;;
esac
if [ -n "$USER_SHELL_PROFILE" ]; then
echo "Detected shell (${SHELL_BIN}). Writing changes to ${USER_SHELL_PROFILE}."
# Check if the directory is already in PATH to prevent duplicates
if ! grep -q "${INSTALL_DIR}" "${USER_SHELL_PROFILE}"; then
echo "" >> "${USER_SHELL_PROFILE}"
echo "# Shell-Agent Deployment (Installed by installer)" >> "${USER_SHELL_PROFILE}"
echo "export PATH=\"${INSTALL_DIR}:${PATH}\"" >> "${USER_SHELL_PROFILE}"
echo ""
echo "Success! Added ${INSTALL_DIR} to your PATH in ${USER_SHELL_PROFILE}."
echo "Please run 'source ${USER_SHELL_PROFILE}' to apply changes."
else
echo "The agent directory is already configured in your shell profile."
fi
else
echo "Manual Step Required: Due to non-standard shell detection, please manually add the following line to your profile (~/.zshrc or ~/.bashrc):"
echo "export PATH=\"${INSTALL_DIR}:${PATH}\""
fi
echo "====================================================================================================="
echo "Installation Complete! Shell-Agent is now installed for user."
echo "====================================================================================================="
echo "ACTION REQUIRED: Please source your shell profile to apply path changes."
echo "Then, you can run the agent by typing: shell-agent"