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