| 1 | import type { Arch } from "./install-platform"; |
| 2 | |
| 3 | function windowsSnippet(arch: "x64" | "arm64"): string { |
| 4 | return `# PowerShell |
| 5 | $ErrorActionPreference = "Stop" |
| 6 | $dest = "$Env:USERPROFILE\\bin" |
| 7 | New-Item -ItemType Directory -Force $dest | Out-Null |
| 8 | $manifest = Invoke-WebRequest https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 9 | |
| 10 | Invoke-WebRequest \` |
| 11 | -Uri https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-windows-${arch}.exe \` |
| 12 | -OutFile "$dest\\codewhale.exe" |
| 13 | Invoke-WebRequest \` |
| 14 | -Uri https://github.com/Hmbown/CodeWhale/releases/latest/download/codew-windows-${arch}.exe \` |
| 15 | -OutFile "$dest\\codew.exe" |
| 16 | |
| 17 | $expected = @{} |
| 18 | $manifest.Content -split "\`n" | ForEach-Object { |
| 19 | $parts = $_.Trim() -split "\\s+" |
| 20 | if ($parts.Length -ge 2) { $expected[$parts[1]] = $parts[0].ToUpperInvariant() } |
| 21 | } |
| 22 | if ((Get-FileHash "$dest\\codewhale.exe" -Algorithm SHA256).Hash -ne $expected["codewhale-windows-${arch}.exe"]) { throw "codewhale.exe checksum mismatch" } |
| 23 | if ((Get-FileHash "$dest\\codew.exe" -Algorithm SHA256).Hash -ne $expected["codew-windows-${arch}.exe"]) { throw "codew.exe checksum mismatch" } |
| 24 | |
| 25 | $Env:Path = "$dest;$Env:Path"`; |
| 26 | } |
| 27 | |
| 28 | function windowsVerify(arch: "x64" | "arm64"): string { |
| 29 | return `# PowerShell |
| 30 | $manifest = Invoke-WebRequest https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 31 | $expected = @{} |
| 32 | $manifest.Content -split "\`n" | ForEach-Object { |
| 33 | $parts = $_.Trim() -split "\\s+" |
| 34 | if ($parts.Length -ge 2) { $expected[$parts[1]] = $parts[0].ToUpperInvariant() } |
| 35 | } |
| 36 | if ((Get-FileHash "$Env:USERPROFILE\\bin\\codewhale.exe" -Algorithm SHA256).Hash -ne $expected["codewhale-windows-${arch}.exe"]) { throw "codewhale.exe checksum mismatch" } |
| 37 | if ((Get-FileHash "$Env:USERPROFILE\\bin\\codew.exe" -Algorithm SHA256).Hash -ne $expected["codew-windows-${arch}.exe"]) { throw "codew.exe checksum mismatch" }`; |
| 38 | } |
| 39 | |
| 40 | export const SNIPPETS: Record<Arch, string> = { |
| 41 | "macos-arm64": `curl -fsSL -O https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 42 | curl -fsSL -O \\ |
| 43 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-macos-arm64 |
| 44 | curl -fsSL -O \\ |
| 45 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codew-macos-arm64 |
| 46 | grep -E ' (codewhale|codew)-macos-arm64$' codewhale-artifacts-sha256.txt | shasum -a 256 -c - |
| 47 | chmod +x codewhale-macos-arm64 codew-macos-arm64 |
| 48 | xattr -d com.apple.quarantine codewhale-macos-arm64 codew-macos-arm64 2>/dev/null || true |
| 49 | sudo mv codewhale-macos-arm64 /usr/local/bin/codewhale |
| 50 | sudo mv codew-macos-arm64 /usr/local/bin/codew`, |
| 51 | "macos-x64": `curl -fsSL -O https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 52 | curl -fsSL -O \\ |
| 53 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-macos-x64 |
| 54 | curl -fsSL -O \\ |
| 55 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codew-macos-x64 |
| 56 | grep -E ' (codewhale|codew)-macos-x64$' codewhale-artifacts-sha256.txt | shasum -a 256 -c - |
| 57 | chmod +x codewhale-macos-x64 codew-macos-x64 |
| 58 | xattr -d com.apple.quarantine codewhale-macos-x64 codew-macos-x64 2>/dev/null || true |
| 59 | sudo mv codewhale-macos-x64 /usr/local/bin/codewhale |
| 60 | sudo mv codew-macos-x64 /usr/local/bin/codew`, |
| 61 | "linux-x64": `curl -fsSL -O https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 62 | curl -fsSL -O \\ |
| 63 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-linux-x64 |
| 64 | curl -fsSL -O \\ |
| 65 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codew-linux-x64 |
| 66 | grep -E ' (codewhale|codew)-linux-x64$' codewhale-artifacts-sha256.txt | sha256sum -c - |
| 67 | chmod +x codewhale-linux-x64 codew-linux-x64 |
| 68 | sudo mv codewhale-linux-x64 /usr/local/bin/codewhale |
| 69 | sudo mv codew-linux-x64 /usr/local/bin/codew`, |
| 70 | "linux-arm64": `curl -fsSL -O https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 71 | curl -fsSL -O \\ |
| 72 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-linux-arm64 |
| 73 | curl -fsSL -O \\ |
| 74 | https://github.com/Hmbown/CodeWhale/releases/latest/download/codew-linux-arm64 |
| 75 | grep -E ' (codewhale|codew)-linux-arm64$' codewhale-artifacts-sha256.txt | sha256sum -c - |
| 76 | chmod +x codewhale-linux-arm64 codew-linux-arm64 |
| 77 | sudo mv codewhale-linux-arm64 /usr/local/bin/codewhale |
| 78 | sudo mv codew-linux-arm64 /usr/local/bin/codew`, |
| 79 | "windows-x64": windowsSnippet("x64"), |
| 80 | "windows-arm64": windowsSnippet("arm64"), |
| 81 | }; |
| 82 | |
| 83 | function unixVerify(platform: string, checksumCommand: string): string { |
| 84 | return `curl -fsSL -O https://github.com/Hmbown/CodeWhale/releases/latest/download/codewhale-artifacts-sha256.txt |
| 85 | verify_binary() { |
| 86 | asset="$1" |
| 87 | installed="$2" |
| 88 | expected=$(awk -v asset="$asset" '$2 == asset { print $1 }' codewhale-artifacts-sha256.txt) |
| 89 | actual=$(${checksumCommand} "$installed" | awk '{ print $1 }') |
| 90 | if [ -z "$expected" ] || [ "$actual" != "$expected" ]; then |
| 91 | echo "$installed checksum mismatch" >&2 |
| 92 | return 1 |
| 93 | fi |
| 94 | } |
| 95 | verify_binary codewhale-${platform} /usr/local/bin/codewhale |
| 96 | verify_binary codew-${platform} /usr/local/bin/codew`; |
| 97 | } |
| 98 | |
| 99 | export const VERIFY: Record<Arch, string> = { |
| 100 | "macos-arm64": unixVerify("macos-arm64", "shasum -a 256"), |
| 101 | "macos-x64": unixVerify("macos-x64", "shasum -a 256"), |
| 102 | "linux-x64": unixVerify("linux-x64", "sha256sum"), |
| 103 | "linux-arm64": unixVerify("linux-arm64", "sha256sum"), |
| 104 | "windows-x64": windowsVerify("x64"), |
| 105 | "windows-arm64": windowsVerify("arm64"), |
| 106 | }; |
| 107 |