Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
124 lines (107 loc) · 4.23 KB
/
Copy pathinstall.ps1
File metadata and controls
124 lines (107 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
$ErrorActionPreference = "Stop"
$Repo = "tomtev/touchgrass"
$DefaultInstallDir = Join-Path $HOME ".touchgrass\bin"
$InstallDir = if ($env:TG_INSTALL_DIR) { $env:TG_INSTALL_DIR } else { $DefaultInstallDir }
$BinaryName = "touchgrass.exe"
function Write-Info([string]$Message) {
Write-Host " $Message" -ForegroundColor DarkGray
}
function Write-Success([string]$Message) {
Write-Host " $Message" -ForegroundColor Green
}
function Fail([string]$Message) {
throw $Message
}
Write-Host ""
Write-Host " touchgrass.sh" -ForegroundColor White
Write-Host " Manage Claude Code, Codex, and more from your phone." -ForegroundColor DarkGray
Write-Host ""
$arch = $null
try {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture.ToString().ToLowerInvariant()
} catch {}
if (-not $arch) {
# Fallback for Windows PowerShell 5.1 (.NET Framework)
$arch = $env:PROCESSOR_ARCHITECTURE
if ($arch -eq "AMD64") { $arch = "x64" }
elseif ($arch -eq "ARM64") { $arch = "arm64" }
else { $arch = $arch.ToLowerInvariant() }
}
if ($arch -ne "x64") {
Fail "Unsupported Windows architecture: $arch (supported: x64)"
}
$target = "windows-x64.exe"
Write-Info "Platform: $target"
Write-Info "Fetching latest release..."
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -Headers @{ "User-Agent" = "touchgrass-installer" }
$latest = $release.tag_name
if (-not $latest) {
Fail "Could not determine latest release. Check https://github.com/$Repo/releases"
}
Write-Info "Version: $latest"
$downloadUrl = "https://github.com/$Repo/releases/download/$latest/touchgrass-$target"
$tmpFile = Join-Path ([System.IO.Path]::GetTempPath()) ("tg-install-" + [guid]::NewGuid().ToString() + ".exe")
try {
Write-Info "Downloading..."
Invoke-WebRequest -Uri $downloadUrl -OutFile $tmpFile -UseBasicParsing
if (-not (Test-Path $tmpFile) -or ((Get-Item $tmpFile).Length -eq 0)) {
Fail "Failed to download binary for $target."
}
$existingInstall = (Test-Path (Join-Path $InstallDir $BinaryName)) -or (Get-Command touchgrass -ErrorAction SilentlyContinue) -or (Get-Command tg -ErrorAction SilentlyContinue)
New-Item -Path $InstallDir -ItemType Directory -Force | Out-Null
Move-Item -Path $tmpFile -Destination (Join-Path $InstallDir $BinaryName) -Force
# Create tg.exe alias for backwards compatibility
Copy-Item -Path (Join-Path $InstallDir $BinaryName) -Destination (Join-Path $InstallDir "tg.exe") -Force
# Try restarting daemon if a pid file exists (best effort).
$daemonPidFile = Join-Path $HOME ".touchgrass\daemon.pid"
if (Test-Path $daemonPidFile) {
try {
$pidRaw = (Get-Content $daemonPidFile -ErrorAction Stop | Select-Object -First 1).Trim()
if ($pidRaw) {
$pid = [int]$pidRaw
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
}
Remove-Item $daemonPidFile -Force -ErrorAction SilentlyContinue
Start-Process -FilePath (Join-Path $InstallDir $BinaryName) -ArgumentList "ls" -WindowStyle Hidden | Out-Null
Write-Info "Daemon restarted"
} catch {
# Ignore daemon restart failures
}
}
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$pathParts = @()
if ($userPath) {
$pathParts = $userPath -split ";"
}
$installDirInPath = $false
foreach ($part in $pathParts) {
if ($part.Trim().ToLowerInvariant() -eq $InstallDir.Trim().ToLowerInvariant()) {
$installDirInPath = $true
break
}
}
if (-not $installDirInPath) {
$newPath = if ($userPath -and $userPath.Trim()) { "$InstallDir;$userPath" } else { $InstallDir }
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
$env:Path = "$InstallDir;$env:Path"
}
Write-Host ""
if ($existingInstall) {
Write-Success "Updated touchgrass.sh to $latest"
} else {
Write-Success "Installed touchgrass to $(Join-Path $InstallDir $BinaryName)"
if (-not $installDirInPath) {
Write-Host ""
Write-Info "PATH updated for your user account."
Write-Info "Open a new terminal to pick up changes."
}
Write-Host ""
Write-Success "Run 'touchgrass init' to get started. (tg also works as alias)"
}
Write-Host ""
}
finally {
if (Test-Path $tmpFile) {
Remove-Item $tmpFile -Force -ErrorAction SilentlyContinue
}
}