diff --git a/.github/workflows/main_catoconsting.yml b/.github/workflows/main_catoconsting.yml index 0d87832..79c131d 100644 --- a/.github/workflows/main_catoconsting.yml +++ b/.github/workflows/main_catoconsting.yml @@ -1,56 +1,56 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy -# More GitHub Actions for Azure: https://github.com/Azure/actions - -name: Build and deploy JAR app to Azure Web App - Catoconsting - -on: - push: - branches: - - main - workflow_dispatch: - -jobs: - build: - runs-on: windows-latest - permissions: - contents: read #This is required for actions/checkout - - steps: - - uses: actions/checkout@v4 - - - name: Set up Java version - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'microsoft' - - - name: Build with Maven - run: mvn clean install - - - name: Upload artifact for deployment job - uses: actions/upload-artifact@v4 - with: - name: java-app - path: '${{ github.workspace }}/target/*.jar' - - deploy: - runs-on: windows-latest - needs: build - - - steps: - - name: Download artifact from build job - uses: actions/download-artifact@v4 - with: - name: java-app - - - name: Deploy to Azure Web App - id: deploy-to-webapp - uses: azure/webapps-deploy@v3 - with: - app-name: 'Catoconsting' - slot-name: 'Production' - package: '*.jar' - - publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2294C70C1BD64F72AAF4A8ED0F6CAEF6 }} - +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy JAR app to Azure Web App - Catoconsting + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + permissions: + contents: read #This is required for actions/checkout + + steps: + - uses: actions/checkout@v4 + + - name: Set up Java version + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'microsoft' + + - name: Build with Maven + run: mvn clean install + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v4 + with: + name: java-app + path: '${{ github.workspace }}/target/*.jar' + + deploy: + runs-on: windows-latest + needs: build + + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v4 + with: + name: java-app + + - name: Deploy to Azure Web App + id: deploy-to-webapp + uses: azure/webapps-deploy@v3 + with: + app-name: 'Catoconsting' + slot-name: 'Production' + package: '*.jar' + + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2294C70C1BD64F72AAF4A8ED0F6CAEF6 }} + diff --git a/.specstory/.what-is-this.md b/.specstory/.what-is-this.md index 85690a8..a0e0cb8 100644 --- a/.specstory/.what-is-this.md +++ b/.specstory/.what-is-this.md @@ -1,69 +1,69 @@ -# SpecStory Artifacts Directory - -This directory is automatically created and maintained by the SpecStory extension to preserve your AI chat history. - -## What's Here? - -- `.specstory/history`: Contains auto-saved markdown files of your AI coding sessions - - Each file represents a separate AI chat session - - If you enable auto-save, files are automatically updated as you work - - You can enable/disable the auto-save feature in the SpecStory settings, it is disabled by default -- `.specstory/.project.json`: Contains the persistent project identity for the current workspace - - This file is only present if you enable AI rules derivation - - This is used to provide consistent project identity of your project, even as the workspace is moved or renamed -- `.specstory/ai_rules_backups`: Contains backups of the `.cursor/rules/derived-cursor-rules.mdc` or the `.github/copilot-instructions.md` file - - Backups are automatically created each time the `.cursor/rules/derived-cursor-rules.mdc` or the `.github/copilot-instructions.md` file is updated - - You can enable/disable the AI Rules derivation feature in the SpecStory settings, it is disabled by default -- `.specstory/.gitignore`: Contains directives to exclude non-essential contents of the `.specstory` directory from version control - - Add `/history` to exclude the auto-saved chat history from version control - -## Valuable Uses - -- Capture: Keep your context window up-to-date when starting new Chat/Composer sessions via @ references -- Search: For previous prompts and code snippets -- Learn: Meta-analyze your patterns and learn from your past experiences -- Derive: Keep the AI on course with your past decisions by automatically deriving rules from your AI interactions - -## Version Control - -We recommend keeping this directory under version control to maintain a history of your AI interactions. However, if you prefer not to version these files, you can exclude them by adding this to your `.gitignore`: - -``` -.specstory/** -``` - -We recommend __not__ keeping the `.specstory/ai_rules_backups` directory under version control if you are already using git to version your AI rules, and committing regularly. You can exclude it by adding this to your `.gitignore`: - -``` -.specstory/ai_rules_backups -``` - -## Searching Your Codebase - -When searching your codebase, search results may include your previous AI coding interactions. To focus solely on your actual code files, you can exclude the AI interaction history from search results. - -To exclude AI interaction history: - -1. Open the "Find in Files" search in Cursor or VSCode (Cmd/Ctrl + Shift + F) -2. Navigate to the "files to exclude" section -3. Add the following pattern: - -``` -.specstory/* -``` - -This will ensure your searches only return results from your working codebase files. - -## Notes - -- Auto-save only works when Cursor or VSCode flushes sqlite database data to disk. This results in a small delay after the AI response is complete before SpecStory can save the history. - -## Settings - -You can control auto-saving behavior in Cursor or VSCode: - -1. Open Cursor/Code → Settings → VS Code Settings (Cmd/Ctrl + ,) -2. Search for "SpecStory" -3. Find "Auto Save" setting to enable/disable - +# SpecStory Artifacts Directory + +This directory is automatically created and maintained by the SpecStory extension to preserve your AI chat history. + +## What's Here? + +- `.specstory/history`: Contains auto-saved markdown files of your AI coding sessions + - Each file represents a separate AI chat session + - If you enable auto-save, files are automatically updated as you work + - You can enable/disable the auto-save feature in the SpecStory settings, it is disabled by default +- `.specstory/.project.json`: Contains the persistent project identity for the current workspace + - This file is only present if you enable AI rules derivation + - This is used to provide consistent project identity of your project, even as the workspace is moved or renamed +- `.specstory/ai_rules_backups`: Contains backups of the `.cursor/rules/derived-cursor-rules.mdc` or the `.github/copilot-instructions.md` file + - Backups are automatically created each time the `.cursor/rules/derived-cursor-rules.mdc` or the `.github/copilot-instructions.md` file is updated + - You can enable/disable the AI Rules derivation feature in the SpecStory settings, it is disabled by default +- `.specstory/.gitignore`: Contains directives to exclude non-essential contents of the `.specstory` directory from version control + - Add `/history` to exclude the auto-saved chat history from version control + +## Valuable Uses + +- Capture: Keep your context window up-to-date when starting new Chat/Composer sessions via @ references +- Search: For previous prompts and code snippets +- Learn: Meta-analyze your patterns and learn from your past experiences +- Derive: Keep the AI on course with your past decisions by automatically deriving rules from your AI interactions + +## Version Control + +We recommend keeping this directory under version control to maintain a history of your AI interactions. However, if you prefer not to version these files, you can exclude them by adding this to your `.gitignore`: + +``` +.specstory/** +``` + +We recommend __not__ keeping the `.specstory/ai_rules_backups` directory under version control if you are already using git to version your AI rules, and committing regularly. You can exclude it by adding this to your `.gitignore`: + +``` +.specstory/ai_rules_backups +``` + +## Searching Your Codebase + +When searching your codebase, search results may include your previous AI coding interactions. To focus solely on your actual code files, you can exclude the AI interaction history from search results. + +To exclude AI interaction history: + +1. Open the "Find in Files" search in Cursor or VSCode (Cmd/Ctrl + Shift + F) +2. Navigate to the "files to exclude" section +3. Add the following pattern: + +``` +.specstory/* +``` + +This will ensure your searches only return results from your working codebase files. + +## Notes + +- Auto-save only works when Cursor or VSCode flushes sqlite database data to disk. This results in a small delay after the AI response is complete before SpecStory can save the history. + +## Settings + +You can control auto-saving behavior in Cursor or VSCode: + +1. Open Cursor/Code → Settings → VS Code Settings (Cmd/Ctrl + ,) +2. Search for "SpecStory" +3. Find "Auto Save" setting to enable/disable + Auto-save occurs when changes are detected in the sqlite database, or every 2 minutes as a safety net. \ No newline at end of file diff --git a/.specstory/history/2025-07-06_16-11Z-install-jave.md b/.specstory/history/2025-07-06_16-11Z-install-jave.md index fccf726..edb83d9 100644 --- a/.specstory/history/2025-07-06_16-11Z-install-jave.md +++ b/.specstory/history/2025-07-06_16-11Z-install-jave.md @@ -1,16 +1,16 @@ - - -# install jave (2025-07-06 16:11Z) - -_**User**_ - -install jave - ---- - -_**Assistant**_ - -I'll help you install Java. Let me check your current workspace and system to provide the best installation approach. - ---- - + + +# install jave (2025-07-06 16:11Z) + +_**User**_ + +install jave + +--- + +_**Assistant**_ + +I'll help you install Java. Let me check your current workspace and system to provide the best installation approach. + +--- + diff --git a/lib/common.psm1 b/lib/common.psm1 new file mode 100644 index 0000000..074f88a --- /dev/null +++ b/lib/common.psm1 @@ -0,0 +1,113 @@ +<# +.SYNOPSIS + Common module for Catoconsting PowerShell setup scripts +.DESCRIPTION + Contains shared functions and utilities used across PowerShell setup scripts +.NOTES + Usage: Import this module from other scripts + Import-Module "$PSScriptRoot\lib\common.psm1" -Force +#> + +# Logging function +# Usage: Write-Log "message" ["level"] +function Write-Log { + param([string]$Message, [string]$Level = "INFO") + $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" + $logMessage = "[$timestamp] [$Level] $Message" + Write-Host $logMessage + if ($LogFile) { + Add-Content -Path $LogFile -Value $logMessage + } +} + +# Check if running as Administrator +# Returns $true if running as admin, $false otherwise +function Test-Administrator { + $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) + return $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +} + +# Require Administrator privileges +# Throws an error if not running as Administrator +function Require-Administrator { + if (-NOT (Test-Administrator)) { + Write-Log "This script requires Administrator privileges" "ERROR" + throw "Administrator privileges required" + } +} + +# Install Chocolatey package manager if not present +function Install-Chocolatey { + Write-Log "Checking for Chocolatey package manager..." + if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { + Write-Log "Installing Chocolatey package manager..." + try { + Set-ExecutionPolicy Bypass -Scope Process -Force + [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 + Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) + Write-Log "Chocolatey installed successfully" "SUCCESS" + + # Refresh environment variables + Update-EnvironmentPath + } catch { + Write-Log "Failed to install Chocolatey: $($_.Exception.Message)" "ERROR" + throw + } + } else { + Write-Log "Chocolatey is already installed" "SUCCESS" + } +} + +# Refresh environment PATH variable +function Update-EnvironmentPath { + $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") +} + +# Install Java JDK 17 (Microsoft distribution) +function Install-JavaJDK17 { + Write-Log "Checking for Java JDK 17..." + $javaVersion = $null + try { + $javaVersion = & java -version 2>&1 | Select-String "version" | ForEach-Object { $_.ToString() } + } catch { + Write-Log "Java not found" + } + + if (-not $javaVersion -or $javaVersion -notmatch "17\.") { + Write-Log "Installing Microsoft OpenJDK 17..." + try { + choco install microsoft-openjdk17 -y + Write-Log "Java JDK 17 installed successfully" "SUCCESS" + + # Refresh environment + Update-EnvironmentPath + } catch { + Write-Log "Failed to install Java JDK 17: $($_.Exception.Message)" "ERROR" + } + } else { + Write-Log "Java JDK 17 is already installed: $javaVersion" "SUCCESS" + } +} + +# Set JAVA_HOME environment variable if not set +function Set-JavaHome { + if (-not $env:JAVA_HOME) { + Write-Log "Setting JAVA_HOME environment variable..." + $javaPath = (Get-Command java -ErrorAction SilentlyContinue).Source + if ($javaPath) { + $javaHome = Split-Path (Split-Path $javaPath -Parent) -Parent + [System.Environment]::SetEnvironmentVariable("JAVA_HOME", $javaHome, "Machine") + $env:JAVA_HOME = $javaHome + Write-Log "JAVA_HOME set to: $javaHome" "SUCCESS" + } + } +} + +# Export module members +Export-ModuleMember -Function Write-Log +Export-ModuleMember -Function Test-Administrator +Export-ModuleMember -Function Require-Administrator +Export-ModuleMember -Function Install-Chocolatey +Export-ModuleMember -Function Update-EnvironmentPath +Export-ModuleMember -Function Install-JavaJDK17 +Export-ModuleMember -Function Set-JavaHome diff --git a/lib/common.sh b/lib/common.sh new file mode 100755 index 0000000..e10e636 --- /dev/null +++ b/lib/common.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Common library for Catoconsting setup scripts +# Contains shared functions and constants used across setup scripts +# +# Usage: source this file from other scripts +# source "$(dirname "$0")/lib/common.sh" + +# Colors for terminal output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +WHITE='\033[1;37m' +NC='\033[0m' + +# Logging function +# Usage: log "message" ["level"] +log() { + local level=${2:-INFO} + local message="[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $1" + echo -e "$message" + if [[ -n "$LOG_FILE" ]]; then + echo "$message" >> "$LOG_FILE" + fi +} + +# Check if command exists +# Usage: command_exists "command_name" +command_exists() { + command -v "$1" &> /dev/null +} + +# Detect OS and package manager +# Sets global variables: OS, PKG_MGR +detect_os() { + if [[ "$OSTYPE" == "darwin"* ]]; then + OS="macos" + PKG_MGR="brew" + elif [[ -f /etc/debian_version ]]; then + OS="debian" + PKG_MGR="apt" + elif [[ -f /etc/redhat-release ]]; then + OS="redhat" + if command -v dnf &> /dev/null; then + PKG_MGR="dnf" + else + PKG_MGR="yum" + fi + else + OS="unknown" + PKG_MGR="unknown" + fi +} diff --git a/setup-desktop.ps1 b/setup-desktop.ps1 index a3be231..e382bee 100644 --- a/setup-desktop.ps1 +++ b/setup-desktop.ps1 @@ -26,81 +26,23 @@ param( $ErrorActionPreference = "Continue" -# Logging function -function Write-Log { - param([string]$Message, [string]$Level = "INFO") - $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" - $logMessage = "[$timestamp] [$Level] $Message" - Write-Host $logMessage - if ($LogFile) { - Add-Content -Path $LogFile -Value $logMessage - } -} +# Import common module +Import-Module "$PSScriptRoot\lib\common.psm1" -Force # Check if running as Administrator -if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - Write-Log "This script requires Administrator privileges" "ERROR" - throw "Administrator privileges required" -} +Require-Administrator Write-Log "=== Desktop PC Setup Started ===" "INFO" Write-Log "Computer Name: $ComputerName" # Step 1: Install Chocolatey if not present -Write-Log "Checking for Chocolatey package manager..." -if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { - Write-Log "Installing Chocolatey package manager..." - try { - Set-ExecutionPolicy Bypass -Scope Process -Force - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 - Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) - Write-Log "Chocolatey installed successfully" "SUCCESS" - - # Refresh environment variables - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") - } catch { - Write-Log "Failed to install Chocolatey: $($_.Exception.Message)" "ERROR" - throw - } -} else { - Write-Log "Chocolatey is already installed" "SUCCESS" -} +Install-Chocolatey # Step 2: Install Java JDK 17 (Microsoft distribution) -Write-Log "Checking for Java JDK 17..." -$javaVersion = $null -try { - $javaVersion = & java -version 2>&1 | Select-String "version" | ForEach-Object { $_.ToString() } -} catch { - Write-Log "Java not found" -} - -if (-not $javaVersion -or $javaVersion -notmatch "17\.") { - Write-Log "Installing Microsoft OpenJDK 17..." - try { - choco install microsoft-openjdk17 -y - Write-Log "Java JDK 17 installed successfully" "SUCCESS" - - # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") - } catch { - Write-Log "Failed to install Java JDK 17: $($_.Exception.Message)" "ERROR" - } -} else { - Write-Log "Java JDK 17 is already installed: $javaVersion" "SUCCESS" -} +Install-JavaJDK17 # Set JAVA_HOME if not set -if (-not $env:JAVA_HOME) { - Write-Log "Setting JAVA_HOME environment variable..." - $javaPath = (Get-Command java -ErrorAction SilentlyContinue).Source - if ($javaPath) { - $javaHome = Split-Path (Split-Path $javaPath -Parent) -Parent - [System.Environment]::SetEnvironmentVariable("JAVA_HOME", $javaHome, "Machine") - $env:JAVA_HOME = $javaHome - Write-Log "JAVA_HOME set to: $javaHome" "SUCCESS" - } -} +Set-JavaHome # Step 3: Install Apache Maven Write-Log "Checking for Apache Maven..." @@ -111,7 +53,7 @@ if (-not (Get-Command mvn -ErrorAction SilentlyContinue)) { Write-Log "Maven installed successfully" "SUCCESS" # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") + Update-EnvironmentPath } catch { Write-Log "Failed to install Maven: $($_.Exception.Message)" "ERROR" } @@ -129,7 +71,7 @@ if (-not (Get-Command git -ErrorAction SilentlyContinue)) { Write-Log "Git installed successfully" "SUCCESS" # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") + Update-EnvironmentPath } catch { Write-Log "Failed to install Git: $($_.Exception.Message)" "ERROR" } @@ -151,7 +93,7 @@ if (-not (Get-Command code -ErrorAction SilentlyContinue)) { Start-Sleep -Seconds 5 # Wait for VS Code installation to complete # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") + Update-EnvironmentPath if (Get-Command code -ErrorAction SilentlyContinue) { code --install-extension vscjava.vscode-java-pack --force 2>&1 | Out-Null diff --git a/setup-desktop.sh b/setup-desktop.sh index 7f7631a..34ea9b5 100755 --- a/setup-desktop.sh +++ b/setup-desktop.sh @@ -18,49 +18,9 @@ set -e COMPUTER_NAME=${1:-$(hostname)} LOG_FILE=${2:-"setup-log-$COMPUTER_NAME-$(date +%Y%m%d-%H%M%S).txt"} -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -CYAN='\033[0;36m' -WHITE='\033[1;37m' -NC='\033[0m' - -# Detect OS -detect_os() { - if [[ "$OSTYPE" == "darwin"* ]]; then - OS="macos" - PKG_MGR="brew" - elif [[ -f /etc/debian_version ]]; then - OS="debian" - PKG_MGR="apt" - elif [[ -f /etc/redhat-release ]]; then - OS="redhat" - if command -v dnf &> /dev/null; then - PKG_MGR="dnf" - else - PKG_MGR="yum" - fi - else - OS="unknown" - PKG_MGR="unknown" - fi -} - -# Logging function -log() { - local level=${2:-INFO} - local message="[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $1" - echo -e "$message" - if [[ -n "$LOG_FILE" ]]; then - echo "$message" >> "$LOG_FILE" - fi -} - -# Check if command exists -command_exists() { - command -v "$1" &> /dev/null -} +# Source common library +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/lib/common.sh" # Install package manager (Homebrew for macOS) install_package_manager() { diff --git a/setup-environment.ps1 b/setup-environment.ps1 index f1a6607..faf6202 100644 --- a/setup-environment.ps1 +++ b/setup-environment.ps1 @@ -24,25 +24,16 @@ param( [string]$ComputerName = $env:COMPUTERNAME ) -# Require Administrator -if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - Write-Error "This script requires Administrator privileges. Please run as Administrator." - exit 1 -} - # Script configuration $ErrorActionPreference = "Stop" $ScriptRoot = $PSScriptRoot $LogFile = Join-Path $ScriptRoot "setup-log-$ComputerName-$(Get-Date -Format 'yyyyMMdd-HHmmss').txt" -# Logging function -function Write-Log { - param([string]$Message, [string]$Level = "INFO") - $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" - $logMessage = "[$timestamp] [$Level] $Message" - Write-Host $logMessage - Add-Content -Path $LogFile -Value $logMessage -} +# Import common module +Import-Module "$PSScriptRoot\lib\common.psm1" -Force + +# Require Administrator +Require-Administrator # Banner function Show-Banner { diff --git a/setup-environment.sh b/setup-environment.sh index c1848ab..1e92ab0 100755 --- a/setup-environment.sh +++ b/setup-environment.sh @@ -19,20 +19,8 @@ COMPUTER_NAME=$(hostname) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LOG_FILE="$SCRIPT_DIR/setup-log-$COMPUTER_NAME-$(date +%Y%m%d-%H%M%S).txt" -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -CYAN='\033[0;36m' -NC='\033[0m' # No Color - -# Logging function -log() { - local level=${2:-INFO} - local message="[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $1" - echo -e "$message" - echo "$message" >> "$LOG_FILE" -} +# Source common library +source "$SCRIPT_DIR/lib/common.sh" # Check if running as root/sudo check_privileges() { diff --git a/setup-server.ps1 b/setup-server.ps1 index 2b7cb3d..2d417ec 100644 --- a/setup-server.ps1 +++ b/setup-server.ps1 @@ -26,22 +26,11 @@ param( $ErrorActionPreference = "Continue" -# Logging function -function Write-Log { - param([string]$Message, [string]$Level = "INFO") - $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" - $logMessage = "[$timestamp] [$Level] $Message" - Write-Host $logMessage - if ($LogFile) { - Add-Content -Path $LogFile -Value $logMessage - } -} +# Import common module +Import-Module "$PSScriptRoot\lib\common.psm1" -Force # Check if running as Administrator -if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { - Write-Log "This script requires Administrator privileges" "ERROR" - throw "Administrator privileges required" -} +Require-Administrator # Check if running on Windows Server $osInfo = Get-CimInstance -ClassName Win32_OperatingSystem @@ -62,60 +51,13 @@ $LogDir = Join-Path $AppDir "logs" $ConfigDir = Join-Path $AppDir "config" # Step 1: Install Chocolatey if not present -Write-Log "Checking for Chocolatey package manager..." -if (-not (Get-Command choco -ErrorAction SilentlyContinue)) { - Write-Log "Installing Chocolatey package manager..." - try { - Set-ExecutionPolicy Bypass -Scope Process -Force - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 - Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) - Write-Log "Chocolatey installed successfully" "SUCCESS" - - # Refresh environment variables - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") - } catch { - Write-Log "Failed to install Chocolatey: $($_.Exception.Message)" "ERROR" - throw - } -} else { - Write-Log "Chocolatey is already installed" "SUCCESS" -} +Install-Chocolatey # Step 2: Install Java JDK 17 (Microsoft distribution) -Write-Log "Checking for Java JDK 17..." -$javaVersion = $null -try { - $javaVersion = & java -version 2>&1 | Select-String "version" | ForEach-Object { $_.ToString() } -} catch { - Write-Log "Java not found" -} - -if (-not $javaVersion -or $javaVersion -notmatch "17\.") { - Write-Log "Installing Microsoft OpenJDK 17..." - try { - choco install microsoft-openjdk17 -y - Write-Log "Java JDK 17 installed successfully" "SUCCESS" - - # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") - } catch { - Write-Log "Failed to install Java JDK 17: $($_.Exception.Message)" "ERROR" - } -} else { - Write-Log "Java JDK 17 is already installed: $javaVersion" "SUCCESS" -} +Install-JavaJDK17 # Set JAVA_HOME if not set -if (-not $env:JAVA_HOME) { - Write-Log "Setting JAVA_HOME environment variable..." - $javaPath = (Get-Command java -ErrorAction SilentlyContinue).Source - if ($javaPath) { - $javaHome = Split-Path (Split-Path $javaPath -Parent) -Parent - [System.Environment]::SetEnvironmentVariable("JAVA_HOME", $javaHome, "Machine") - $env:JAVA_HOME = $javaHome - Write-Log "JAVA_HOME set to: $javaHome" "SUCCESS" - } -} +Set-JavaHome # Step 3: Install IIS Web Server and components Write-Log "Checking for IIS..." @@ -231,7 +173,7 @@ try { Write-Log "NSSM installed successfully" "SUCCESS" # Refresh environment - $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") + Update-EnvironmentPath } else { Write-Log "NSSM is already installed" "SUCCESS" } diff --git a/setup-server.sh b/setup-server.sh index 1b170d6..6f29df1 100755 --- a/setup-server.sh +++ b/setup-server.sh @@ -18,13 +18,9 @@ set -e COMPUTER_NAME=${1:-$(hostname)} LOG_FILE=${2:-"setup-log-$COMPUTER_NAME-$(date +%Y%m%d-%H%M%S).txt"} -# Colors -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -CYAN='\033[0;36m' -WHITE='\033[1;37m' -NC='\033[0m' +# Source common library +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/lib/common.sh" # Configuration APP_NAME="Catoconsting" @@ -34,39 +30,6 @@ LOG_DIR="$APP_DIR/logs" CONFIG_DIR="$APP_DIR/config" SERVICE_NAME="catoconsting" -# Detect OS -detect_os() { - if [[ -f /etc/debian_version ]]; then - OS="debian" - PKG_MGR="apt" - elif [[ -f /etc/redhat-release ]]; then - OS="redhat" - if command -v dnf &> /dev/null; then - PKG_MGR="dnf" - else - PKG_MGR="yum" - fi - else - OS="unknown" - PKG_MGR="unknown" - fi -} - -# Logging function -log() { - local level=${2:-INFO} - local message="[$(date '+%Y-%m-%d %H:%M:%S')] [$level] $1" - echo -e "$message" - if [[ -n "$LOG_FILE" ]]; then - echo "$message" >> "$LOG_FILE" - fi -} - -# Check if command exists -command_exists() { - command -v "$1" &> /dev/null -} - # Check if running as root check_root() { if [[ $EUID -ne 0 ]]; then