#!/usr/bin/env pwsh $ErrorActionPreference = "Stop" $Version="1.9.0.302" $ClojureTools="clojure-tools-$Version" $ClojureToolsUrl="https://download.clojure.org/install/$ClojureTools.zip" if (!(Test-Path "clojure-tools")) { echo "Downloading and expanding tar" Invoke-WebRequest -Uri $ClojureToolsUrl -OutFile "$ClojureTools.zip" Expand-Archive "$ClojureTools.zip" -DestinationPath . } if ($PSVersionTable.Platform -eq "Unix") { echo "Platform is unix" $DestinationPath="/usr/local" } else { $DestinationPath="$env:APPDATA\Clojure" } echo "Installing libs into $DestinationPath" New-Item -Force -Type Directory "$DestinationPath/lib/clojure" | Out-Null @("clojure-tools/deps.edn", "clojure-tools/example-deps.edn") | Copy-Item -Destination $DestinationPath/lib/clojure New-Item -Force -Type Directory "$DestinationPath/lib/clojure/libexec" | Out-Null Copy-Item "clojure-tools/$ClojureTools.jar" "$DestinationPath/lib/clojure/libexec" echo "Installing clojure and clj into $DestinationPath" if ($PSVersionTable.Platform -eq "Unix") { Get-Content "clojure-tools/clojure.ps1" | %{$_ -replace "__PREFIX__", "$DestinationPath" -replace "__VERSION__", "$Version"} > "$DestinationPath/bin/clojure" Copy-Item "clojure-tools/clj.ps1" "$DestinationPath/bin/clj" chmod 755 "$DestinationPath/bin/clojure" chmod 755 "$DestinationPath/bin/clj" } else { New-Item -Force -Type Directory "$DestinationPath\bin" | Out-Null Get-Content "clojure-tools/clojure.ps1" | %{$_ -replace "__PREFIX__", "$DestinationPath" -replace "__VERSION__", "$Version"} > "$DestinationPath/bin/clojure.ps1" Copy-Item "clojure-tools/clj.ps1" "$DestinationPath\bin\clj.ps1" $userPath=[Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) if (!($userPath -contains $DestinationPath)) { $env:PATH += ";$DestinationPath\bin" [Environment]::SetEnvironmentVariable("Path", "$userPath;$DestinationPath\bin", [System.EnvironmentVariableTarget]::User) } } echo "Removing download" Remove-Item -Recurse clojure-tools Remove-Item "$ClojureTools.zip" echo "Use clj -h for help."