Skip to content

Commit d92fef8

Browse files
test homebrew noninteractive install
1 parent 718053f commit d92fef8

2 files changed

Lines changed: 43 additions & 10 deletions

File tree

MacUtilGUI/Services/ScriptService.fs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ module ScriptService =
6969
export TERM=${TERM:-xterm-256color}
7070
export DEBIAN_FRONTEND=noninteractive
7171
export CI=true
72-
export NONINTERACTIVE=1
73-
export FORCE_NONINTERACTIVE=1
72+
export NONINTERACTIVE=0
73+
export FORCE_NONINTERACTIVE=0
7474
export HOMEBREW_NO_ENV_HINTS=1
7575
export HOMEBREW_NO_INSTALL_CLEANUP=1
7676
export HOMEBREW_NO_AUTO_UPDATE=1
@@ -110,11 +110,8 @@ set +m # Disable job control
110110

111111
// Function to check if a script needs elevation (contains sudo, $ESCALATION_TOOL, etc.)
112112
let needsElevation (scriptContent: string) : bool =
113-
scriptContent.Contains("sudo ")
114-
|| scriptContent.Contains("$ESCALATION_TOOL")
113+
scriptContent.Contains("$ESCALATION_TOOL")
115114
|| scriptContent.Contains("${ESCALATION_TOOL}")
116-
|| scriptContent.Contains("/usr/bin/sudo")
117-
|| scriptContent.Contains("/bin/sudo")
118115

119116
let getEmbeddedResource (resourcePath: string) : string option =
120117
try
@@ -362,8 +359,8 @@ set +m # Disable job control
362359
"export TERM=xterm-256color\n" +
363360
"export DEBIAN_FRONTEND=noninteractive\n" +
364361
"export CI=true\n" +
365-
"export NONINTERACTIVE=1\n" +
366-
"export FORCE_NONINTERACTIVE=1\n" +
362+
"export NONINTERACTIVE=0\n" +
363+
"export FORCE_NONINTERACTIVE=0\n" +
367364
"export HOMEBREW_NO_ENV_HINTS=1\n" +
368365
"export HOMEBREW_NO_INSTALL_CLEANUP=1\n" +
369366
"export HOMEBREW_NO_AUTO_UPDATE=1\n" +

scripts/common-script.sh

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,54 @@ done
2222
return 0
2323
}
2424

25+
setup_askpass() {
26+
# Create a temporary askpass helper script
27+
ASKPASS_SCRIPT="/tmp/macutil_askpass_$$"
28+
cat > "$ASKPASS_SCRIPT" << 'EOF'
29+
#!/bin/sh
30+
osascript -e 'display dialog "Administrator password required for MacUtil setup:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null
31+
EOF
32+
chmod +x "$ASKPASS_SCRIPT"
33+
export SUDO_ASKPASS="$ASKPASS_SCRIPT"
34+
}
35+
36+
cleanup_askpass() {
37+
# Clean up the temporary askpass script
38+
if [ -n "$ASKPASS_SCRIPT" ] && [ -f "$ASKPASS_SCRIPT" ]; then
39+
rm -f "$ASKPASS_SCRIPT"
40+
fi
41+
}
42+
2543
checkPackageManager() {
2644
## Check if brew is installed
2745
if command_exists "brew"; then
2846
printf "%b\n" "${GREEN}Homebrew is installed${RC}"
2947
else
3048
printf "%b\n" "${RED}Homebrew is not installed${RC}"
3149
printf "%b\n" "${YELLOW}Installing Homebrew...${RC}"
32-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
33-
if [ $? -ne 0 ]; then
50+
51+
# Setup askpass helper for automated password handling
52+
setup_askpass
53+
54+
# Use sudo with askpass for non-interactive installation
55+
SUDO_ASKPASS="$ASKPASS_SCRIPT" sudo -A /bin/bash -c "NONINTERACTIVE=1 $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
56+
install_result=$?
57+
58+
# Cleanup askpass helper
59+
cleanup_askpass
60+
61+
if [ $install_result -ne 0 ]; then
3462
printf "%b\n" "${RED}Failed to install Homebrew${RC}"
3563
exit 1
3664
fi
65+
66+
# Add Homebrew to PATH for the current session
67+
if [ -f "/opt/homebrew/bin/brew" ]; then
68+
eval "$(/opt/homebrew/bin/brew shellenv)"
69+
elif [ -f "/usr/local/bin/brew" ]; then
70+
eval "$(/usr/local/bin/brew shellenv)"
71+
fi
72+
trap cleanup_askpass EXIT INT TERM
3773
fi
3874
}
3975

0 commit comments

Comments
 (0)