From 7921c959ff7df062e483a9362645eed6f2b7a172 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 3 Dec 2025 18:35:57 +0000 Subject: [PATCH] Add smart user detection and selection for kiosk client install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added intelligent user selection that scans /home directory and presents available users, making it much easier to install the kiosk client for the correct user account. Features: 1. Smart User Detection - Scans /etc/passwd for real users (UID >= 1000) - Excludes system accounts (nologin, /bin/false) - Shows username, UID, and home directory - Presents numbered list of available users 2. Intelligent Defaults - Auto-suggests SUDO_USER if available - Falls back to first detected user - Highlights suggested choice as default 3. Manual Override - Option to manually enter username - Validates entered username exists - Shows confirmation with UID 4. Improved User Experience - install_client_only(): Uses new select_user function - configure_local_client(): Shows current user, offers to change - Clear feedback on user selection - Proper error handling for invalid selections 5. Verified Ownership All user configs are properly owned by selected user: - ~/.baresip/config (chown in configure_baresip:1879) - ~/.baresip/accounts (chown in configure_baresip:1879) - ~/.config/systemd/user/* (chown in enable_client_services:1962) - ~/.config/wireplumber/* (chown in configure_audio_ducking:1067) - All PipeWire/audio operations run as selected user Example Flow: $ sudo ./easy-asterisk-interactive-v1.28.sh > Install Client Only Scanning for users... 1) kiosk (UID: 1000, Home: /home/kiosk) 2) admin (UID: 1001, Home: /home/admin) 3) Enter username manually Select user [1]: 1 ✓ Selected user: kiosk (UID: 1000) This makes it much easier to install on kiosk systems where you might not remember the exact username, and ensures all configs are created with proper ownership from the start. --- easy-asterisk-interactive-v1.28.sh | 112 +++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 7 deletions(-) diff --git a/easy-asterisk-interactive-v1.28.sh b/easy-asterisk-interactive-v1.28.sh index 28c2b83..e987d7c 100644 --- a/easy-asterisk-interactive-v1.28.sh +++ b/easy-asterisk-interactive-v1.28.sh @@ -67,6 +67,80 @@ generate_password() { tr -dc 'A-Za-z0-9' < /dev/urandom | head -c 16 } +select_user() { + # Scan /home for real users (exclude system accounts) + local -a users=() + local -a user_ids=() + local count=0 + + echo "Scanning for users..." + echo "" + + # Get users from /home with valid shells + while IFS=: read -r username _ uid _ _ homedir shell; do + # Only include users with UID >= 1000 and valid shell + if [[ $uid -ge 1000 && -d "$homedir" && "$shell" != "/usr/sbin/nologin" && "$shell" != "/bin/false" ]]; then + ((count++)) + users+=("$username") + user_ids+=("$uid") + echo " ${count}) ${username} (UID: ${uid}, Home: ${homedir})" + fi + done < /etc/passwd + + # Add option to manually enter username + ((count++)) + echo " ${count}) Enter username manually" + echo "" + + # Suggest default based on SUDO_USER or first user found + local default_choice="" + local default_user="${SUDO_USER:-}" + if [[ -z "$default_user" ]]; then + default_user="${users[0]:-}" + default_choice="1" + else + # Find index of SUDO_USER + for i in "${!users[@]}"; do + if [[ "${users[$i]}" == "$default_user" ]]; then + default_choice=$((i + 1)) + break + fi + done + fi + + if [[ -n "$default_choice" ]]; then + read -p "Select user [${default_choice}]: " choice + choice="${choice:-$default_choice}" + else + read -p "Select user: " choice + fi + + # Validate choice + if [[ "$choice" =~ ^[0-9]+$ && "$choice" -le "${#users[@]}" && "$choice" -gt 0 ]]; then + local idx=$((choice - 1)) + KIOSK_USER="${users[$idx]}" + KIOSK_UID="${user_ids[$idx]}" + echo "" + print_success "Selected user: $KIOSK_USER (UID: $KIOSK_UID)" + return 0 + elif [[ "$choice" == "$count" ]]; then + # Manual entry + echo "" + read -p "Enter username: " KIOSK_USER + if id "$KIOSK_USER" >/dev/null 2>&1; then + KIOSK_UID=$(id -u "$KIOSK_USER") + print_success "Selected user: $KIOSK_USER (UID: $KIOSK_UID)" + return 0 + else + print_error "User '$KIOSK_USER' not found" + return 1 + fi + else + print_error "Invalid selection" + return 1 + fi +} + load_config() { if [[ -f "$CONFIG_FILE" ]]; then source "$CONFIG_FILE" 2>/dev/null || true @@ -1192,13 +1266,33 @@ router_doctor() { configure_local_client() { print_header "Configure Local Client" load_config + + # If KIOSK_USER already set from config, show and ask if want to change + if [[ -n "$KIOSK_USER" ]]; then + echo "Current configured user: $KIOSK_USER" + read -p "Change user? [y/N]: " change_user + if [[ "$change_user" =~ ^[Yy]$ ]]; then + KIOSK_USER="" + KIOSK_UID="" + fi + fi + + # If still no user, select one if [[ -z "$KIOSK_USER" ]]; then - local default_user="${SUDO_USER:-$USER}" - read -p "User [$default_user]: " KIOSK_USER - KIOSK_USER="${KIOSK_USER:-$default_user}" + echo "" + echo "Select the user to configure:" + echo "" + if ! select_user; then + print_error "User selection failed" + return 1 + fi + else + # Ensure KIOSK_UID is set KIOSK_UID=$(id -u "$KIOSK_USER" 2>/dev/null) fi + echo "" + if [[ ! -d "/home/${KIOSK_USER}/.baresip" ]]; then print_error "Baresip not installed for $KIOSK_USER" echo "" @@ -2165,11 +2259,15 @@ install_server_only() { install_client_only() { print_header "Client Installation" - local default_user="${SUDO_USER:-$USER}" - read -p "User [$default_user]: " target_user - KIOSK_USER="${target_user:-$default_user}" - KIOSK_UID=$(id -u "$KIOSK_USER") + echo "Select the user to install the kiosk client for:" + echo "" + if ! select_user; then + print_error "User selection failed" + return 1 + fi + + echo "" read -p "Server (IP or domain): " ASTERISK_HOST read -p "SIP Password: " SIP_PASSWORD