diff --git a/install.ps1 b/install.ps1 index 2e64989..9f8460a 100644 --- a/install.ps1 +++ b/install.ps1 @@ -87,30 +87,86 @@ if ($List) { exit 0 } -# --- Check deps --- -if ($CheckDeps) { +# --- Check deps function --- +function Invoke-DependencyCheck { Write-Host '=== Running Dependency Checks ===' -ForegroundColor Cyan Write-Host '' + + $missingDeps = @() + Write-Host '--- Windows Dependencies ---' -ForegroundColor Yellow - $winScript = Join-Path $ScriptDir 'plugins\windows-reverse-engineering\skills\windows-reverse-engineering\scripts\check-deps.ps1' - if (Test-Path $winScript) { - & powershell -ExecutionPolicy Bypass -File $winScript + $winCheck = Join-Path $ScriptDir 'plugins\windows-reverse-engineering\skills\windows-reverse-engineering\scripts\check-deps.ps1' + $winInstall = Join-Path $ScriptDir 'plugins\windows-reverse-engineering\skills\windows-reverse-engineering\scripts\install-dep.ps1' + if (Test-Path $winCheck) { + $winOut = & powershell -ExecutionPolicy Bypass -File $winCheck + foreach ($line in $winOut) { + $lineStr = [string]$line + if ($lineStr -match '^INSTALL_') { + $depInfo = @{ + OS = 'Windows' + Name = ($lineStr -split ':')[1] + InstallScript = $winInstall + } + $missingDeps += $depInfo + } else { + Write-Host $lineStr + } + } } else { - Write-Host ('Windows check-deps.ps1 not found at: ' + $winScript) -ForegroundColor Red + Write-Host ('Windows check-deps.ps1 not found at: ' + $winCheck) -ForegroundColor Red } + Write-Host '' Write-Host '--- Android Dependencies ---' -ForegroundColor Yellow - $androidScript = Join-Path $ScriptDir 'plugins\android-reverse-engineering\skills\android-reverse-engineering\scripts\check-deps.sh' - if (Test-Path $androidScript) { + $androidCheck = Join-Path $ScriptDir 'plugins\android-reverse-engineering\skills\android-reverse-engineering\scripts\check-deps.sh' + $androidInstall = Join-Path $ScriptDir 'plugins\android-reverse-engineering\skills\android-reverse-engineering\scripts\install-dep.sh' + if (Test-Path $androidCheck) { $bashCmd = Get-Command bash -ErrorAction SilentlyContinue if ($bashCmd) { - & bash $androidScript + $andOut = & bash $androidCheck + foreach ($line in $andOut) { + $lineStr = [string]$line + if ($lineStr -match '^INSTALL_') { + $depInfo = @{ + OS = 'Android' + Name = ($lineStr -split ':')[1] + InstallScript = $androidInstall + } + $missingDeps += $depInfo + } else { + Write-Host $lineStr + } + } } else { Write-Host 'bash not found. Android dependency check requires WSL or Git Bash.' -ForegroundColor Yellow } } else { - Write-Host ('Android check-deps.sh not found at: ' + $androidScript) -ForegroundColor Red + Write-Host ('Android check-deps.sh not found at: ' + $androidCheck) -ForegroundColor Red } + + if ($missingDeps.Count -gt 0) { + Write-Host '' + $totalMissing = $missingDeps.Count + $ans = Read-Host ('Detected {0} missing dependencies (optional/required). Would you like to install them now? (y/N)' -f $totalMissing) + if ($ans -match '^y') { + Write-Host '' + foreach ($depInfo in $missingDeps) { + Write-Host ('--- Installing ' + $depInfo.OS + ' dependency: ' + $depInfo.Name + ' ---') -ForegroundColor Cyan + if ($depInfo.OS -eq 'Windows') { + & powershell -ExecutionPolicy Bypass -File $depInfo.InstallScript $depInfo.Name + } else { + & bash $depInfo.InstallScript $depInfo.Name + } + } + Write-Host '' + Write-Host 'Done installing dependencies.' -ForegroundColor Green + Write-Host 'Restart your terminal if any PATH variables were updated.' -ForegroundColor Yellow + } + } +} + +if ($CheckDeps) { + Invoke-DependencyCheck exit 0 } diff --git a/install.sh b/install.sh index cd1a5d6..345d8e9 100644 --- a/install.sh +++ b/install.sh @@ -81,27 +81,82 @@ if $LIST; then exit 0 fi -# --- Check deps --- -if $CHECK_DEPS; then +# --- Check deps function --- +invoke_dependency_check() { echo "=== Running Dependency Checks ===" echo "" + + local missing_win=() + local missing_android=() + echo "--- Windows Dependencies ---" - WIN_SCRIPT="$SCRIPT_DIR/plugins/windows-reverse-engineering/skills/windows-reverse-engineering/scripts/check-deps.ps1" - if command -v powershell &>/dev/null && [ -f "$WIN_SCRIPT" ]; then - powershell -ExecutionPolicy Bypass -File "$WIN_SCRIPT" || true - elif command -v pwsh &>/dev/null && [ -f "$WIN_SCRIPT" ]; then - pwsh -ExecutionPolicy Bypass -File "$WIN_SCRIPT" || true + local win_check="$SCRIPT_DIR/plugins/windows-reverse-engineering/skills/windows-reverse-engineering/scripts/check-deps.ps1" + local win_install="$SCRIPT_DIR/plugins/windows-reverse-engineering/skills/windows-reverse-engineering/scripts/install-dep.ps1" + if command -v powershell &>/dev/null && [ -f "$win_check" ]; then + while IFS= read -r line; do + if [[ "$line" =~ ^INSTALL_(REQUIRED|OPTIONAL):(.+)$ ]]; then + missing_win+=("${BASH_REMATCH[2]}") + else + echo "$line" + fi + done < <(powershell -ExecutionPolicy Bypass -File "$win_check" 2>&1 || true) + elif command -v pwsh &>/dev/null && [ -f "$win_check" ]; then + while IFS= read -r line; do + if [[ "$line" =~ ^INSTALL_(REQUIRED|OPTIONAL):(.+)$ ]]; then + missing_win+=("${BASH_REMATCH[2]}") + else + echo "$line" + fi + done < <(pwsh -ExecutionPolicy Bypass -File "$win_check" 2>&1 || true) else echo "PowerShell not available. Skipping Windows dependency check." fi + echo "" echo "--- Android Dependencies ---" - ANDROID_SCRIPT="$SCRIPT_DIR/plugins/android-reverse-engineering/skills/android-reverse-engineering/scripts/check-deps.sh" - if [ -f "$ANDROID_SCRIPT" ]; then - bash "$ANDROID_SCRIPT" || true + local android_check="$SCRIPT_DIR/plugins/android-reverse-engineering/skills/android-reverse-engineering/scripts/check-deps.sh" + local android_install="$SCRIPT_DIR/plugins/android-reverse-engineering/skills/android-reverse-engineering/scripts/install-dep.sh" + if [ -f "$android_check" ]; then + while IFS= read -r line; do + # Filter out powershell warnings matching CRLF if needed, bash doesn't have it generally but check-deps might + line="${line%$'\r'}" + if [[ "$line" =~ ^INSTALL_(REQUIRED|OPTIONAL):(.+)$ ]]; then + missing_android+=("${BASH_REMATCH[2]}") + else + echo "$line" + fi + done < <(bash "$android_check" 2>&1 || true) else echo "Android check-deps.sh not found." fi + + local total_missing=$((${#missing_win[@]} + ${#missing_android[@]})) + if [ "$total_missing" -gt 0 ]; then + echo "" + read -rp "Detected $total_missing missing dependencies (optional/required). Would you like to install them now? (y/N) " ans + if [[ "$ans" =~ ^[Yy] ]]; then + echo "" + for dep in "${missing_win[@]}"; do + echo "--- Installing Windows dependency: $dep ---" + if command -v powershell &>/dev/null; then + powershell -ExecutionPolicy Bypass -File "$win_install" "$dep" + else + pwsh -ExecutionPolicy Bypass -File "$win_install" "$dep" + fi + done + for dep in "${missing_android[@]}"; do + echo "--- Installing Android dependency: $dep ---" + bash "$android_install" "$dep" + done + echo "" + echo "Done installing dependencies." + echo "Restart your terminal if any PATH variables were updated." + fi + fi +} + +if $CHECK_DEPS; then + invoke_dependency_check exit 0 fi