Update installation paths and script logic for proper system-wide and user installations

- Changed system installation path from /usr/local/share/aisbf to /usr/share/aisbf
- Updated aisbf.sh script to dynamically determine correct paths at runtime
- Script now checks for /usr/share/aisbf first, then falls back to ~/.local/share/aisbf
- Updated setup.py to install script with dynamic path detection
- Updated config.py to check for /usr/share/aisbf instead of /usr/local/share/aisbf
- Updated AI.PROMPT documentation to reflect new installation paths
- Script creates venv in appropriate location based on installation type
- Ensures proper main.py location is used regardless of who launches the script
parent c4d777ac
......@@ -80,7 +80,7 @@ Exports all main components:
### aisbf/config.py
Configuration management with smart file location detection:
- Checks installed location first (`/usr/local/share/aisbf/` or `~/.local/share/aisbf/`)
- Checks installed location first (`/usr/share/aisbf/` or `~/.local/share/aisbf/`)
- Falls back to source tree `config/` directory for development
- Creates `~/.aisbf/` directory on first run
- Copies default configs to user directory
......@@ -146,8 +146,8 @@ sudo python setup.py install
Installs to:
- `/usr/local/lib/python*/dist-packages/aisbf/` - Package
- `/usr/local/aisbf-venv/` - Virtual environment
- `/usr/local/share/aisbf/` - Config files and main.py
- `/usr/share/aisbf/venv/` - Virtual environment
- `/usr/share/aisbf/` - Config files and main.py
- `/usr/local/bin/aisbf` - Executable script
## Configuration Management
......@@ -156,7 +156,7 @@ Installs to:
**Installed Configuration Files (read-only defaults):**
- User: `~/.local/share/aisbf/providers.json`, `~/.local/share/aisbf/rotations.json`, `~/.local/share/aisbf/main.py`
- System: `/usr/local/share/aisbf/providers.json`, `/usr/local/share/aisbf/rotations.json`, `/usr/local/share/aisbf/main.py`
- System: `/usr/share/aisbf/providers.json`, `/usr/share/aisbf/rotations.json`, `/usr/share/aisbf/main.py`
**User Configuration Files (writable):**
- `~/.aisbf/providers.json` - Provider configurations
......
......@@ -19,22 +19,122 @@
########################################################
# AISBF - AI Service Broker Framework || AI Should Be Free
# This script starts the AISBF proxy server using the installed virtual environment
# This script manages the AISBF server using the installed virtual environment
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PIDFILE="/tmp/aisbf.pid"
# Change to the script directory
cd "$SCRIPT_DIR"
# Check if venv exists
if [ ! -d "venv" ]; then
echo "Error: Virtual environment not found. Please run: python setup.py install"
exit 1
# Determine the correct share directory at runtime
# Check for system installation first (/usr/share/aisbf)
if [ -d "/usr/share/aisbf" ]; then
SHARE_DIR="/usr/share/aisbf"
VENV_DIR="/usr/share/aisbf/venv"
else
# Fall back to user installation (~/.local/share/aisbf)
SHARE_DIR="$HOME/.local/share/aisbf"
VENV_DIR="$HOME/.local/share/aisbf/venv"
fi
# Activate virtual environment
source venv/bin/activate
# Function to create venv if it doesn't exist
ensure_venv() {
if [ ! -d "$VENV_DIR" ]; then
echo "Creating virtual environment at $VENV_DIR"
python3 -m venv "$VENV_DIR"
# Install requirements if requirements.txt exists
if [ -f "$SHARE_DIR/requirements.txt" ]; then
echo "Installing requirements from $SHARE_DIR/requirements.txt"
"$VENV_DIR/bin/pip" install -r "$SHARE_DIR/requirements.txt"
fi
fi
}
# Function to start the server
start_server() {
# Ensure venv exists
ensure_venv
# Activate the virtual environment
source $VENV_DIR/bin/activate
# Change to share directory where main.py is located
cd $SHARE_DIR
# Start the proxy server
uvicorn main:app --host 0.0.0.0 --port 8000
}
# Function to start as daemon
start_daemon() {
# Check if already running
if [ -f "$PIDFILE" ]; then
PID=$(cat "$PIDFILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "AISBF is already running (PID: $PID)"
exit 1
else
# Stale PID file, remove it
rm -f "$PIDFILE"
fi
fi
# Ensure venv exists
ensure_venv
# Start in background with nohup
nohup bash -c "source $VENV_DIR/bin/activate && cd $SHARE_DIR && uvicorn main:app --host 0.0.0.0 --port 8000" > /dev/null 2>&1 &
PID=$!
echo $PID > "$PIDFILE"
echo "AISBF started in background (PID: $PID)"
}
# Function to check status
check_status() {
if [ -f "$PIDFILE" ]; then
PID=$(cat "$PIDFILE")
if ps -p "$PID" > /dev/null 2>&1; then
echo "AISBF is running (PID: $PID)"
exit 0
else
echo "AISBF is not running (stale PID file)"
rm -f "$PIDFILE"
exit 1
fi
else
echo "AISBF is not running"
exit 1
fi
}
# Function to stop the daemon
stop_daemon() {
if [ -f "$PIDFILE" ]; then
PID=$(cat "$PIDFILE")
if ps -p "$PID" > /dev/null 2>&1; then
kill "$PID"
rm -f "$PIDFILE"
echo "AISBF stopped (PID: $PID)"
else
echo "AISBF is not running (stale PID file)"
rm -f "$PIDFILE"
fi
else
echo "AISBF is not running"
fi
}
# Start the proxy server
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
# Main command handling
case "$1" in
daemon)
start_daemon
;;
status)
check_status
;;
stop)
stop_daemon
;;
*)
# Default: start in foreground
start_server
;;
esac
......@@ -54,7 +54,7 @@ class Config:
"""Get the directory containing default config files"""
# Try installed location first
installed_dirs = [
Path('/usr/local/share/aisbf'),
Path('/usr/share/aisbf'),
Path.home() / '.local' / 'share' / 'aisbf',
]
......
......@@ -60,23 +60,31 @@ class InstallCommand(_install):
if '--user' in sys.argv or os.geteuid() != 0:
# User installation - use ~/.local/bin
bin_dir = Path.home() / '.local' / 'bin'
share_dir = Path.home() / '.local' / 'share' / 'aisbf'
else:
# System installation - use /usr/local/bin
bin_dir = Path('/usr/local/bin')
share_dir = Path('/usr/local/share/aisbf')
# Create the bin directory if it doesn't exist
bin_dir.mkdir(parents=True, exist_ok=True)
# Create the aisbf script that uses the venv
script_content = f"""#!/bin/bash
# The script will dynamically determine the correct paths at runtime
script_content = """#!/bin/bash
# AISBF - AI Service Broker Framework || AI Should Be Free
# This script manages the AISBF server using the installed virtual environment
PIDFILE="/tmp/aisbf.pid"
SHARE_DIR="{share_dir}"
VENV_DIR="$SHARE_DIR/venv"
# Determine the correct share directory at runtime
# Check for system installation first (/usr/share/aisbf)
if [ -d "/usr/share/aisbf" ]; then
SHARE_DIR="/usr/share/aisbf"
VENV_DIR="/usr/share/aisbf/venv"
else
# Fall back to user installation (~/.local/share/aisbf)
SHARE_DIR="$HOME/.local/share/aisbf"
VENV_DIR="$HOME/.local/share/aisbf/venv"
fi
# Function to create venv if it doesn't exist
ensure_venv() {{
......@@ -222,7 +230,7 @@ setup(
"aisbf": ["*.json"],
},
data_files=[
# Install to /usr/local/share/aisbf (system-wide)
# Install to /usr/share/aisbf (system-wide)
('share/aisbf', [
'main.py',
'requirements.txt',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment