Skip to content

Commit

Permalink
Add --as-clj to install script
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Apr 14, 2023
1 parent 3780d2d commit 3f5a59e
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions install.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#Requires -Version 5

Param(
[switch]${as-clj} = $false
)

$erroractionpreference = 'stop' # quit if anything goes wrong

if (($PSVersionTable.PSVersion.Major) -lt 5) {
Expand Down Expand Up @@ -35,23 +39,35 @@ Write-Output "Downloading..."
(New-Object System.Net.WebClient).DownloadFile($download_url,"$tmp_zip_file")
Write-Output 'Extracting...'
Expand-Archive -LiteralPath "$tmp_zip_file" -DestinationPath "$tmp_dir" -Force

function Make-Dir($dir) {
if(!(test-path $dir)) {
mkdir $dir > $null };
}

$deps_clj_dir = "$env:USERPROFILE\deps.clj"
$tmp_exe_file = "$tmp_dir\deps.exe"
$installed_exe_file = "$deps_clj_dir\deps.exe"
$installed_exe_file_backup = "$deps_clj_dir\deps.exe.bak"

if (${as-clj}) {
Write-Output "Installing clojure.exe to $deps_clj_dir..."
$installed_exe_files = @("$deps_clj_dir\clj.exe","$deps_clj_dir\clojure.exe")
$installed_exe_files_backup = @("$deps_clj_dir\clj.exe.bak","$deps_clj_dir\clojure.exe.bak")
}
else {
Write-Output "Installing deps.exe to $deps_clj_dir..."
$installed_exe_files = @("$deps_clj_dir\deps.exe")
$installed_exe_files_backup = @("$deps_clj_dir\deps.exe.bak")
}

Make-Dir($deps_clj_dir)
Write-Output "Installing deps.exe to $deps_clj_dir..."
if (Test-Path -Path "$installed_exe_file") {
Move-Item -Path "$installed_exe_file" -Destination "$installed_exe_file_backup" -Force
for ($i = 0; $i -le ($installed_exe_files.length - 1); $i += 1) {
$installed_exe_file = $installed_exe_files[$i]
$installed_exe_file_backup = $installed_exe_files_backup[$i]
if (Test-Path -Path "$installed_exe_file") {
Move-Item -Path "$installed_exe_file" -Destination "$installed_exe_file_backup" -Force
}
Copy-Item -Path "$tmp_exe_file" -Destination "$installed_exe_file" -Force
}
Move-Item -Path "$tmp_exe_file" -Destination "$installed_exe_file" -Force
Remove-Item $tmp_exe_file

function env($name,$global,$val='__get') {
$target = 'User'; if($global) {$target = 'Machine'}
Expand Down

0 comments on commit 3f5a59e

Please sign in to comment.