From e47251991eb42cbeeff8ba1f4ad82d9f538b247b Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 04:43:18 +0000 Subject: [PATCH] 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