Compare commits
5
Commits
1723803e9c
...
950eb5d361
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
950eb5d361
|
||
|
|
9278241dd0
|
||
|
|
1fa3770e6e
|
||
|
|
775b03e9de
|
||
|
|
d9ec12dba3
|
+54
-23
@@ -135,6 +135,23 @@ run_whiptail() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Ask a yes/no question on the CLI. Returns 0 for yes, 1 for no.
|
||||
# On read failure (e.g. closed stdin), falls back to default_answer.
|
||||
# Usage: confirm_yes_no "<prompt>" "<y|n default answer>" "$tty_in" "$tty_out"
|
||||
confirm_yes_no() {
|
||||
local prompt="$1"
|
||||
local default_answer="$2"
|
||||
local tty_in="$3"
|
||||
local tty_out="$4"
|
||||
local answer=""
|
||||
read -r -p "$prompt" answer < "$tty_in" > "$tty_out" 2>&1 || answer="$default_answer"
|
||||
answer="$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$answer")"
|
||||
if [[ -z "$answer" ]]; then
|
||||
answer="$default_answer"
|
||||
fi
|
||||
[[ "$answer" =~ ^[YyJj] ]]
|
||||
}
|
||||
|
||||
# Determine and prompt for the non-root target user
|
||||
prompt_target_user() {
|
||||
if [[ -n "${TARGET_USER:-}" ]]; then
|
||||
@@ -173,9 +190,7 @@ prompt_target_user() {
|
||||
if [[ -n "$candidate" && "$candidate" != "root" ]]; then
|
||||
printf "\n%bTarget User Detection:%b\n" "${CLR_CYAN}" "${CLR_RESET}" > "$tty_out"
|
||||
printf "Detected target user: %b%s%b\n" "${CLR_BOLD}" "$candidate" "${CLR_RESET}" > "$tty_out"
|
||||
local answer=""
|
||||
read -r -p "Use target user '$candidate'? [Y/n]: " answer < "$tty_in" > "$tty_out" 2>&1 || answer="y"
|
||||
if [[ -z "$answer" || "$answer" =~ ^[YyJj] ]]; then
|
||||
if confirm_yes_no "Use target user '$candidate'? [Y/n]: " "y" "$tty_in" "$tty_out"; then
|
||||
chosen="$candidate"
|
||||
fi
|
||||
fi
|
||||
@@ -255,36 +270,52 @@ prompt_ollama_models_path() {
|
||||
tty_out="/dev/stderr"
|
||||
fi
|
||||
|
||||
# If whiptail is available and running on an active terminal, use whiptail dialog
|
||||
# If whiptail is available and running on an active terminal, first ask
|
||||
# whether the configured default path should be used, and only show
|
||||
# the free-text path dialog (pre-filled with that default) if not.
|
||||
if command_exists whiptail && has_tty; then
|
||||
local tui_tmp
|
||||
tui_tmp="$(mktemp)"
|
||||
if run_whiptail --output-fd 3 --title "Ollama KI-Modelle Speicherort" \
|
||||
--inputbox "Bitte gib den Speicherort für die Ollama KI-Modelle an:" \
|
||||
10 70 "$default_path" \
|
||||
3> "$tui_tmp"; then
|
||||
local tui_input
|
||||
tui_input="$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' < "$tui_tmp")"
|
||||
if [[ -n "$tui_input" ]]; then
|
||||
chosen="$tui_input"
|
||||
else
|
||||
chosen="$default_path"
|
||||
local yesno_status=0
|
||||
run_whiptail --title "Ollama KI-Modelle Speicherort" \
|
||||
--yes-button "Standard verwenden" --no-button "Eigenen Pfad angeben" \
|
||||
--yesno "Standard-Speicherort für Ollama-Modelle:\n\n$default_path\n\nMöchtest du diesen Speicherort verwenden?" \
|
||||
12 70 || yesno_status=$?
|
||||
if [[ "$yesno_status" -eq 0 || "$yesno_status" -eq 255 ]]; then
|
||||
# Yes, or ESC/Cancel (255) - use the configured default,
|
||||
# consistent with the inputbox fallback below where an
|
||||
# empty or cancelled dialog also keeps the default instead
|
||||
# of asking again.
|
||||
chosen="$default_path"
|
||||
fi
|
||||
|
||||
if [[ -z "$chosen" ]]; then
|
||||
local tui_tmp
|
||||
tui_tmp="$(mktemp)"
|
||||
if run_whiptail --output-fd 3 --title "Ollama KI-Modelle Speicherort" \
|
||||
--inputbox "Bitte gib den Speicherort für die Ollama KI-Modelle an:" \
|
||||
10 70 "$default_path" \
|
||||
3> "$tui_tmp"; then
|
||||
chosen="$(sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' < "$tui_tmp")"
|
||||
fi
|
||||
rm -f "$tui_tmp"
|
||||
[[ -z "$chosen" ]] && chosen="$default_path"
|
||||
fi
|
||||
rm -f "$tui_tmp"
|
||||
fi
|
||||
|
||||
# CLI fallback if whiptail was not used or failed
|
||||
if [[ -z "$chosen" ]]; then
|
||||
printf "\n%bOllama KI-Modelle Speicherort:%b\n" "${CLR_CYAN}" "${CLR_RESET}" > "$tty_out"
|
||||
printf "Standard-Pfad: %b%s%b\n" "${CLR_BOLD}" "$default_path" "${CLR_RESET}" > "$tty_out"
|
||||
local input_path=""
|
||||
read -r -p "Speicherort für Ollama-Modelle eingeben [$default_path]: " input_path < "$tty_in" > "$tty_out" 2>&1 || true
|
||||
input_path="$(echo "$input_path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
if [[ -n "$input_path" ]]; then
|
||||
chosen="$input_path"
|
||||
else
|
||||
if confirm_yes_no "Standard-Speicherort verwenden? [J/n]: " "j" "$tty_in" "$tty_out"; then
|
||||
chosen="$default_path"
|
||||
else
|
||||
local input_path=""
|
||||
read -r -p "Speicherort für Ollama-Modelle eingeben [$default_path]: " input_path < "$tty_in" > "$tty_out" 2>&1 || true
|
||||
input_path="$(echo "$input_path" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
|
||||
if [[ -n "$input_path" ]]; then
|
||||
chosen="$input_path"
|
||||
else
|
||||
chosen="$default_path"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user