HEX
Server: Apache/2.4.63 (Unix)
System: Linux TOMS-220NAS 4.4.302+ #86009 SMP Wed Nov 26 18:19:17 CST 2025 x86_64
User: flavio87 (1026)
PHP: 8.3.27
Disabled: NONE
Upload Files
File: /volume1/@appstore/WebStation/feasibility_checks/check_share_for_cold_tier.sh
#!/usr/bin/bash

# Function to check if a share folder is used by web services as document root
check_web_service_usage() {
    local share_name="$1"
    local service_config="/usr/syno/etc/packages/WebStation/Service.json"
    
    # Check if WebStation Service configuration file exists
    if [ ! -f "$service_config" ]; then
        return 1  # No WebStation config, no usage
    fi
    
    # Extract all root paths from Service.json and check if any share folder name matches
    # Extract the folder name after /volumeX/ and compare with $1
    
    # Use grep to find all root entries with complete paths
    local root_paths=$(grep -o "\"root\"[[:space:]]*:[[:space:]]*\"/volume[0-9]*/[^\"]*\"" "$service_config" 2>/dev/null)
    
    if [ -n "$root_paths" ]; then
        # Process each root path
        while IFS= read -r line; do
            # Extract the path part between quotes after "root" : "
            local path=$(echo "$line" | sed 's/.*"root"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/')
            
            # Extract the share folder name (everything after /volumeX/)
            # Pattern: /volume1/sharename or /volume2/sharename -> sharename
            local folder_name=$(echo "$path" | sed 's|^/volume[0-9]*/\([^/]*\).*|\1|')
            
            # Check if the extracted folder name matches the input parameter
            if [ "$folder_name" = "$share_name" ]; then
                return 0  # Found a match, share is being used
            fi
        done <<< "$root_paths"
    fi
    
    return 1  # Share is not being used by web services
}

# Main logic
if [ "$2" == "tiering_bucket" ]; then
    # Original hard-coded check for web and web_packages
    if [ "$1" == "web" ] || [ "$1" == "web_packages" ]; then
        exit 1
    fi
    
    # Check for any share folder
    if check_web_service_usage "$1"; then
        # Share is being used by web services, prevent tiering
        exit 1
    fi
fi

exit 0