Skip to content

Commit

Permalink
fix: add script for installing yay
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 8, 2024
1 parent 0379559 commit 00b86b9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions src/utils/setup/setupPacmanPack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { info, warning } from "ci-log"
import { execa, execaSync } from "execa"
import which from "which"
import type { InstallationInfo } from "./setupBin.js"
import { tmpdir } from "os"
import { join } from "path"

/* eslint-disable require-atomic-updates */
let didUpdate: boolean = false
Expand All @@ -14,9 +16,8 @@ export async function setupPacmanPack(name: string, version?: string, aur?: stri

const pacman = "pacman"

if (aur === "yay" && which.sync("yay", { nothrow: true }) === null) {
// TODO: install yay automatically
throw new Error(`yay is needed for ${name}, but it is not installed, please install it manually first`)
if (aur === "yay") {
setupYay()
}

// yay can't run as root, so skip update
Expand Down Expand Up @@ -78,3 +79,29 @@ async function availablePacmanVersions(pacman: string, name: string) {
}
return availableVersions
}

function setupYay() {
if (which.sync("yay", { nothrow: true }) === null) {
try {
// Install prerequisites
execRootSync("pacman", ["-S", "--noconfirm", "base-devel", "git"])

// Clone the yay repository into a temporary directory
execaSync("git", ["clone", "https://aur.archlinux.org/yay.git"], {
stdio: "inherit",
cwd: tmpdir(),
})

// Build and install yay
execaSync("makepkg", ["-si", "--noconfirm"], {
stdio: "inherit",
cwd: join(tmpdir(), "yay"),
})

// clean-up
execaSync("rm", ["-rf", join(tmpdir(), "yay")], { stdio: "inherit" })
} catch (error) {
throw new Error(`Failed to install yay: ${error}. Install yay manually and re-run the script.`)
}
}
}

0 comments on commit 00b86b9

Please sign in to comment.