Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write ps1 script to download data #900

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ tasks:
setup-win:
platforms: [ windows ]
cmds:
- powershell -Command "Invoke-WebRequest 'https://drive.google.com/uc?export=download&id=1I-hwc0RHoQqW774gbS5qR-GHa1E7BlsS' -OutFile {{.DATA_DIR}}/sena-3.zip -Resume"
- powershell -Command "Invoke-WebRequest 'https://drive.usercontent.google.com/download?export=download&id=1Jk-eSDho8ATBMS-Kmfatwi-MWQth26ro&confirm=t' -OutFile {{.DATA_DIR}}/elawa.zip -Resume"
- powershell -File download.ps1 sena-3 'https://drive.google.com/uc?export=download&id=1I-hwc0RHoQqW774gbS5qR-GHa1E7BlsS' 'BEC5131799DB07BF8D84D8FC1F3169FB2574F2A1F4C37F6898EAB563A4AE95B8'
- powershell -File download.ps1 elawa 'https://drive.usercontent.google.com/download?export=download&id=1Jk-eSDho8ATBMS-Kmfatwi-MWQth26ro&confirm=t' "E3608F1E3188CE5FDB166FBF9D5AAD06558DB68EFA079FB453881572B50CB8E3"
setup-unix:
platforms: [ linux, darwin ]
cmds:
Expand Down
51 changes: 51 additions & 0 deletions download.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
param (
[Parameter(Mandatory=$true)]
[string]$FileName,

[Parameter(Mandatory=$true)]
[string]$Url,

[Parameter(Mandatory=$true)]
[string]$Checksum
)

$DataDir = "./data"
$FilePath = "$DataDir\$FileName.zip"

function Get-Checksum {
param (
[string]$FilePath
)
$hash = Get-FileHash -Path $FilePath -Algorithm SHA256
return $hash.Hash
}

function Get-File {
param (
[string]$FileName,
[string]$FileUrl,
[string]$ExpectedChecksum,
[string]$FilePath
)

Write-Host("Trying to download $FileName data...")

if (Test-Path -Path $FilePath) {
$checksum = Get-Checksum -FilePath $FilePath
if ($checksum -eq $ExpectedChecksum) {
# Checksum matches. No need to re-download.
Write-Output "$FileName already exists."
} else {
Write-Output "Checksum does not match. Re-downloading $FileName..."
Invoke-WebRequest -Uri $FileUrl -OutFile $FilePath
}
} else {
Write-Output "$FileName does not exist. Downloading..."
Invoke-WebRequest -Uri $FileUrl -OutFile $FilePath
}
}

Get-File -FileName $FileName `
-FileUrl $Url `
-ExpectedChecksum $Checksum `
-FilePath $FilePath