Skip to content

Commit

Permalink
smbserver - add option to empty all recycle bins (#1983)
Browse files Browse the repository at this point in the history
  • Loading branch information
szaimen authored May 22, 2021
1 parent b5bc04f commit 39e64fe
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions not-supported/smbserver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ then
fi

# Find mounts
print_text_in_color "$ICyan" "Getting all valid mounts. This can take a while..."
DIRECTORIES=$(find /mnt/ -mindepth 1 -maxdepth 2 -type d | grep -v "/mnt/ncdata")
mapfile -t DIRECTORIES <<< "$DIRECTORIES"
for directory in "${DIRECTORIES[@]}"
Expand Down Expand Up @@ -1387,6 +1388,81 @@ and file versions that were created more than 2 days ago!" "$SUBTITLE"
fi
}

empty_recycle_bins() {
local count
local selected_options
local args
local TEST=""
local FOLDER_SIZE
local SMB_PATH
local SUBTITLE="Empty recycle bins"

# Show a list with available SMB-shares
args=(whiptail --title "$TITLE - $SUBTITLE" --separate-output --checklist \
"Please select which recycle folders you want to empty.
$CHECKLIST_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4)
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 '/.*')/.recycle/"
if [ -d "$SMB_PATH" ]
then
FOLDER_SIZE="$(du -sh "$SMB_PATH" | awk '{print $1}')"
else
FOLDER_SIZE=0B
fi
args+=("$SMB_PATH" "$FOLDER_SIZE" ON)
TEST+="$SMB_PATH"
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
fi

# Show selected shares
selected_options=$("${args[@]}" 3>&1 1>&2 2>&3)
if [ -z "$selected_options" ]
then
msg_box "No option selected." "$SUBTITLE"
return
fi
mapfile -t selected_options <<< "$selected_options"
for element in "${selected_options[@]}"
do
print_text_in_color "$ICyan" "Emptying $element"
if [ -d "$element" ]
then
rm -r "$element"
fi
done
msg_box "All selected recycle folders were emptied!
Please note: If you are using BTRFS as file system, it can take up to 54h until the space is released due to automatic snapshots." "$SUBTITLE"

# Allow to clean up Nextclouds trashbin, too
if yesno_box_no "Do you want to clean up Nextclouds trashbin, too?
This will run the command 'occ trashbin:cleanup --all-users' for you if you select 'Yes'!" "$SUBTITLE"
then
nextcloud_occ trashbin:cleanup --all-users -vvv
msg_box "The cleanup of Nextclouds trashbin was successful!" "$SUBTITLE"
fi

# Allow to clean up Nextclouds versions, too
if yesno_box_no "Do you want to clean up all file versions in Nextcloud?
This will run the command 'occ versions:cleanup' for you if you select 'Yes'!" "$SUBTITLE"
then
nextcloud_occ versions:cleanup -vvv
msg_box "The cleanup of all file versions in Nextcloud was successful!" "$SUBTITLE"
fi
}

# SMB-server Main Menu
while :
do
Expand All @@ -1396,6 +1472,7 @@ $MENU_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"Open the SMB-user Menu" "(manage SMB-users)" \
"Open the SMB-share Menu" "(manage SMB-shares)" \
"Automatically empty recycle bins " "(Schedule cleanup of recycle folders)" \
"Empty recycle bins" "(Clean up recycle folders)" \
"Exit" "(exit this script)" 3>&1 1>&2 2>&3)

case "$choice" in
Expand All @@ -1408,6 +1485,9 @@ $MENU_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"Automatically empty recycle bins ")
automatically_empty_recycle_bins
;;
"Empty recycle bins")
empty_recycle_bins
;;
"Exit")
break
;;
Expand Down

0 comments on commit 39e64fe

Please sign in to comment.