#!/bin/bash set -e REPO_URL="https://github.com/MyAISandbox/server-toolkit.git" INSTALL_DIR="$HOME/.server-toolkit" BIN_DIR="$HOME/.local/bin" echo "" echo "╔════════════════════════════════════════════════╗" echo "║ Server Toolkit Installer ║" echo "║ Отказоустойчивый инструмент управления ║" echo "╚════════════════════════════════════════════════╝" echo "" check_os() { if [ -f /etc/os-release ]; then . /etc/os-release if [[ "$ID" != "ubuntu" && "$ID_LIKE" != *"ubuntu"* && "$ID_LIKE" != *"debian"* ]]; then echo "❌ Error: This tool is designed for Ubuntu/Debian systems" echo " Detected: $NAME" exit 1 fi echo "✓ OS: $NAME $VERSION" else echo "⚠ Warning: Cannot detect OS, continuing anyway..." fi } check_sudo() { if ! sudo -n true 2>/dev/null; then echo "⚠ Sudo access required. You may be prompted for password." sudo -v fi echo "✓ Sudo access confirmed" } install_dependencies() { echo "" echo "Installing dependencies..." sudo apt-get update -qq if ! command -v python3 &> /dev/null; then echo " Installing Python 3..." sudo apt-get install -y python3 python3-pip python3-venv fi if ! command -v git &> /dev/null; then echo " Installing Git..." sudo apt-get install -y git fi echo "✓ Dependencies installed" } clone_or_update() { if [ -d "$INSTALL_DIR" ]; then echo "" echo "Existing installation found, updating..." cd "$INSTALL_DIR" git pull origin main else echo "" echo "Cloning repository..." git clone "$REPO_URL" "$INSTALL_DIR" fi echo "✓ Repository ready" } install_tool() { echo "" echo "Installing Server Toolkit..." cd "$INSTALL_DIR" if [ ! -d ".venv" ]; then echo " Creating virtual environment..." python3 -m venv .venv fi echo " Installing Python packages..." .venv/bin/pip install -q --upgrade pip .venv/bin/pip install -q -e . echo "✓ Server Toolkit installed" } create_symlink() { echo "" echo "Creating command shortcuts..." mkdir -p "$BIN_DIR" cat > "$BIN_DIR/server-toolkit" << 'SCRIPT' #!/bin/bash INSTALL_DIR="$HOME/.server-toolkit" exec "$INSTALL_DIR/.venv/bin/python" -m server_toolkit "$@" SCRIPT chmod +x "$BIN_DIR/server-toolkit" ln -sf "$BIN_DIR/server-toolkit" "$BIN_DIR/stk" echo "✓ Commands created: server-toolkit, stk" } update_shell_profile() { local shell_profile="" if [ -n "$BASH_VERSION" ]; then shell_profile="$HOME/.bashrc" elif [ -n "$ZSH_VERSION" ]; then shell_profile="$HOME/.zshrc" else shell_profile="$HOME/.profile" fi if ! grep -q "$BIN_DIR" "$shell_profile" 2>/dev/null; then echo "" echo "Adding $BIN_DIR to PATH in $shell_profile..." echo "" >> "$shell_profile" echo '# Server Toolkit' >> "$shell_profile" echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$shell_profile" echo "✓ PATH updated" echo "" echo "⚠ Run: source $shell_profile" echo " Or restart your shell" fi } main() { echo "Starting installation..." echo "" check_os check_sudo install_dependencies clone_or_update install_tool create_symlink update_shell_profile echo "" echo "╔════════════════════════════════════════════════╗" echo "║ ✓ Installation Complete! ║" echo "╚════════════════════════════════════════════════╝" echo "" echo "🚀 Quick Start:" echo "" echo " # Reload your shell configuration:" echo " source ~/.bashrc # or ~/.zshrc" echo "" echo " # Run Server Toolkit:" echo " server-toolkit" echo " # or" echo " stk" echo "" echo " # Install location: $INSTALL_DIR" echo "" } main