Skip to content

Commit afcab59

Browse files
committed
Never escalate for optional apt packages outside Tauri mode
The optional bypass sat inside the TAURI_MODE branch, so a plain curl | sh install on a non-root Debian or Ubuntu box still fell through to the escalation branch and showed the default-yes permission prompt for cmake, GCC and the libcurl headers. That is exactly the toolchain this change set declared unnecessary on the consumer path, so the prompt asked for a password to install packages nothing here uses, and a headless run failed the same way instead of falling through to prebuilt llama.cpp. Move the check above the mode split so optional callers return 2 in both modes. Required packages such as curl still escalate unchanged.
1 parent 88d52a0 commit afcab59

2 files changed

Lines changed: 53 additions & 9 deletions

File tree

install.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,14 +778,17 @@ _smart_apt_install() {
778778
return 0
779779
fi
780780

781+
# Optional callers never elevate, in any mode: nothing on the consumer path
782+
# builds anything, so neither the terminal sudo prompt below nor the Tauri
783+
# NEED_SUDO dialog (whose Cancel leaves the user not installed) may gate the
784+
# run over unused tools. The caller falls through to prebuilt llama.cpp.
785+
# Required packages such as curl still escalate.
786+
if [ "${_SMART_APT_OPTIONAL:-false}" = true ]; then
787+
return 2
788+
fi
789+
781790
if [ "$TAURI_MODE" = true ]; then
782-
# Optional callers never elevate: NEED_SUDO raises a mandatory desktop
783-
# permission dialog whose Cancel leaves the user not installed, over tools
784-
# nothing needs. The caller falls through to prebuilt llama.cpp.
785-
if [ "${_SMART_APT_OPTIONAL:-false}" = true ]; then
786-
return 2
787-
fi
788-
# Otherwise report needed packages and exit — Rust handles elevation.
791+
# Report needed packages and exit — Rust handles elevation.
789792
tauri_log "NEED_SUDO" "$_STILL_MISSING"
790793
exit 2
791794
fi
@@ -2089,8 +2092,8 @@ _check_linux_deps() {
20892092
if [ -n "$_optional_missing" ] && command -v apt-get >/dev/null 2>&1; then
20902093
step "deps" "installing optional build tools: $_optional_missing" "$C_DIM"
20912094
# Subshell because _smart_apt_install exits rather than returns, so `|| true`
2092-
# alone would not catch it. _SMART_APT_OPTIONAL suppresses the NEED_SUDO
2093-
# handshake, so no install hinges on a prompt for tools nothing here needs.
2095+
# alone would not catch it. _SMART_APT_OPTIONAL suppresses every escalation
2096+
# path, so no install hinges on a prompt for tools nothing here needs.
20942097
( _SMART_APT_OPTIONAL=true; _smart_apt_install $_optional_missing ) || true
20952098
_optional_missing=""
20962099
command -v cmake >/dev/null 2>&1 || _optional_missing="$_optional_missing cmake"

tests/sh/test_linux_deps_gate.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,47 @@ _mk git 'exit 0'
163163
_out="$(_run_gate true)"
164164
assert_contains "install proceeds" "$_out" "RC=0"
165165

166+
echo "=== optional apt packages never ask for elevation, in any mode ==="
167+
# Regression: the optional bypass sat inside the TAURI_MODE branch, so a plain
168+
# `curl | sh` on a non-root Debian box still hit the sudo prompt (default yes) and
169+
# installed cmake, GCC and dev headers that nothing on the consumer path uses.
170+
_APT_FN=$(mktemp)
171+
{
172+
sed -n '/^_is_pkg_installed()/,/^}$/p' "$INSTALL_SH"
173+
sed -n '/^_apt_distro_description()/,/^}$/p' "$INSTALL_SH"
174+
sed -n '/^_can_read_tty()/,/^}$/p' "$INSTALL_SH"
175+
sed -n '/^_smart_apt_install()/,/^}$/p' "$INSTALL_SH"
176+
} > "$_APT_FN"
177+
178+
_run_apt() {
179+
# $1 = TAURI_MODE, $2 = _SMART_APT_OPTIONAL. apt-get always fails, as it does
180+
# for a non-root user, so the function reaches its escalation decision.
181+
rm -f "$_BIN"/*
182+
_mk apt-get 'exit 100'
183+
_mk sudo 'echo "ELEVATION_ATTEMPTED: $*"; exit 1'
184+
ln -sf "$(command -v sed)" "$_BIN/sed" # the function trims its list with sed
185+
# _APT_FN after _HARNESS so the real function replaces the recording stub.
186+
( PATH="$_BIN"; export PATH
187+
"$_SH" -c ". '$_HARNESS'; . '$_APT_FN'; TAURI_MODE=$1; _SMART_APT_OPTIONAL=$2
188+
( _smart_apt_install unsloth_absent_pkg ); echo \"RC=\$?\"" 2>&1 )
189+
}
190+
191+
_out="$(_run_apt false true)"
192+
assert_contains "optional: returns 2 so the caller can continue" "$_out" "RC=2"
193+
assert_not_contains "optional: no sudo prompt" "$_out" "elevated permissions"
194+
assert_not_contains "optional: sudo never invoked" "$_out" "ELEVATION_ATTEMPTED"
195+
196+
_out="$(_run_apt true true)"
197+
assert_contains "optional in Tauri: returns 2" "$_out" "RC=2"
198+
assert_not_contains "optional in Tauri: no NEED_SUDO dialog" "$_out" "NEED_SUDO"
199+
200+
_out="$(_run_apt false false)"
201+
assert_contains "required: still escalates" "$_out" "ELEVATION_ATTEMPTED"
202+
203+
_out="$(_run_apt true false)"
204+
assert_contains "required in Tauri: still asks Rust to elevate" "$_out" "NEED_SUDO"
205+
206+
rm -f "$_APT_FN"
166207
rm -rf "$_BIN" "$_FN_FILE" "$_HARNESS"
167208
echo ""
168209
echo "=== $PASS passed, $FAIL failed ==="

0 commit comments

Comments
 (0)