diff options
author | Patrick Murphy <Patrick.Murphy@multitech.com> | 2020-06-10 16:30:03 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2020-06-18 20:22:08 -0500 |
commit | 01f73eaf483ea5050a26098c3eb5949275118f3c (patch) | |
tree | 1b47e66e6c832ef56bae96d9eb8bcfc960b9981d /recipes-core/lighttpd/lighttpd/lighttpd_custom_images_setup | |
parent | 21ba34aa24d4953e278dc35e010f7d9b9f6842e2 (diff) | |
download | meta-mlinux-01f73eaf483ea5050a26098c3eb5949275118f3c.tar.gz meta-mlinux-01f73eaf483ea5050a26098c3eb5949275118f3c.tar.bz2 meta-mlinux-01f73eaf483ea5050a26098c3eb5949275118f3c.zip |
recovered 1.4.48 default init script
Diffstat (limited to 'recipes-core/lighttpd/lighttpd/lighttpd_custom_images_setup')
-rw-r--r-- | recipes-core/lighttpd/lighttpd/lighttpd_custom_images_setup | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/recipes-core/lighttpd/lighttpd/lighttpd_custom_images_setup b/recipes-core/lighttpd/lighttpd/lighttpd_custom_images_setup new file mode 100644 index 0000000..ecd5f46 --- /dev/null +++ b/recipes-core/lighttpd/lighttpd/lighttpd_custom_images_setup @@ -0,0 +1,57 @@ +#!/bin/bash +# Detects mime types for UI Customization images and generates according Lighttpd config fragment + +CONFIG_PATH="/var/run/config/lighttpd_custom_images.conf" +IMAGE_PATH="/var/www/static/images/" +MAGIC_DB_PATH="/usr/share/misc/magic-images.mgc" +shopt -s nullglob + +echoerr() { + echo "$@" 1>&2 +} + +generate_mime_assign() { + local IMAGE="$1" + local OUTPUT=$(file -ib "$IMAGE" --magic-file "$MAGIC_DB_PATH") + local CONTENT_TYPE + + if [ "$?" -ne "0" ] || [[ "$OUTPUT" == "" ]] || [[ "$OUTPUT" == *"cannot open"* ]]; then + echoerr "Failed to run file(1): ${?}; ${OUTPUT}" + return 1 + fi + + CONTENT_TYPE="$OUTPUT" + cat <<END +\$HTTP["url"] =~ "/static/images/$IMAGE" { + mimetype.assign = ("" => "$CONTENT_TYPE") + } +END +} + +process_files() { + local INDENT=" " + local ELSE_STRING="" + local FRAGMENT + + for IMAGE in custom_*; do + INDENT=" " + + FRAGMENT=$(generate_mime_assign $IMAGE) + if [ "$?" -eq "0" ]; then + echo "${INDENT}${ELSE_STRING}${FRAGMENT}" >> "$CONFIG_PATH" + ELSE_STRING="else " + fi + done +} + +echo "Generating $CONFIG_PATH" + +# truncate and write head +cat > "$CONFIG_PATH" <<END +\$HTTP["url"] =~ "/static/images/custom_" { +END + +cd "$IMAGE_PATH" && process_files + +# write tail (closing brace) +echo "}" >> "$CONFIG_PATH" |