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