Skip to content

Commit

Permalink
ps1 for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
fszlin committed Apr 4, 2017
1 parent b2b7aee commit bcdd336
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,5 @@ ModelManifest.xml

_test/
build/
.certes/
data.json
61 changes: 61 additions & 0 deletions scripts/certes.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Param(
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$passthrough
)

$cliArchiveName = "certes-cli.zip"
$binPath = "./.certes"
$certesBinPath = "$binPath/bin"
$dotnetBinPath = "$binPath/dotnet"
$certesVerPath = "$binPath/ver"
$cliPath = "$certesBinPath/Certes.Cli.dll"
$cliMinVersion = [Version]"1.0.1"
$updateCheckDays = -7

Function Init {
New-Item $binPath -Type Directory -Force | Out-Null
}

Function Get-Cli {
If (Test-Path $cliPath) {
$pubDate = [DateTime](Get-Content -Raw $certesVerPath -ErrorAction SilentlyContinue)
if (($pubDate) -And ($pubDate -gt (Get-Date).AddDays($updateCheckDays))) {
Return;
}
}

Init
Remove-Item $certesBinPath -Force -Recurse -ErrorAction SilentlyContinue | Out-Null

$releaseInfo = Invoke-WebRequest https://api.github.com/repos/fszlin/certes/releases/latest | ConvertFrom-Json

$cliInfo = $releaseInfo.assets | `
Where-Object { $_.name -eq $cliArchiveName } | `
Select -ExpandProperty browser_download_url
Invoke-WebRequest $cliInfo -OutFile "$binPath/$cliArchiveName"
Expand-Archive "$binPath/$cliArchiveName" -DestinationPath $certesBinPath -Force

New-Item $certesVerPath -Type File -Value (Get-Date -Format s) -Force | Out-Null
}

Function Get-Dotnet {
$dotnetCmd = Get-Command "$dotnetBinPath/dotnet.exe" -ErrorAction SilentlyContinue

If (!$dotnetCmd) {
$dotnetCmd = Get-Command "dotnet" -ErrorAction SilentlyContinue
}

if ((!$dotnetCmd) -Or ($dotnetCmd.Version -le $cliMinVersion)) {
Init
Invoke-WebRequest https://dot.net/v1/dotnet-install.ps1 -OutFile "$binPath/dotnet-install.ps1"
& $binPath/dotnet-install.ps1 -InstallDir $dotnetBinPath -NoPath
$dotnetCmd = Get-Command "$dotnetBinPath/dotnet.exe" -ErrorAction SilentlyContinue
}

Return $dotnetCmd.Source
}

Get-Cli
$dotnetExe = Get-Dotnet

& $dotnetExe $cliPath $passthrough

0 comments on commit bcdd336

Please sign in to comment.