diff --git a/update-fcp-mod-manager.bat b/update-fcp-mod-manager.bat index 772a8ea..dca3880 100644 --- a/update-fcp-mod-manager.bat +++ b/update-fcp-mod-manager.bat @@ -13,6 +13,7 @@ if /I not "%~1"=="--from-temp" ( set "APP_NAME=FCPModUpdater.exe" set "ARCHIVE=FCPModUpdater-win-x64-selfcontained.zip" set "BASE_URL=https://github.com/FalloutCollaborationProject/FCP-Mod-Updater/releases/latest/download" +set "RELEASES_API=https://api.github.com/repos/FalloutCollaborationProject/FCP-Mod-Updater/releases?per_page=50" set "STAGING=%TEMP%\FCPModUpdater-update-%RANDOM%%RANDOM%" if not exist ".\%APP_NAME%" ( @@ -32,8 +33,24 @@ if not exist "%STAGING%" ( exit /b 1 ) -echo Downloading latest FCP Mod Manager release... -powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '%BASE_URL%/%ARCHIVE%' -OutFile '%STAGING%\%ARCHIVE%'; Invoke-WebRequest -Uri '%BASE_URL%/checksums.txt' -OutFile '%STAGING%\checksums.txt'" +echo Select update channel: +echo 1^) Latest stable release +echo 2^) Latest pre-release +set /P "CHANNEL_CHOICE=Choice [1]: " +if "%CHANNEL_CHOICE%"=="" set "CHANNEL_CHOICE=1" + +if "%CHANNEL_CHOICE%"=="1" ( + echo Downloading latest stable FCP Mod Manager release... + powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '%BASE_URL%/%ARCHIVE%' -OutFile '%STAGING%\%ARCHIVE%'; Invoke-WebRequest -Uri '%BASE_URL%/checksums.txt' -OutFile '%STAGING%\checksums.txt'" +) else if "%CHANNEL_CHOICE%"=="2" ( + echo Finding latest FCP Mod Manager pre-release... + powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; $headers = @{ 'User-Agent' = 'FCPModUpdater' }; $releases = Invoke-RestMethod -Headers $headers -Uri '%RELEASES_API%'; $release = $releases | Where-Object { $_.prerelease -and -not $_.draft } | Select-Object -First 1; if ($null -eq $release) { throw 'No pre-release was found.' }; $archive = $release.assets | Where-Object { $_.name -eq '%ARCHIVE%' } | Select-Object -First 1; $checksums = $release.assets | Where-Object { $_.name -eq 'checksums.txt' } | Select-Object -First 1; if ($null -eq $archive) { throw ('No asset named %ARCHIVE% was found on ' + $release.tag_name + '.') }; if ($null -eq $checksums) { throw ('No checksums.txt asset was found on ' + $release.tag_name + '.') }; Invoke-WebRequest -Headers $headers -Uri $archive.browser_download_url -OutFile '%STAGING%\%ARCHIVE%'; Invoke-WebRequest -Headers $headers -Uri $checksums.browser_download_url -OutFile '%STAGING%\checksums.txt'" +) else ( + echo Invalid selection. + rmdir /S /Q "%STAGING%" >nul 2>nul + exit /b 1 +) + if not "%ERRORLEVEL%"=="0" ( echo Download failed. rmdir /S /Q "%STAGING%" >nul 2>nul diff --git a/update-fcp-mod-manager.sh b/update-fcp-mod-manager.sh index 446d960..fad0a25 100755 --- a/update-fcp-mod-manager.sh +++ b/update-fcp-mod-manager.sh @@ -4,6 +4,7 @@ set -euo pipefail APP_NAME="FCPModUpdater" ARCHIVE="FCPModUpdater-linux-x64-selfcontained.tar.gz" BASE_URL="https://github.com/FalloutCollaborationProject/FCP-Mod-Updater/releases/latest/download" +RELEASES_API="https://api.github.com/repos/FalloutCollaborationProject/FCP-Mod-Updater/releases?per_page=50" if [[ "${1:-}" != "--from-temp" ]]; then temp_script="$(mktemp)" @@ -44,9 +45,67 @@ cleanup() { } trap cleanup EXIT -echo "Downloading latest FCP Mod Manager release..." -curl -fsSL "${BASE_URL}/${ARCHIVE}" -o "${staging}/${ARCHIVE}" -curl -fsSL "${BASE_URL}/checksums.txt" -o "${staging}/checksums.txt" +echo "Select update channel:" +echo " 1) Latest stable release" +echo " 2) Latest pre-release" +read -r -p "Choice [1]: " channel_choice + +case "${channel_choice:-1}" in + 1) + echo "Downloading latest stable FCP Mod Manager release..." + curl -fsSL "${BASE_URL}/${ARCHIVE}" -o "${staging}/${ARCHIVE}" + curl -fsSL "${BASE_URL}/checksums.txt" -o "${staging}/checksums.txt" + ;; + 2) + if ! command -v python3 >/dev/null 2>&1; then + echo "Missing required tool for pre-release selection: python3" + exit 1 + fi + + echo "Finding latest FCP Mod Manager pre-release..." + curl -fsSL "${RELEASES_API}" -o "${staging}/releases.json" + mapfile -t asset_urls < <(python3 - "${ARCHIVE}" "${staging}/releases.json" <<'PY' +import json +import sys + +archive_name = sys.argv[1] +releases_path = sys.argv[2] + +with open(releases_path, "r", encoding="utf-8") as handle: + releases = json.load(handle) + +release = next((item for item in releases if item.get("prerelease") and not item.get("draft")), None) +if release is None: + sys.exit("No pre-release was found.") + +assets = release.get("assets", []) +archive = next((asset for asset in assets if asset.get("name") == archive_name), None) +checksums = next((asset for asset in assets if asset.get("name") == "checksums.txt"), None) + +if archive is None: + sys.exit(f"No asset named {archive_name} was found on {release.get('tag_name', 'the pre-release')}.") +if checksums is None: + sys.exit(f"No checksums.txt asset was found on {release.get('tag_name', 'the pre-release')}.") + +print(archive["browser_download_url"]) +print(checksums["browser_download_url"]) +PY +) + + if [[ "${#asset_urls[@]}" -ne 2 ]]; then + echo "Could not resolve pre-release download URLs." + exit 1 + fi + + echo "Downloading latest pre-release FCP Mod Manager release..." + curl -fsSL "${asset_urls[0]}" -o "${staging}/${ARCHIVE}" + curl -fsSL "${asset_urls[1]}" -o "${staging}/checksums.txt" + ;; + *) + echo "Invalid selection." + exit 1 + ;; +esac cd "${staging}" if ! grep " ${ARCHIVE}$" checksums.txt | sha256sum -c -; then