From e47251991eb42cbeeff8ba1f4ad82d9f538b247b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 04:43:18 +0000 Subject: [PATCH 1/2] Add diagnostic script and improve permission fix for talkkonnect Added diagnose_talkkonnect.sh to help troubleshoot installation issues: - Checks binary installation - Finds all config files and shows ownership - Analyzes systemd service configuration - Detects audio/PipeWire sessions for each user - Identifies permission mismatches - Provides specific recommendations Improved fix_talkkonnect_permissions.sh: - Now automatically updates systemd service file if needed - Changes service user to match target user - Updates config path in service file - Reloads systemd after changes - Stops service before making changes These tools help resolve the "permission denied" error when talkkonnect is configured to run as one user but config is owned by another. --- diagnose_talkkonnect.sh | 163 +++++++++++++++++++++++++++++++++ fix_talkkonnect_permissions.sh | 69 ++++++++++++-- 2 files changed, 224 insertions(+), 8 deletions(-) create mode 100755 diagnose_talkkonnect.sh diff --git a/diagnose_talkkonnect.sh b/diagnose_talkkonnect.sh new file mode 100755 index 0000000..167091c --- /dev/null +++ b/diagnose_talkkonnect.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +# ====================================================================== +# File: diagnose_talkkonnect.sh +# Purpose: Diagnose talkkonnect installation and permission issues +# ====================================================================== + +echo "=======================================================================" +echo "TalkKonnect Installation Diagnostics" +echo "=======================================================================" +echo "" + +# Check if talkkonnect binary exists +echo "[1] Checking talkkonnect binary..." +if [ -f /usr/local/bin/talkkonnect ]; then + echo " ✓ Binary found: /usr/local/bin/talkkonnect" + ls -lh /usr/local/bin/talkkonnect +else + echo " ✗ Binary NOT found at /usr/local/bin/talkkonnect" + echo " Run the installation script first!" +fi +echo "" + +# Check for config files in all possible locations +echo "[2] Searching for config files..." +FOUND_CONFIGS=() +for USER_DIR in /home/*; do + CONFIG="$USER_DIR/.config/talkkonnect/talkkonnect.xml" + if [ -f "$CONFIG" ]; then + FOUND_CONFIGS+=("$CONFIG") + echo " ✓ Found: $CONFIG" + ls -lh "$CONFIG" + fi +done + +if [ -f "/root/.config/talkkonnect/talkkonnect.xml" ]; then + FOUND_CONFIGS+=("/root/.config/talkkonnect/talkkonnect.xml") + echo " ✓ Found: /root/.config/talkkonnect/talkkonnect.xml" + ls -lh "/root/.config/talkkonnect/talkkonnect.xml" +fi + +if [ ${#FOUND_CONFIGS[@]} -eq 0 ]; then + echo " ✗ No config files found!" +fi +echo "" + +# Check systemd service +echo "[3] Checking systemd service..." +if [ -f /etc/systemd/system/talkkonnect.service ]; then + echo " ✓ Service file found" + echo "" + echo " Service User:" + grep "^User=" /etc/systemd/system/talkkonnect.service || echo " (not specified)" + echo "" + echo " Config Path:" + grep "ExecStart=" /etc/systemd/system/talkkonnect.service | grep -o '\-config [^ ]*' || echo " (not found)" + echo "" + echo " Full ExecStart line:" + grep "ExecStart=" /etc/systemd/system/talkkonnect.service + echo "" +else + echo " ✗ Service file NOT found at /etc/systemd/system/talkkonnect.service" +fi +echo "" + +# Check which user should run talkkonnect +echo "[4] Audio/PipeWire session detection..." +for USER_NAME in kiosk user ubuntu; do + if id "$USER_NAME" &>/dev/null; then + USER_UID=$(id -u "$USER_NAME") + echo " Checking user: $USER_NAME (UID: $USER_UID)" + + # Check if PipeWire is running for this user + if [ -S "/run/user/$USER_UID/pipewire-0" ]; then + echo " ✓ PipeWire session active: /run/user/$USER_UID/pipewire-0" + else + echo " ✗ No PipeWire session found" + fi + + # Check audio group membership + if groups "$USER_NAME" | grep -q audio; then + echo " ✓ In 'audio' group" + else + echo " ✗ NOT in 'audio' group" + fi + + # Check input group membership (for PTT) + if groups "$USER_NAME" | grep -q input; then + echo " ✓ In 'input' group" + else + echo " ✗ NOT in 'input' group" + fi + echo "" + fi +done + +# Analyze permission issues +echo "[5] Permission Analysis..." +if [ ${#FOUND_CONFIGS[@]} -gt 0 ] && [ -f /etc/systemd/system/talkkonnect.service ]; then + SERVICE_USER=$(grep "^User=" /etc/systemd/system/talkkonnect.service | cut -d= -f2) + SERVICE_CONFIG=$(grep "ExecStart=" /etc/systemd/system/talkkonnect.service | grep -o '\-config [^ ]*' | awk '{print $2}') + + echo " Service configured to run as: $SERVICE_USER" + echo " Service configured to use config: $SERVICE_CONFIG" + echo "" + + if [ -f "$SERVICE_CONFIG" ]; then + CONFIG_OWNER=$(stat -c '%U' "$SERVICE_CONFIG") + echo " Config file owner: $CONFIG_OWNER" + echo "" + + if [ "$CONFIG_OWNER" != "$SERVICE_USER" ]; then + echo " ⚠️ PERMISSION MISMATCH!" + echo " Service runs as '$SERVICE_USER' but config is owned by '$CONFIG_OWNER'" + echo "" + echo " This is why you're getting 'permission denied'!" + echo "" + else + echo " ✓ Ownership is correct" + fi + else + echo " ✗ Config file not found at: $SERVICE_CONFIG" + fi +fi + +echo "" +echo "=======================================================================" +echo "Recommendations" +echo "=======================================================================" +echo "" + +# Provide recommendations +if [ ${#FOUND_CONFIGS[@]} -eq 0 ]; then + echo "❌ No config files found - run the installation script first:" + echo " ./talkkonnect_complete_install.sh" +elif [ ! -f /etc/systemd/system/talkkonnect.service ]; then + echo "⚠️ Config exists but no systemd service - complete the installation:" + echo " ./talkkonnect_complete_install.sh" +else + SERVICE_USER=$(grep "^User=" /etc/systemd/system/talkkonnect.service | cut -d= -f2 2>/dev/null) + SERVICE_CONFIG=$(grep "ExecStart=" /etc/systemd/system/talkkonnect.service | grep -o '\-config [^ ]*' | awk '{print $2}' 2>/dev/null) + + if [ -f "$SERVICE_CONFIG" ]; then + CONFIG_OWNER=$(stat -c '%U' "$SERVICE_CONFIG" 2>/dev/null) + + if [ "$CONFIG_OWNER" != "$SERVICE_USER" ]; then + echo "🔧 PERMISSION ISSUE DETECTED - Run the fix script:" + echo " sudo ./fix_talkkonnect_permissions.sh" + echo "" + echo " Or manually fix permissions:" + echo " sudo chown -R $SERVICE_USER:$SERVICE_USER $(dirname $SERVICE_CONFIG)" + else + echo "✅ Installation looks good!" + echo "" + echo "Next steps:" + echo " 1. Edit config: sudo nano $SERVICE_CONFIG" + echo " 2. Test manually: sudo -u $SERVICE_USER /usr/local/bin/talkkonnect -config $SERVICE_CONFIG" + echo " 3. Start service: sudo systemctl start talkkonnect" + echo " 4. Check status: sudo systemctl status talkkonnect" + fi + fi +fi + +echo "" diff --git a/fix_talkkonnect_permissions.sh b/fix_talkkonnect_permissions.sh index e8571db..ecb6bd4 100755 --- a/fix_talkkonnect_permissions.sh +++ b/fix_talkkonnect_permissions.sh @@ -84,25 +84,78 @@ echo "Current permissions:" ls -la "$CONFIG_DIR" echo "" -# Check systemd service if it exists +# Check and fix systemd service if it exists if [ -f /etc/systemd/system/talkkonnect.service ]; then echo "[+] Checking systemd service configuration..." SERVICE_USER=$(grep "^User=" /etc/systemd/system/talkkonnect.service | cut -d= -f2) SERVICE_CONFIG=$(grep "^ExecStart=" /etc/systemd/system/talkkonnect.service | grep -o '\-config [^ ]*' | cut -d' ' -f2) - echo " Service runs as: $SERVICE_USER" - echo " Config path: $SERVICE_CONFIG" + echo " Current service user: $SERVICE_USER" + echo " Current config path: $SERVICE_CONFIG" + echo "" + + NEED_SERVICE_UPDATE=false if [ "$SERVICE_USER" != "$TARGET_USER" ]; then - echo "" - echo "[!] WARNING: Service is configured to run as '$SERVICE_USER' but you selected '$TARGET_USER'" - echo "[!] Update /etc/systemd/system/talkkonnect.service to use the correct user" + echo " ⚠️ Service user needs to be changed from '$SERVICE_USER' to '$TARGET_USER'" + NEED_SERVICE_UPDATE=true fi if [ "$SERVICE_CONFIG" != "$CONFIG_DIR/talkkonnect.xml" ]; then + echo " ⚠️ Config path needs to be updated to: $CONFIG_DIR/talkkonnect.xml" + NEED_SERVICE_UPDATE=true + fi + + if [ "$NEED_SERVICE_UPDATE" = true ]; then echo "" - echo "[!] WARNING: Service config path doesn't match!" - echo "[!] Update /etc/systemd/system/talkkonnect.service to use: $CONFIG_DIR/talkkonnect.xml" + read -p "Update systemd service file? [Y/n]: " UPDATE_SERVICE + UPDATE_SERVICE=${UPDATE_SERVICE:-Y} + + if [[ "$UPDATE_SERVICE" =~ ^[Yy] ]]; then + echo "[+] Updating systemd service..." + + # Get target user's UID + TARGET_UID=$(id -u "$TARGET_USER") + + # Create updated service file + sudo tee /etc/systemd/system/talkkonnect.service > /dev/null </dev/null; then + echo "[+] Stopping existing service..." + sudo systemctl stop talkkonnect + fi + + echo "[+] Service is ready to start with new configuration" + else + echo "[!] Skipped service update - you'll need to update it manually" + fi + else + echo " ✓ Service configuration is correct" fi fi From f56f0be57ac48af4a6f8c251fcc9280cea22c175 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 12:36:09 +0000 Subject: [PATCH 2/2] Fix permission issues when creating config in different user's home The installation script was failing with "Permission denied" when trying to create the config directory in another user's home directory. Fixes: 1. Added home directory existence check before creating config 2. Use sudo -u to create directory as target user when needed 3. Use sudo tee to write config file (handles all permission scenarios) 4. Use sudo for sed command to modify the created config file 5. Always set proper ownership and permissions after creation This fixes the "mkdir: cannot create directory '/home/kiosk': Permission denied" error. Now the script will: - Verify target user's home directory exists (fail gracefully if not) - Create config directory as the target user - Write config file with sudo to avoid permission issues - Set proper ownership (user:user) and permissions (755 dir, 644 file) --- talkkonnect_complete_install.sh | 70 +++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/talkkonnect_complete_install.sh b/talkkonnect_complete_install.sh index 10c1cac..c0c1422 100644 --- a/talkkonnect_complete_install.sh +++ b/talkkonnect_complete_install.sh @@ -434,20 +434,38 @@ echo "=======================================================================" echo "[+] CREATING CONFIGURATION" echo "=======================================================================" -CONFIG_DIR="$TARGET_HOME/.config/talkkonnect" -mkdir -p "$CONFIG_DIR" +# Verify target user's home directory exists +if [ ! -d "$TARGET_HOME" ]; then + echo "[!] Error: Home directory for user '$TARGET_USER' does not exist: $TARGET_HOME" + echo "[!] Please ensure the user account is properly set up with a home directory" + echo "[!] You may need to run: sudo mkhomedir_helper $TARGET_USER" + exit 1 +fi -cat > "$CONFIG_DIR/talkkonnect.xml" << 'EOFXML' +CONFIG_DIR="$TARGET_HOME/.config/talkkonnect" + +# Create config directory with appropriate permissions +if [ "$TARGET_USER" != "$USER" ]; then + # Need to use sudo to create directory in another user's home + sudo -u "$TARGET_USER" mkdir -p "$CONFIG_DIR" + echo "[+] Created config directory as user: $TARGET_USER" +else + mkdir -p "$CONFIG_DIR" + echo "[+] Created config directory" +fi + +# Create config file (use tee with sudo to handle permissions) +sudo tee "$CONFIG_DIR/talkkonnect.xml" > /dev/null << 'EOFXML' - @@ -484,17 +502,17 @@ cat > "$CONFIG_DIR/talkkonnect.xml" << 'EOFXML' @@ -504,13 +522,13 @@ cat > "$CONFIG_DIR/talkkonnect.xml" << 'EOFXML' - - + @@ -522,14 +540,14 @@ cat > "$CONFIG_DIR/talkkonnect.xml" << 'EOFXML' EOFXML -# Update the log path to use actual username -sed -i "s|/home/user/|$TARGET_HOME/|g" "$CONFIG_DIR/talkkonnect.xml" +# Update the log path to use actual username (needs sudo since file was created with tee) +sudo sed -i "s|/home/user/|$TARGET_HOME/|g" "$CONFIG_DIR/talkkonnect.xml" -# Set proper ownership if running as a different user -if [ "$TARGET_USER" != "$USER" ]; then - sudo chown -R "$TARGET_USER:$TARGET_USER" "$CONFIG_DIR" - echo "[+] Set ownership of config directory to $TARGET_USER" -fi +# Set proper ownership - always needed since we used sudo tee +sudo chown -R "$TARGET_USER:$TARGET_USER" "$CONFIG_DIR" +sudo chmod 755 "$CONFIG_DIR" +sudo chmod 644 "$CONFIG_DIR/talkkonnect.xml" +echo "[+] Set ownership of config directory to $TARGET_USER" echo "[+] Created configuration file: $CONFIG_DIR/talkkonnect.xml"