Created
May 21, 2025 23:21
-
-
Save kfrancis/03a152dcfe7b239d6024c7f4d4ea5678 to your computer and use it in GitHub Desktop.
Dotnet GPT Codex setup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit on any error | |
set -e | |
# Function to log status with timestamp | |
log() { | |
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | |
} | |
log "🚀 Setting up development environment for AspNetZero application..." | |
# Define variables | |
NODE_VERSION="20" # Updated to match existing environment | |
WORKSPACE_DIR="/workspace" | |
# Determine .NET version from global.json or use latest | |
DOTNET_VERSION="latest" | |
DOTNET_CHANNEL="" | |
if [ -f "global.json" ]; then | |
log "📋 Found global.json, checking for .NET SDK version..." | |
# Extract SDK version from global.json using grep and sed | |
SDK_VERSION=$(grep -o '"version"[^,]*' global.json | sed 's/"version":[[:space:]]*"\([^"]*\)".*/\1/' | tr -d '"' | tr -d ' ') | |
if [ ! -z "$SDK_VERSION" ]; then | |
DOTNET_VERSION="$SDK_VERSION" | |
# Extract major.minor for channel (e.g., "7.0.410" -> "7.0") | |
DOTNET_CHANNEL=$(echo "$SDK_VERSION" | cut -d'.' -f1,2) | |
log "🎯 Using .NET SDK version from global.json: $DOTNET_VERSION (channel: $DOTNET_CHANNEL)" | |
else | |
log "⚠️ Could not parse .NET version from global.json, using latest" | |
fi | |
elif [ -f "$WORKSPACE_DIR/global.json" ]; then | |
log "📋 Found global.json in workspace, checking for .NET SDK version..." | |
SDK_VERSION=$(grep -o '"version"[^,]*' "$WORKSPACE_DIR/global.json" | sed 's/"version":[[:space:]]*"\([^"]*\)".*/\1/' | tr -d '"' | tr -d ' ') | |
if [ ! -z "$SDK_VERSION" ]; then | |
DOTNET_VERSION="$SDK_VERSION" | |
DOTNET_CHANNEL=$(echo "$SDK_VERSION" | cut -d'.' -f1,2) | |
log "🎯 Using .NET SDK version from workspace global.json: $DOTNET_VERSION (channel: $DOTNET_CHANNEL)" | |
else | |
log "⚠️ Could not parse .NET version from workspace global.json, using latest" | |
fi | |
else | |
log "📋 No global.json found, using latest .NET SDK version" | |
fi | |
# Function to check command success | |
check_command() { | |
if [ $? -ne 0 ]; then | |
log "❌ Error: $1 failed" | |
exit 1 | |
fi | |
} | |
# Update package lists | |
log "📦 Updating package lists..." | |
apt-get update | |
check_command "apt-get update" | |
# Install basic utilities (only if not already installed) | |
log "🔧 Installing basic utilities..." | |
apt-get install -y curl wget git unzip build-essential apt-transport-https gnupg2 software-properties-common lsb-release | |
check_command "basic utilities installation" | |
# Install .NET SDK if not already installed | |
log "📦 Installing .NET SDK $DOTNET_VERSION..." | |
if ! command -v dotnet &> /dev/null; then | |
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh | |
chmod +x dotnet-install.sh | |
# Install based on whether we have a specific version or latest | |
if [ "$DOTNET_VERSION" = "latest" ]; then | |
./dotnet-install.sh --version latest --install-dir /usr/share/dotnet | |
elif [ ! -z "$DOTNET_CHANNEL" ]; then | |
./dotnet-install.sh --version "$DOTNET_VERSION" --channel "$DOTNET_CHANNEL" --install-dir /usr/share/dotnet | |
else | |
./dotnet-install.sh --version "$DOTNET_VERSION" --install-dir /usr/share/dotnet | |
fi | |
check_command ".NET SDK installation" | |
rm dotnet-install.sh | |
# Add .NET to PATH in bashrc for persistence | |
echo 'export DOTNET_ROOT=/usr/share/dotnet' >> ~/.bashrc | |
echo 'export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools' >> ~/.bashrc | |
# Set for current session | |
export DOTNET_ROOT=/usr/share/dotnet | |
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools | |
log "✅ .NET SDK $DOTNET_VERSION installed successfully" | |
else | |
DOTNET_VERSION_INSTALLED=$(dotnet --version) | |
log "ℹ️ .NET SDK is already installed: $DOTNET_VERSION_INSTALLED" | |
# Check if installed version matches required version | |
if [ "$DOTNET_VERSION" != "latest" ] && [ "$DOTNET_VERSION_INSTALLED" != "$DOTNET_VERSION" ]; then | |
log "⚠️ Warning: Installed .NET version ($DOTNET_VERSION_INSTALLED) differs from required version ($DOTNET_VERSION)" | |
log "ℹ️ Consider updating or installing the specific version if needed" | |
fi | |
fi | |
# Install .NET global tools with version compatibility | |
log "🔧 Installing .NET global tools..." | |
# Determine appropriate tool versions based on .NET version | |
if [ ! -z "$DOTNET_CHANNEL" ]; then | |
MAJOR_VERSION=$(echo "$DOTNET_CHANNEL" | cut -d'.' -f1) | |
case $MAJOR_VERSION in | |
"6") | |
EF_VERSION="6.0.25" | |
FORMAT_VERSION="5.1.250801" | |
;; | |
"7") | |
EF_VERSION="7.0.15" | |
FORMAT_VERSION="5.1.250801" | |
;; | |
"8") | |
EF_VERSION="8.0.10" | |
FORMAT_VERSION="5.1.250801" | |
;; | |
*) | |
# For .NET 9+ or unknown versions, use latest | |
EF_VERSION="" | |
FORMAT_VERSION="" | |
;; | |
esac | |
else | |
# For latest .NET, use latest tools | |
EF_VERSION="" | |
FORMAT_VERSION="" | |
fi | |
# Install dotnet-ef with appropriate version | |
if ! dotnet tool list -g | grep dotnet-ef &> /dev/null; then | |
log "Installing Entity Framework Core tools..." | |
if [ ! -z "$EF_VERSION" ]; then | |
dotnet tool install -g dotnet-ef --version "$EF_VERSION" || log "⚠️ dotnet-ef installation failed, but continuing..." | |
else | |
dotnet tool install -g dotnet-ef || log "⚠️ dotnet-ef installation failed, but continuing..." | |
fi | |
else | |
log "ℹ️ dotnet-ef is already installed" | |
fi | |
# Install dotnet-format with appropriate version | |
if ! dotnet tool list -g | grep dotnet-format &> /dev/null; then | |
log "Installing dotnet-format..." | |
if [ ! -z "$FORMAT_VERSION" ]; then | |
dotnet tool install -g dotnet-format --version "$FORMAT_VERSION" || log "⚠️ dotnet-format installation failed, but continuing..." | |
else | |
dotnet tool install -g dotnet-format || log "⚠️ dotnet-format installation failed, but continuing..." | |
fi | |
else | |
log "ℹ️ dotnet-format is already installed" | |
fi | |
# Ensure .NET tools directory is in PATH | |
if ! echo $PATH | grep -q "/root/.dotnet/tools"; then | |
log "Adding .NET tools directory to PATH..." | |
echo 'export PATH="$PATH:/root/.dotnet/tools"' >> ~/.bashrc | |
export PATH="$PATH:/root/.dotnet/tools" | |
fi | |
# SQL Server tools installation | |
log "📦 Installing SQL Server tools..." | |
if ! command -v sqlcmd &> /dev/null; then | |
# Create a temporary directory for Microsoft signing key | |
mkdir -p /tmp/mssql-keys | |
cd /tmp/mssql-keys | |
# Download and install Microsoft signing key | |
log "Adding Microsoft repository for SQL tools..." | |
wget -q https://packages.microsoft.com/keys/microsoft.asc | |
cat microsoft.asc | gpg --dearmor > microsoft.gpg | |
install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/ | |
rm microsoft.asc microsoft.gpg | |
# Add Microsoft SQL Server repository | |
log "Adding Microsoft SQL Server repository..." | |
echo "deb [arch=amd64] https://packages.microsoft.com/ubuntu/22.04/prod jammy main" > /etc/apt/sources.list.d/mssql-release.list | |
apt-get update | |
# Install SQL Server tools | |
log "Installing SQL Server command-line tools..." | |
ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev | |
check_command "SQL Server tools installation" | |
# Add SQL Server tools to PATH | |
echo 'export PATH=$PATH:/opt/mssql-tools/bin' >> ~/.bashrc | |
export PATH=$PATH:/opt/mssql-tools/bin | |
cd - > /dev/null | |
log "✅ SQL Server tools installed successfully" | |
else | |
log "ℹ️ SQL Server tools are already installed" | |
fi | |
# Install Redis (if needed) | |
log "📦 Installing Redis..." | |
if ! command -v redis-server &> /dev/null; then | |
apt-get install -y redis-server | |
check_command "Redis installation" | |
log "✅ Redis installed successfully" | |
else | |
log "ℹ️ Redis is already installed" | |
fi | |
# Set up workspace directory | |
if [ ! -d "$WORKSPACE_DIR" ]; then | |
log "📂 Creating workspace directory..." | |
mkdir -p "$WORKSPACE_DIR" | |
fi | |
# Navigate to workspace directory | |
cd "$WORKSPACE_DIR" | |
# Install frontend dependencies (if not already installed) | |
log "🔧 Installing frontend dependencies..." | |
log "Installing Yarn package manager..." | |
npm install -g yarn || log "⚠️ Yarn installation failed, but continuing..." | |
log "Installing Angular CLI..." | |
npm install -g @angular/cli || log "⚠️ Angular CLI installation failed, but continuing..." | |
log "Installing Gulp CLI..." | |
npm install -g gulp-cli || log "⚠️ Gulp CLI installation failed, but continuing..." | |
# Install ESLint for linting | |
log "🔧 Installing ESLint for JavaScript/TypeScript linting..." | |
npm install -g eslint || log "⚠️ ESLint installation failed, but continuing..." | |
# Set environment variables in bashrc for persistence | |
log "⚙️ Setting environment variables..." | |
{ | |
echo 'export ASPNETCORE_ENVIRONMENT=Development' | |
echo 'export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true' | |
echo 'export DOTNET_CLI_TELEMETRY_OPTOUT=1' | |
} >> ~/.bashrc | |
# Set for current session | |
export ASPNETCORE_ENVIRONMENT=Development | |
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true | |
export DOTNET_CLI_TELEMETRY_OPTOUT=1 | |
log "✅ Setup complete! Your environment is now ready for .net development." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment