Skip to content

Commit 6006ce2

Browse files
committed
Switch homebrew to use askpass
1 parent a027ec7 commit 6006ce2

3 files changed

Lines changed: 45 additions & 63 deletions

File tree

package-lock.json

Lines changed: 26 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "default",
3-
"version": "1.1.0-beta1",
3+
"version": "1.1.0-beta4",
44
"description": "Default plugin for Codify - provides 50+ declarative resources for managing development tools and system configuration across macOS and Linux",
55
"main": "dist/index.js",
66
"scripts": {
@@ -42,8 +42,8 @@
4242
"license": "ISC",
4343
"type": "module",
4444
"dependencies": {
45-
"@codifycli/plugin-core": "1.1.0-beta12",
46-
"@codifycli/schemas": "1.1.0-beta4",
45+
"@codifycli/plugin-core": "1.1.0-beta16",
46+
"@codifycli/schemas": "1.1.0-beta5",
4747
"ajv": "^8.18.0",
4848
"ajv-formats": "^2.1.1",
4949
"chalk": "^5.3.0",

src/resources/homebrew/homebrew.ts

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -100,48 +100,16 @@ export class HomebrewResource extends Resource<HomebrewConfig> {
100100
return this.installBrewInCustomDir(plan.desiredConfig.directory)
101101
}
102102

103-
const askpassPath = path.join(os.tmpdir(), `codify-askpass-${nanoid(8)}.sh`);
104-
105-
const askpassScript = `#!/bin/bash
106-
prompt="\${1:-Password: }"
107-
printf '\\033[34m%s\\033[0m' "$prompt" > /dev/tty
108-
109-
password=""
110-
while IFS= read -r -s -n1 -d '' char < /dev/tty; do
111-
if [[ "$char" == $'\\0' || "$char" == $'\\n' || "$char" == $'\\r' ]]; then
112-
break
113-
elif [[ "$char" == $'\\177' || "$char" == $'\\b' ]]; then
114-
if [[ -n "$password" ]]; then
115-
password="\${password%?}"
116-
printf '\\b \\b' > /dev/tty
117-
fi
118-
else
119-
password+="$char"
120-
printf '*' > /dev/tty
121-
fi
122-
done
123-
124-
printf '\\n' > /dev/tty
125-
printf '%s\\n' "$password"
126-
`;
127103

128-
try {
129-
await fs.writeFile(askpassPath, askpassScript, { mode: 0o700 });
130-
131-
await $.spawn(
132-
'/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
133-
{
134-
stdin: true,
135-
interactive: true,
136-
env: {
137-
NONINTERACTIVE: 1,
138-
SUDO_ASKPASS: askpassPath,
139-
},
140-
}
141-
);
142-
} finally {
143-
await fs.unlink(askpassPath).catch(() => {});
144-
}
104+
await $.spawn(
105+
'/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
106+
{
107+
requiresSudoAskpass: true,
108+
env: {
109+
NONINTERACTIVE: 1,
110+
},
111+
}
112+
);
145113

146114
const brewPath = Utils.isLinux() ? '/home/linuxbrew/.linuxbrew/bin/brew' : '/opt/homebrew/bin/brew';
147115
await FileUtils.addToShellRc(`eval "$(${brewPath} shellenv)"`);
@@ -153,7 +121,7 @@ printf '%s\\n' "$password"
153121
override async destroy(): Promise<void> {
154122
const $ = getPty();
155123

156-
const { status } = await $.spawnSafe('which brew');
124+
const { status } = await $.spawnSafe('which brew', { interactive: true });
157125
if (status === SpawnStatus.ERROR) {
158126
return;
159127
}
@@ -164,8 +132,12 @@ printf '%s\\n' "$password"
164132
if (homebrewDirectory === '/opt/homebrew') {
165133
await $.spawnSafe(
166134
'/bin/bash -c "$(/usr/bin/curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"',
167-
{ stdin: true, interactive: true, env: { INTERACTIVE: 1 } }
168-
)
135+
{
136+
requiresSudoAskpass: true,
137+
env: {
138+
NONINTERACTIVE: 1,
139+
},
140+
})
169141
} else {
170142
await $.spawn(`rm -rf ${homebrewDirectory}`, { requiresRoot: true });
171143
}

0 commit comments

Comments
 (0)