diff --git a/not-supported/smbserver.sh b/not-supported/smbserver.sh index b9870eb0..379d2e59 100644 --- a/not-supported/smbserver.sh +++ b/not-supported/smbserver.sh @@ -733,6 +733,7 @@ create_share() { force create mode = 0770 force directory mode = 0770 recycle:repository = .recycle + recycle:touch = true recycle:keeptree = yes recycle:versions = yes recycle:directory_mode = 0770 @@ -1288,6 +1289,104 @@ $MENU_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ done } +automatically_empty_recycle_bins() { + local SUBTITLE="Automatically empty recycle bins" + local count + local TEST="" + + # Ask for removal + if crontab -u root -l | grep -q "$SCRIPTS/recycle-bin-cleanup.sh" + then + if yesno_box_yes "It seems like automatic recycle bin cleanup is already configured. Do you want to disable it?" "$SUBTITLE" + then + crontab -u root -l | grep -v "$SCRIPTS/recycle-bin-cleanup.sh" | crontab -u root - + rm -rf "$SCRIPTS/recycle-bin-cleanup.sh" + msg_box "Automatic recycle bin cleanup was successfully disabled." "$SUBTITLE" + fi + return + fi + + # Ask for installation + msg_box "Automatic recycle bin cleanup does clean up all recycle bin folders automatically in the background. +It gets executed every day and cleans old files in the recycle bin folders that were deleted more than 2 days ago." "$SUBTITLE" + if ! yesno_box_yes "Do you want to enable automatic recycle bin cleanup?" "$SUBTITLE" + then + return + fi + + # Adjust some things + count=1 + while [ $count -le $MAX_COUNT ] + do + CACHE=$(sed -n "/^#SMB$count-start/,/^#SMB$count-end/p" "$SMB_CONF") + if [ -n "$CACHE" ] + then + TEST+="SMB$count" + if ! echo "$CACHE" | grep -q 'recycle:touch' + then + CACHE=$(echo "$CACHE" | sed "/recycle:repository/a \ \ \ \ recycle:touch = true") + sed -i "/^#SMB$count-start/,/^#SMB$count-end/d" "$SMB_CONF" + echo -e "\n$CACHE" >> "$SMB_CONF" + fi + fi + count=$((count+1)) + done + + # Return if none created + if [ -z "$TEST" ] + then + msg_box "No SMB-share created. Please create a SMB-share first." "$SUBTITLE" + return + else + systemctl restart smbd + fi + + # Execute + cat << AUTOMATIC_CLEANUP > "$SCRIPTS/recycle-bin-cleanup.sh" +#!/bin/bash + +# Secure the file +chown root:root "$SCRIPTS/recycle-bin-cleanup.sh" +chmod 700 "$SCRIPTS/recycle-bin-cleanup.sh" + +count=1 +while [ \$count -le $MAX_COUNT ] +do + CACHE=\$(sed -n "/^#SMB\$count-start/,/^#SMB\$count-end/p" "$SMB_CONF") + if [ -n "\$CACHE" ] + then + SMB_PATH=\$(echo "\$CACHE" | grep "path =" | grep -oP '/.*') + if [ -d "\$SMB_PATH" ] && [ -d "\$SMB_PATH/.recycle/" ] + then + find "\$SMB_PATH/.recycle/" -type f -atime +2 -delete + fi + fi + count=\$((count+1)) +done +AUTOMATIC_CLEANUP + + # Secure the file + chown root:root "$SCRIPTS/recycle-bin-cleanup.sh" + chmod 700 "$SCRIPTS/recycle-bin-cleanup.sh" + + # Add cronjob + crontab -u root -l | grep -v "$SCRIPTS/recycle-bin-cleanup.sh" | crontab -u root - + crontab -u root -l | { cat; echo "@daily $SCRIPTS/recycle-bin-cleanup.sh >/dev/null"; } | crontab -u root - + + # Show message + msg_box "Automatic recycle bin cleanup was successfully configured!" "$SUBTITLE" + + # Allow to adjust Nextcloud to do the same + if yesno_box_yes "Do you want Nextcloud to delete files in its trashbin that were deleted more than 2 days ago \ +and file versions that were created more than 2 days ago, too?" "$SUBTITLE" + then + nextcloud_occ config:system:set trashbin_retention_obligation --value="auto, 2" + nextcloud_occ config:system:set versions_retention_obligation --value="auto, 2" + msg_box "Nextcloud was successfully configured to delete files in its trashbin that were deleted more than 2 days ago \ +and file versions that were created more than 2 days ago!" "$SUBTITLE" + fi +} + # SMB-server Main Menu while : do @@ -1295,16 +1394,20 @@ do "Choose what you want to do. $MENU_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \ "Open the SMB-user Menu" "(manage SMB-users)" \ -"Open the SMB-share Menu " "(manage SMB-shares)" \ +"Open the SMB-share Menu" "(manage SMB-shares)" \ +"Automatically empty recycle bins " "(Schedule cleanup of recycle folders)" \ "Exit" "(exit this script)" 3>&1 1>&2 2>&3) case "$choice" in "Open the SMB-user Menu") user_menu ;; - "Open the SMB-share Menu ") + "Open the SMB-share Menu") share_menu ;; + "Automatically empty recycle bins ") + automatically_empty_recycle_bins + ;; "Exit") break ;;