AtOM/lib/destinations/updateMimes

59 lines
1.8 KiB
Bash

#!/bin/bash
# Copyright © 2012-2026 ScriptFanix
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# A copy of the GNU General Public License v3 is includded in the LICENSE file
# at the root of the project.
updateMimes() {
# Reset all mime_actions to action=1 (transcode) as the default
Update mime_actions action 1 <<<"action != 1"
# For each destination's skip patterns, set action=0 (exclude from
# processing)
# Multiple patterns are pipe-separated; split by setting IFS='|'
for destination in ${!destinationskipmime[@]}
do
IFS='|'
for mime_type in ${destinationskipmime["$destination"]}
do
IFS="$oldIFS"
# Convert config wildcard '*' to SQL wildcard '%'
Update mime_type_actions action 0 >/dev/null < <(
cat <<-EOWhere
destination_id = ${destinationid["$destination"]}
mime_text LIKE ${mime_type//\*/%}
EOWhere
)
done
done
# For each destination's copy-mime patterns, set action=2 (copy
# verbatim)
# Multiple patterns are pipe-separated; split by setting IFS='|'
for destination in ${!destinationcopymime[@]}
do
IFS='|'
for mime_type in ${destinationcopymime["$destination"]}
do
IFS="$oldIFS"
# Convert config wildcard '*' to SQL wildcard '%'
Update mime_type_actions action 2 >/dev/null < <(
cat <<-EOWhere
destination_id = ${destinationid["$destination"]}
mime_text LIKE ${mime_type//\*/%}
EOWhere
)
done
done
IFS="$oldIFS"
}