273273
274274setup_media_permissions () {
275275 local media_dirs=$1
276+ local needs_reload=false
276277
277278 print_info " Setting up media directory permissions..."
278279
@@ -293,13 +294,13 @@ setup_media_permissions() {
293294 # Fall back to adding dust user to the directory owner's group
294295 local dir_owner=$( stat -c ' %U' " $dir " )
295296 local dir_group=$( stat -c ' %G' " $dir " )
296- usermod -aG " $dir_group " " $SERVICE_USER " 2> /dev/null || true
297+ usermod -aG " $dir_group " " $SERVICE_USER " 2> /dev/null && needs_reload=true || true
297298 }
298299 else
299300 print_info " Adding group permissions for $dir "
300301 # No setfacl, use group permissions
301302 local dir_group=$( stat -c ' %G' " $dir " )
302- usermod -aG " $dir_group " " $SERVICE_USER " 2> /dev/null || {
303+ usermod -aG " $dir_group " " $SERVICE_USER " 2> /dev/null && needs_reload=true || {
303304 print_warning " Could not add $SERVICE_USER to group $dir_group "
304305 print_warning " You may need to manually grant access to $dir "
305306 }
@@ -312,6 +313,52 @@ setup_media_permissions() {
312313 done
313314
314315 print_info " Media directory permissions configured"
316+
317+ # If we added the user to groups, we need to reload systemd
318+ if [ " $needs_reload " = true ]; then
319+ echo " "
320+ echo -e " ${YELLOW} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC} "
321+ echo -e " ${YELLOW} Important: Group Changes Detected${NC} "
322+ echo -e " ${YELLOW} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC} "
323+ echo " "
324+ echo " The 'dust' user was added to one or more groups to access your media."
325+ echo " For these changes to take effect, the systemd daemon needs to reload"
326+ echo " and the service needs to restart."
327+ echo " "
328+
329+ if [ -t 0 ]; then
330+ # Interactive mode - ask user
331+ read -p " Would you like to reload systemd and restart the service now? [Y/n] " -n 1 -r
332+ echo " "
333+ if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then
334+ print_info " Reloading systemd daemon..."
335+ systemctl daemon-reload
336+ if systemctl is-active --quiet " $SERVICE_NAME " 2> /dev/null; then
337+ print_info " Restarting service to apply group changes..."
338+ systemctl restart " $SERVICE_NAME "
339+ sleep 2
340+ if systemctl is-active --quiet " $SERVICE_NAME " ; then
341+ print_success " Service restarted successfully"
342+ else
343+ print_warning " Service may not have restarted properly"
344+ print_info " Check logs with: journalctl -u $SERVICE_NAME -n 50"
345+ fi
346+ fi
347+ else
348+ print_warning " Skipping reload. To apply changes later, run:"
349+ print_info " sudo systemctl daemon-reload"
350+ print_info " sudo systemctl restart $SERVICE_NAME "
351+ fi
352+ else
353+ # Non-interactive mode - just inform the user
354+ print_warning " Running in non-interactive mode."
355+ print_info " To apply group changes, please run:"
356+ print_info " sudo systemctl daemon-reload"
357+ print_info " sudo systemctl restart $SERVICE_NAME "
358+ fi
359+ echo " "
360+ fi
361+
315362 print_info " Note: If you still see permission errors, you may need to:"
316363 print_info " sudo chmod -R +rX /path/to/media"
317364 print_info " Or: sudo chown -R $SERVICE_USER :$SERVICE_USER /path/to/media"
0 commit comments