Files
code-tools/.devcontainer/post-start.sh
Travis Vasceannie bb469f8d2b Refactor workspace setup script for cross-platform compatibility and improved user management
- Added system detection logic to handle different OS types (Linux, macOS, Windows).
- Enhanced user creation logic to support non-root execution and proper ownership.
- Updated directory creation to use dynamic home paths based on detected OS.
- Improved Git configuration and metadata capture with error handling.
- Modularized system package installation based on OS type.
- Streamlined Node.js, Python, and Rust setup scripts with error handling.
- Updated shell configuration to include dynamic aliases and environment info script.
- Deprecated `devcontainer_image` variable in favor of `devcontainer_repo_url` for better repository management.
- Adjusted Terraform workspace configuration to support new repository URL and caching options.
2025-09-07 20:56:56 +00:00

53 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "Running post-start setup..."
# Set up environment variables
export PATH="$PATH:$HOME/.local/bin:$HOME/bin"
# Initialize any services that need to be started
if [ -n "$ENABLE_SERVICES" ] && [ "$ENABLE_SERVICES" = "true" ]; then
echo "Services are enabled, checking connectivity..."
# Wait for services to be ready (if enabled)
if [ -n "$POSTGRES_URL" ]; then
echo "Waiting for PostgreSQL..."
for i in {1..30}; do
if pg_isready -d "$POSTGRES_URL" 2>/dev/null; then
echo "PostgreSQL is ready!"
break
fi
sleep 1
done
fi
if [ -n "$REDIS_URL" ]; then
echo "Checking Redis connectivity..."
# Parse Redis URL to get host and port
REDIS_HOST=$(echo "$REDIS_URL" | sed -E 's|redis://[^@]*@([^:]+):.*|\1|')
REDIS_PORT=$(echo "$REDIS_URL" | sed -E 's|.*:([0-9]+).*|\1|')
for i in {1..30}; do
if redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" ping 2>/dev/null | grep -q PONG; then
echo "Redis is ready!"
break
fi
sleep 1
done
fi
fi
# Display welcome message
echo ""
echo "🚀 Workspace is ready!"
echo "📂 Working directory: $(pwd)"
echo "🌿 Git branch: $(git branch --show-current 2>/dev/null || echo 'no repo')"
echo ""
# Clone repository if specified and not already present
if [ -n "$CODER_WORKSPACE_REPO" ] && [ ! -d .git ]; then
echo "Cloning repository: $CODER_WORKSPACE_REPO"
git clone "$CODER_WORKSPACE_REPO" .
fi
echo "Post-start setup complete!"