Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save roelbroersma/1044ecb62482f692267f8002780ba853 to your computer and use it in GitHub Desktop.
Save roelbroersma/1044ecb62482f692267f8002780ba853 to your computer and use it in GitHub Desktop.
When using Synology Snapshots and replicating these to another local volume, those snapshots (ending with ...-1) will automatically be visible (read-only) on the network. You can set 'Hide this folder in My Network locations' but every thime after replicating, it will again show them. You can schedule the script below just after replicating, it …
#!/bin/bash
# Script to set 'browseable=no' for specific Samba shares ending with -1
# Author: Roel Broersma
# Description: This script modifies the smb.share.conf file to set 'browseable=no'
# for all shares ending with -1, provided the 'browseable' option
# is already defined within the section. It then checks the Samba
# configuration for syntax errors and reloads the configuration.
# Version: 1.0
# Date: 27 March 2024
# Initialize variables
config_file="/etc/samba/smb.share.conf"
backup_file="$config_file.bak"
debug_mode=0 # Set to 1 to enable debug logging, 0 to disable
debug_log="/volume2/Scripts/sed_debug.log"
# Function to log messages when debug mode is enabled
function debug_log {
if [[ $debug_mode -eq 1 ]]; then
echo "$1" | tee -a $debug_log
fi
}
# Creating a backup of the configuration file for safety
debug_log "Creating backup of the configuration file..."
cp $config_file $backup_file || { echo "Failed to create a backup file."; exit 1; }
# Marking sections...
debug_log "Marking sections..."
sed -i 's/^\(\[.*-1\]\)/SECTION_START:\1/' $config_file || { echo "Failed to mark sections."; exit 1; }
# Modifying sections...
debug_log "Modifying sections..."
sed -i '/^SECTION_START:\[.*-1\]$/,/^\[/ { /^[[:space:]]*browseable=yes/ s/browseable=yes/browseable=no/; }' $config_file || { echo "Failed to modify sections."; exit 1; }
# Cleaning up markers...
debug_log "Cleaning up markers..."
sed -i 's/^SECTION_START://' $config_file || { echo "Failed to clean up markers."; exit 1; }
smbcontrol all reload-config
debug_log "Processing complete."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment