From f56f0be57ac48af4a6f8c251fcc9280cea22c175 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 12:36:09 +0000 Subject: [PATCH] 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"