Fix bootstrap download script
This commit is contained in:
120
contrib/bootstrap/bootstrap-dragonx.bat
Normal file
120
contrib/bootstrap/bootstrap-dragonx.bat
Normal file
@@ -0,0 +1,120 @@
|
||||
@echo off
|
||||
REM Copyright 2024 The Hush Developers
|
||||
REM Copyright 2024 The DragonX Developers
|
||||
REM Released under the GPLv3
|
||||
REM
|
||||
REM Download and apply a DRAGONX blockchain bootstrap.
|
||||
REM Safely preserves wallet.dat and configuration files.
|
||||
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
set "BOOTSTRAP_BASE_URL=https://bootstrap.dragonx.is"
|
||||
set "BOOTSTRAP_FILE=DRAGONX.zip"
|
||||
set "CHAIN_NAME=DRAGONX"
|
||||
set "DATADIR=%APPDATA%\Hush\%CHAIN_NAME%"
|
||||
set "CLI=dragonx-cli.bat"
|
||||
|
||||
echo ============================================
|
||||
echo DragonX Bootstrap Installer (Windows)
|
||||
echo ============================================
|
||||
echo.
|
||||
echo [INFO] Data directory: %DATADIR%
|
||||
echo.
|
||||
|
||||
REM Step 1: Stop daemon if running
|
||||
echo [INFO] Checking if DragonX daemon is running...
|
||||
%CLI% getinfo >nul 2>&1
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo [INFO] Stopping DragonX daemon...
|
||||
%CLI% stop >nul 2>&1
|
||||
echo [INFO] Waiting for daemon to stop...
|
||||
set /a tries=0
|
||||
:wait_loop
|
||||
timeout /t 2 /nobreak >nul
|
||||
%CLI% getinfo >nul 2>&1
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
set /a tries+=1
|
||||
if !tries! LSS 60 goto wait_loop
|
||||
echo [ERROR] Daemon did not stop after 120 seconds.
|
||||
echo [ERROR] Please stop it manually and retry.
|
||||
goto :eof
|
||||
)
|
||||
echo [INFO] Daemon stopped.
|
||||
) else (
|
||||
echo [INFO] Daemon is not running.
|
||||
)
|
||||
|
||||
REM Step 2: Clean blockchain data (preserve wallet.dat and config)
|
||||
echo [INFO] Cleaning blockchain data...
|
||||
if exist "%DATADIR%\blocks" rmdir /s /q "%DATADIR%\blocks"
|
||||
if exist "%DATADIR%\chainstate" rmdir /s /q "%DATADIR%\chainstate"
|
||||
if exist "%DATADIR%\notarizations" rmdir /s /q "%DATADIR%\notarizations"
|
||||
if exist "%DATADIR%\komodo" rmdir /s /q "%DATADIR%\komodo"
|
||||
if exist "%DATADIR%\db.log" del /f /q "%DATADIR%\db.log"
|
||||
if exist "%DATADIR%\debug.log" del /f /q "%DATADIR%\debug.log"
|
||||
if exist "%DATADIR%\fee_estimates.dat" del /f /q "%DATADIR%\fee_estimates.dat"
|
||||
if exist "%DATADIR%\banlist.dat" del /f /q "%DATADIR%\banlist.dat"
|
||||
echo [INFO] Blockchain data cleaned.
|
||||
|
||||
REM Step 3: Download bootstrap and checksums
|
||||
if not exist "%DATADIR%" mkdir "%DATADIR%"
|
||||
set "ARCHIVE=%DATADIR%\%BOOTSTRAP_FILE%"
|
||||
set "MD5FILE=%DATADIR%\%BOOTSTRAP_FILE%.md5"
|
||||
set "SHA256FILE=%DATADIR%\%BOOTSTRAP_FILE%.sha256"
|
||||
|
||||
echo [INFO] Downloading bootstrap from %BOOTSTRAP_BASE_URL% ...
|
||||
echo [INFO] This may take a while depending on your connection speed.
|
||||
|
||||
REM Download bootstrap zip
|
||||
powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $ProgressPreference = 'Continue'; Invoke-WebRequest -Uri '%BOOTSTRAP_BASE_URL%/%BOOTSTRAP_FILE%' -OutFile '%ARCHIVE%' }"
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo [ERROR] Download failed. Please check your internet connection.
|
||||
goto :eof
|
||||
)
|
||||
echo [INFO] Bootstrap download complete.
|
||||
|
||||
REM Download checksums
|
||||
echo [INFO] Downloading checksums...
|
||||
powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%BOOTSTRAP_BASE_URL%/%BOOTSTRAP_FILE%.md5' -OutFile '%MD5FILE%' }"
|
||||
powershell -Command "& { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%BOOTSTRAP_BASE_URL%/%BOOTSTRAP_FILE%.sha256' -OutFile '%SHA256FILE%' }"
|
||||
|
||||
REM Verify checksums
|
||||
echo [INFO] Verifying checksums...
|
||||
powershell -Command "& { $expected = (Get-Content '%MD5FILE%').Split(' ')[0]; $actual = (Get-FileHash '%ARCHIVE%' -Algorithm MD5).Hash.ToLower(); if ($actual -ne $expected) { Write-Host '[ERROR] MD5 checksum verification failed!'; exit 1 } else { Write-Host '[INFO] MD5 checksum verified.' } }"
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo [ERROR] The download may be corrupted. Please try again.
|
||||
goto :done
|
||||
)
|
||||
powershell -Command "& { $expected = (Get-Content '%SHA256FILE%').Split(' ')[0]; $actual = (Get-FileHash '%ARCHIVE%' -Algorithm SHA256).Hash.ToLower(); if ($actual -ne $expected) { Write-Host '[ERROR] SHA256 checksum verification failed!'; exit 1 } else { Write-Host '[INFO] SHA256 checksum verified.' } }"
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo [ERROR] The download may be corrupted. Please try again.
|
||||
goto :done
|
||||
)
|
||||
|
||||
REM Clean up checksum files
|
||||
del /f /q "%MD5FILE%" 2>nul
|
||||
del /f /q "%SHA256FILE%" 2>nul
|
||||
|
||||
REM Step 4: Extract bootstrap
|
||||
echo [INFO] Extracting bootstrap...
|
||||
cd /d "%DATADIR%"
|
||||
|
||||
REM Use PowerShell to extract zip, excluding wallet.dat
|
||||
powershell -Command "& { Add-Type -AssemblyName System.IO.Compression; $zip = [System.IO.Compression.ZipFile]::OpenRead('%ARCHIVE%'); foreach ($entry in $zip.Entries) { if ($entry.Name -eq 'wallet.dat' -or $entry.Name -like '*.conf') { continue }; $destPath = Join-Path '%DATADIR%' $entry.FullName; $destDir = Split-Path $destPath -Parent; if (!(Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null }; if ($entry.Name) { [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $destPath, $true) } }; $zip.Dispose() }"
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo [ERROR] Extraction failed.
|
||||
echo [ERROR] Archive location: %ARCHIVE%
|
||||
goto :done
|
||||
)
|
||||
echo [INFO] Bootstrap extracted successfully.
|
||||
|
||||
REM Remove archive
|
||||
del /f /q "%ARCHIVE%" 2>nul
|
||||
echo [INFO] Removed downloaded archive.
|
||||
|
||||
echo.
|
||||
:done
|
||||
echo [INFO] Bootstrap installation complete!
|
||||
echo [INFO] You can now start DragonX with: dragonxd.bat
|
||||
echo.
|
||||
pause
|
||||
Reference in New Issue
Block a user