Dumb question; how to install on Windows from the binary release? #4804
-
I have the I realize this is a multi-call binary so running Right now I am running
I haven't found an elegant way to parse the currently defined functions so I copy the output of the $utils = "arch", "b2sum", "b3sum", "base32", "base64", "basename", "basenc", "cat", "cksum", "comm", "cp",
"csplit", "cut", "date", "dd", "df", "dir", "dircolors", "dirname", "du", "echo", "env", "expand", "expr",
"factor", "false", "fmt", "fold", "hashsum", "head", "hostname", "join", "link", "ln", "ls", "md5sum", "mkdir",
"mktemp", "more", "mv", "nl", "nproc", "numfmt", "od", "paste", "pr", "printenv", "printf", "ptx", "pwd",
"readlink", "realpath", "relpath", "rm", "rmdir", "seq", "sha1sum", "sha224sum", "sha256sum", "sha3-224sum",
"sha3-256sum", "sha3-384sum", "sha3-", "512sum", "sha384sum", "sha3sum", "sha512sum", "shake128sum", "shake256sum",
"shred", "shuf", "sleep", "sort", "split", "sum", "sync", "tac", "tail", "tee", "test", "touch", "tr", "true",
"truncate", "tsort", "uname", "unexpand", "uniq", "unlink", "vdir", "wc", "whoami", "yes"
Foreach ($util in $utils) {
$util_path = (-join(".\", $util, ".exe"))
New-Item -ItemType SymbolicLink -Path $util_path -Target ".\coreutils.exe"
} Which gives me the utils as symlinks in a directory that I add to my $PATH variable But I can't help but feel this isn't how we should be installing the utils. How do you do it? How are you supposed to do it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
The symlinks and adding the directory sounds about right actually if you do it manually. Generally, we recommend using a package manager though. On Windows, you can use |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks for this question / anwer @alshdavid and @tertsdiepraam -- that was exactly what I was trying to do. For anyone as lazy as me thinking "I don't want to go over the list of utils, just get all of them", the below script will create links to all of them without explicitly listing which ones you want. In my machine it requires opening Powershell as admin (not completely sure why). # based on this question: https://github.com/uutils/coreutils/discussions/4804
[CmdletBinding()]
param()
$utilsList = @(coreutils.exe --list)
Foreach ($util in $utilsList) {
$util_path = ( -join (".\", $util, ".exe"))
Write-Verbose -Message "Creating link to $util as $util_path"
New-Item -ItemType SymbolicLink -Path $util_path -Target ".\coreutils.exe"
} |
Beta Was this translation helpful? Give feedback.
-
@pedroangelini I have updated the script with an auto-download and install script. The script can be used to download and update coreutils.
[CmdletBinding()]
param (
$path,
[switch] $force
)
$dir_target = $path
if ("$dir_target" -eq "") {
$dir_target = "$env:USERPROFILE\local\uutils"
}
Write-Host "TARTGET DIR: $dir_target"
Write-Host "OS: $([System.Runtime.InteropServices.RuntimeInformation]::OSDescription)"
$platform = switch -Wildcard ([System.Runtime.InteropServices.RuntimeInformation]::OSDescription) {
"*Windows*" { "pc-windows-msvc.zip" }
"*Linux*" { "unknown-linux-musl.tar.gz" }
"*Darwin*" { "apple-darwin.tar.gz" }
Default { exit 1 }
}
Write-Host "CPU: $([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)"
$arch = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
"X64" { "x86_64" }
"X86" { "i686" }
"Arm" { "arm" }
"Arm64" { "aarch64" }
Default {
Write-Host "Unknown CPU architecture"
exit 1
}
}
$url_api = "https://api.github.com/repos/uutils/coreutils/releases/latest"
Write-Host "URL GitHub: $url_api"
$response = Invoke-WebRequest -Uri "$url_api" -UseBasicParsing
$releases = $response | ConvertFrom-Json
$url_target = ""
$name_target = ""
foreach ($asset in $releases.assets) {
if ($asset.browser_download_url.Contains("$arch-$platform")) {
$url_target = $asset.browser_download_url
$name_target = $asset.name
}
}
Write-Host "URL Archive: $url_target"
if ($force) {
Write-Host "ACTION: Deleting & recreating `"$dir_target`""
} else {
Write-Host -ForegroundColor red -NoNewLine "PROMPT: Delete & recreate `"$dir_target`" [y/n]"
$confirmation = Read-Host
if ($confirmation -ne 'y') {
exit 0
}
}
if ( Test-Path "$dir_target" ) {
Remove-Item -Force -Recurse $dir_target | Out-Null
}
New-Item -ItemType Directory -Force -Path $dir_target | Out-Null
$path_temp = "$dir_target\.temp"
$path_archive = "$path_temp\$name_target"
$name_stripped = "$([io.path]::GetFileNameWithoutExtension("$name_target"))"
if ( Test-Path "$path_temp" ) {
Remove-Item -Recurse -Force "$path_temp" | Out-Null
}
New-Item -ItemType Directory -Force -Path $path_temp | Out-Null
Write-Host "ACTION: Downloading archive"
Invoke-WebRequest $url_target -OutFile "$path_archive"
Write-Host "ACTION: Expanding archive"
switch -wildcard ($url_target){
"*.zip" {
Expand-Archive "$path_archive" -DestinationPath "$path_temp" | Out-Null
Get-ChildItem -Path "$path_temp\$name_stripped" -Recurse | Move-Item -Destination "$dir_target"
}
"*.tar.gz" {
echo "tar.gz"
}
"*.tar.xz" {
echo "tar.xz"
}
Default {
Write-Host "Unknown archive kind: $url_target"
exit 1
}
}
$bin_dir = "$dir_target\bin"
if ( Test-Path "$bin_dir" ) {
Remove-Item -Recurse -Force "$bin_dir" | Out-Null
}
New-Item -ItemType "directory" "$bin_dir" | Out-Null
New-Item -ItemType SymbolicLink -Path "$bin_dir\coreutils.exe" -Target "$dir_target\coreutils.exe" | Out-Null
$existing_aliases = ""
function Check-Command($cmdname)
{
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
Foreach ($util in @(. "$bin_dir\coreutils.exe" --list)) {
$target_path = "$bin_dir\$util.exe"
$coreutils = "$dir_target\coreutils.exe"
Write-Host -Message "LINK: $coreutils -> $target_path"
New-Item -ItemType SymbolicLink -Path "$target_path" -Target "$coreutils" | Out-Null
if ("$util" -eq "[") {
continue
}
if (Check-Command $util)
{
if ("$((Get-Command "$util").CommandType)" -eq "Alias") {
$existing_aliases += "Remove-Item Alias:`"$util`" `r`n"
}
}
}
if ( Test-Path "$path_temp" ) {
Remove-Item -Recurse -Force "$path_temp" | Out-Null
}
Write-Host ""
Write-Host "Add this to `$profile:"
Write-Host ""
Write-Host "Remove-Item Alias:`"cat`""
Write-Host "Remove-Item Alias:`"cp`""
Write-Host "Remove-Item Alias:`"dir`""
Write-Host "Remove-Item Alias:`"echo`""
Write-Host "Remove-Item Alias:`"ls`""
Write-Host "Remove-Item Alias:`"mv`""
Write-Host "Remove-Item Alias:`"pwd`""
Write-Host "Remove-Item Alias:`"rm`""
Write-Host "Remove-Item Alias:`"rmdir`""
Write-Host ""
Write-Host "Add this directory to your `$PATH:"
Write-Host ""
Write-Host "$dir_target\bin" |
Beta Was this translation helpful? Give feedback.
The symlinks and adding the directory sounds about right actually if you do it manually. Generally, we recommend using a package manager though. On Windows, you can use
scoop
for example, which should do all of that for you. At some point we had contributors working on packaging uutils for the Windows store as well, but I think that work has stalled for now.