AmberDB

 view release on metacpan or  search on metacpan

bin/setup_windows.ps1  view on Meta::CPAN

    [string]$Drive = "R:",
    [string]$Size = "512M",
    [string]$ProjectName = "",
    [string]$ProjectDir = "",
    [string]$User = ""
)

# 1. Resolve Project Paths
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
if (-not $ProjectDir) {
    $ProjectDir = Split-Path -Parent $scriptDir
}
$ProjectDir = (Resolve-Path $ProjectDir).Path

if (Test-Path (Join-Path $ProjectDir "tables")) {
    $dbDir  = $ProjectDir
    $appDir = Split-Path -Parent $ProjectDir
}
elseif (Test-Path (Join-Path $ProjectDir "dbstore")) {
    $dbDir  = Join-Path $ProjectDir "dbstore"
    $appDir = $ProjectDir
}
elseif (Test-Path (Join-Path $ProjectDir "dbase")) {
    $dbDir  = Join-Path $ProjectDir "dbase"
    $appDir = $ProjectDir
}
else {
    $dbDir  = $ProjectDir
    $appDir = $ProjectDir
}

if (-not $ProjectName -or $ProjectName -eq "dbstore" -or $ProjectName -eq "dbase") {
    $ProjectName = Split-Path -Leaf $appDir
    if ($ProjectName -eq "dbstore" -or $ProjectName -eq "dbase") {
        $ProjectName = Split-Path -Leaf (Split-Path -Parent $appDir)
    }
}

$ramdiskDir   = Join-Path $dbDir "ramdisk"
$driveRoot = "$Drive\"
if ($User -and $ProjectName -and $ProjectName -ne $User -and $ProjectName -ne "amberdb") {
    $projectRam = Join-Path (Join-Path $driveRoot $User) $ProjectName
}
elseif ($User) {
    $projectRam = Join-Path $driveRoot $User
}
else {
    $projectRam = Join-Path $driveRoot $ProjectName
}
$lockDir      = Join-Path $dbDir "lock"
$taskName     = "AmberDB-Watchdog-$ProjectName"
$daemonScript = Join-Path $scriptDir "amberdb_daemon.pl"
$libDir       = Join-Path $appDir "lib"

# Subfolders required by AmberDB
$subdirs = @("tables", "config", "schema", "lock", "pids")

function Check-Admin {
    $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
    if (-not $isAdmin) {
        Write-Error "[ERROR] Administrator privileges required! Please right-click PowerShell and select 'Run as Administrator'."
        exit 1
    }
}

function Install-ImDisk {
    Write-Host "[SETUP] Checking ImDisk installation..." -ForegroundColor Cyan

    $imdiskCmd = Get-Command imdisk -ErrorAction SilentlyContinue
    if ($imdiskCmd) {
        Write-Host "[OK] ImDisk is already installed on your system ($($imdiskCmd.Source))." -ForegroundColor Green
        return
    }

    Check-Admin

    Write-Host "[SETUP] ImDisk not detected. Attempting automated installation..." -ForegroundColor Cyan

    # 1. Try winget (Windows Package Manager)
    $wingetCmd = Get-Command winget -ErrorAction SilentlyContinue
    if ($wingetCmd) {
        Write-Host "[SETUP] Installing ImDisk via Windows Package Manager (winget)..." -ForegroundColor Cyan
        & winget install --id LTR.ImDisk -e --silent --accept-package-agreements --accept-source-agreements
        $imdiskCmd = Get-Command imdisk -ErrorAction SilentlyContinue
        if ($imdiskCmd) {
            Write-Host "[SUCCESS] ImDisk installed successfully via winget!" -ForegroundColor Green
            return
        }
    }

    # 2. Try Chocolatey
    $chocoCmd = Get-Command choco -ErrorAction SilentlyContinue
    if ($chocoCmd) {
        Write-Host "[SETUP] Installing ImDisk via Chocolatey..." -ForegroundColor Cyan
        & choco install imdisk-toolkit -y
        $imdiskCmd = Get-Command imdisk -ErrorAction SilentlyContinue
        if ($imdiskCmd) {
            Write-Host "[SUCCESS] ImDisk installed successfully via Chocolatey!" -ForegroundColor Green
            return
        }
    }

    # 3. Direct download from SourceForge
    Write-Host "[SETUP] Downloading ImDisk Toolkit from SourceForge..." -ForegroundColor Cyan
    $downloadUrl = "https://sourceforge.net/projects/imdisk-toolkit/files/latest/download"
    $installerPath = Join-Path $env:TEMP "ImDiskTk-setup.exe"

    try {
        [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
        Invoke-WebRequest -Uri $downloadUrl -OutFile $installerPath -UserAgent "Mozilla/5.0"
        if (Test-Path $installerPath) {
            Write-Host "[SETUP] Running ImDisk installer silently..." -ForegroundColor Cyan
            Start-Process -FilePath $installerPath -ArgumentList "/SILENT", "/NORESTART" -Wait
            Write-Host "[SUCCESS] ImDisk Toolkit installation completed!" -ForegroundColor Green
            return
        }
    }
    catch {
        Write-Warning "[WARN] Automatic download failed: $_"
    }



( run in 1.394 second using v1.01-cache-2.11-cpan-e623d60df62 )