| 1 | import { InstallCodeBlock } from "@/components/install-code-block"; |
| 2 | import { aptKeyFileName, type DesktopArch, type DesktopDownload, type LinuxDownloads } from "@/lib/desktop-release"; |
| 3 | import { fill, getChrome, getHome } from "@/lib/i18n/dictionaries"; |
| 4 | |
| 5 | const ARCH_NAME: Record<DesktopArch, string> = { arm64: "Apple silicon", x64: "Intel" }; |
| 6 | |
| 7 | export function DesktopDownloadBlock({ downloads, locale }: { downloads: DesktopDownload[]; locale: string }) { |
| 8 | const chrome = getChrome(locale); |
| 9 | const megabytes = new Intl.NumberFormat(chrome.dateLocale, { maximumFractionDigits: 1 }); |
| 10 | const named = downloads.length > 1; |
| 11 | return ( |
| 12 | <> |
| 13 | {downloads.map((download) => { |
| 14 | const size = `${megabytes.format(download.size / 1_000_000)} MB`; |
| 15 | const arch = named && download.arch ? ARCH_NAME[download.arch] : null; |
| 16 | return ( |
| 17 | <div className="desktop-download" key={download.url}> |
| 18 | <p> |
| 19 | <a href={download.url} className="btn btn-primary" rel="noopener"> |
| 20 | {chrome.downloadMacos} |
| 21 | {arch ? ` · ${arch}` : null} |
| 22 | </a> |
| 23 | </p> |
| 24 | <p> |
| 25 | {fill(chrome.downloadVersion, { version: download.version })} · {fill(chrome.downloadSize, { size })} · {chrome.downloadSigned} |
| 26 | </p> |
| 27 | <p> |
| 28 | {chrome.downloadChecksum}: <code>{download.sha256}</code> |
| 29 | </p> |
| 30 | </div> |
| 31 | ); |
| 32 | })} |
| 33 | </> |
| 34 | ); |
| 35 | } |
| 36 | |
| 37 | const KEYRING_DIR = "/etc/apt/keyrings"; |
| 38 | |
| 39 | export function aptInstallLines(apt: NonNullable<LinuxDownloads["apt"]>): string { |
| 40 | const keyFile = aptKeyFileName(apt.keyUrl); |
| 41 | if (!keyFile) throw new Error("apt key URL has no safe file name"); |
| 42 | const keyPath = `${KEYRING_DIR}/${keyFile}`; |
| 43 | return [ |
| 44 | `sudo install -d -m 0755 ${KEYRING_DIR}`, |
| 45 | `curl -fsSL ${apt.keyUrl} | sudo tee ${keyPath} >/dev/null`, |
| 46 | `echo "deb [arch=${apt.architecture} signed-by=${keyPath}] ${apt.repository} ${apt.suite} ${apt.component}" | sudo tee /etc/apt/sources.list.d/codewhale.list >/dev/null`, |
| 47 | `sudo apt update && sudo apt install ${apt.package}`, |
| 48 | ].join("\n"); |
| 49 | } |
| 50 | |
| 51 | export function groupFingerprint(fingerprint: string): string { |
| 52 | return fingerprint.match(/.{1,4}/g)?.join(" ") ?? fingerprint; |
| 53 | } |
| 54 | |
| 55 | export function LinuxDownloadBlock({ linux, locale }: { linux: LinuxDownloads; locale: string }) { |
| 56 | const chrome = getChrome(locale); |
| 57 | const home = getHome(locale); |
| 58 | const megabytes = new Intl.NumberFormat(chrome.dateLocale, { maximumFractionDigits: 1 }); |
| 59 | const { apt, appImage } = linux; |
| 60 | return ( |
| 61 | <div className="desktop-download desktop-download-linux"> |
| 62 | <h3>{chrome.downloadLinux} · x64</h3> |
| 63 | {apt ? ( |
| 64 | <> |
| 65 | <p>{chrome.downloadAptTitle}</p> |
| 66 | <InstallCodeBlock cmd={aptInstallLines(apt)} copyLabel={home.copy} copiedLabel={home.copied} copyLocale={locale} /> |
| 67 | <p>{chrome.downloadAptTrust}</p> |
| 68 | <p> |
| 69 | {chrome.downloadAptFingerprint.split("{fingerprint}").flatMap((part, index) => |
| 70 | index === 0 ? [part] : [<code key="fingerprint">{groupFingerprint(apt.keyFingerprint)}</code>, part], |
| 71 | )} |
| 72 | </p> |
| 73 | </> |
| 74 | ) : null} |
| 75 | {appImage ? ( |
| 76 | <> |
| 77 | <p> |
| 78 | <a href={appImage.url} className="btn btn-secondary" rel="noopener"> |
| 79 | {chrome.downloadAppImage} |
| 80 | </a> |
| 81 | </p> |
| 82 | <p> |
| 83 | {fill(chrome.downloadVersion, { version: linux.version })} · {fill(chrome.downloadSize, { size: `${megabytes.format(appImage.size / 1_000_000)} MB` })} |
| 84 | </p> |
| 85 | <p> |
| 86 | {chrome.downloadChecksum}: <code>{appImage.sha256}</code> |
| 87 | </p> |
| 88 | <p>{chrome.downloadAppImageTrust}</p> |
| 89 | </> |
| 90 | ) : null} |
| 91 | </div> |
| 92 | ); |
| 93 | } |
| 94 |