@echo off
setlocal

REM Copyright (C) 2026 Yota Hamada
REM SPDX-License-Identifier: GPL-3.0-or-later

set "PS1_URL=https://raw.githubusercontent.com/dagucloud/dagu/main/scripts/installer.ps1"
set "TEMP_PS1=%TEMP%\dagu-installer-%RANDOM%.ps1"

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$ProgressPreference='SilentlyContinue'; Invoke-WebRequest -UseBasicParsing -Uri '%PS1_URL%' -OutFile '%TEMP_PS1%';"
if errorlevel 1 (
  echo Failed to download the PowerShell installer. >&2
  exit /b 1
)

powershell -NoProfile -ExecutionPolicy Bypass -File "%TEMP_PS1%" %*
set "EXIT_CODE=%ERRORLEVEL%"

del /q "%TEMP_PS1%" >nul 2>&1
exit /b %EXIT_CODE%
