made tomcat extension parsing in-line with upcoming release of rust rewrite
This commit is contained in:
parent
494d9ad140
commit
265a1b9b95
38
xdg-sanity
38
xdg-sanity
@ -20,6 +20,19 @@ set -e
|
|||||||
|
|
||||||
argv0="$0"
|
argv0="$0"
|
||||||
|
|
||||||
|
get_urls() {
|
||||||
|
i="0"
|
||||||
|
until ! tomcat replace.urls["$i"] "$file" >/dev/null 2>&1
|
||||||
|
do
|
||||||
|
URLS="$(printf "%s\n%s" \
|
||||||
|
"$URLS" \
|
||||||
|
"$(tomcat replace.urls["$i"] "$file")"
|
||||||
|
)"
|
||||||
|
|
||||||
|
i="$(printf "%s+1\n" "$i" | bc)"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# check if usage is valid
|
# check if usage is valid
|
||||||
if test -z "$1"; then
|
if test -z "$1"; then
|
||||||
printf "Usage: %s [resource...]\n" "$argv0" 1>&2
|
printf "Usage: %s [resource...]\n" "$argv0" 1>&2
|
||||||
@ -28,8 +41,7 @@ fi
|
|||||||
|
|
||||||
for dep in \
|
for dep in \
|
||||||
curl \
|
curl \
|
||||||
handlr \
|
handlr
|
||||||
tomcat
|
|
||||||
do
|
do
|
||||||
if ! command -v "$dep" >/dev/null 2>&1; then
|
if ! command -v "$dep" >/dev/null 2>&1; then
|
||||||
printf "%s: Missing dependency: %s(1)\n" "$argv0" "$dep" 1>&2
|
printf "%s: Missing dependency: %s(1)\n" "$argv0" "$dep" 1>&2
|
||||||
@ -46,9 +58,8 @@ fi
|
|||||||
while test -n "$1"; do
|
while test -n "$1"; do
|
||||||
URL="$1"
|
URL="$1"
|
||||||
|
|
||||||
# use curl(1) to write out the request header's content_type,
|
# use curl(1) to write out the request header's content_type, strip everything
|
||||||
# strip everything after the first semicolon,
|
# after the first semicolon, chop off any weird whitespace remnants
|
||||||
# chop off any weird whitespace remnants
|
|
||||||
MIME="$(curl -Ls -o /dev/null -w '%{content_type}' "$1" | sed 's/\;.*//' \
|
MIME="$(curl -Ls -o /dev/null -w '%{content_type}' "$1" | sed 's/\;.*//' \
|
||||||
| xargs echo)"
|
| xargs echo)"
|
||||||
|
|
||||||
@ -56,6 +67,8 @@ while test -n "$1"; do
|
|||||||
MATCH="$(printf "%s\n" "$URL" | sed -ne 's/^h.\+\/\///p' \
|
MATCH="$(printf "%s\n" "$URL" | sed -ne 's/^h.\+\/\///p' \
|
||||||
| sed -e 's/\/.*\+//g')"
|
| sed -e 's/\/.*\+//g')"
|
||||||
|
|
||||||
|
# only check for extensions if tomcat(1) is installed
|
||||||
|
if command -v tomcat >/dev/null 2>&1; then
|
||||||
# run through MIME extensions
|
# run through MIME extensions
|
||||||
for file in \
|
for file in \
|
||||||
"$XDG_DATA_HOME"/xdg-sanity/*-mime.toml \
|
"$XDG_DATA_HOME"/xdg-sanity/*-mime.toml \
|
||||||
@ -63,12 +76,11 @@ while test -n "$1"; do
|
|||||||
/usr/local/share/xdg-sanity/*-mime.toml
|
/usr/local/share/xdg-sanity/*-mime.toml
|
||||||
do
|
do
|
||||||
if test -e "$file"; then
|
if test -e "$file"; then
|
||||||
i=$(tomcat replace.urls "$file" | sed 's/ /\n/g' | wc -l)
|
get_urls
|
||||||
while ! [ "$i" = 0 ]; do
|
for url in $URLS; do
|
||||||
if [ "$MATCH" = "$(tomcat replace.urls["$i"] "$file")" ]; then
|
if [ "$MATCH" = "$url" ]; then
|
||||||
MIME="$(tomcat with.mime "$file")"
|
MIME="$(tomcat with.mime "$file")"
|
||||||
fi
|
fi
|
||||||
i="$(printf "%s-1\n" "$i" | bc)"
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -80,15 +92,15 @@ while test -n "$1"; do
|
|||||||
/usr/local/share/xdg-sanity/*-replace.toml
|
/usr/local/share/xdg-sanity/*-replace.toml
|
||||||
do
|
do
|
||||||
if test -e "$file"; then
|
if test -e "$file"; then
|
||||||
i="$(tomcat replace.urls "$file" | sed 's/ /\n/g' | wc -l)"
|
get_urls
|
||||||
while ! [ "$i" = 0 ]; do
|
for url in $URLS; do
|
||||||
if [ "$MATCH" = "$(tomcat replace.urls["$i"] "$file")" ]; then
|
if [ "$MATCH" = "$url" ]; then
|
||||||
URL="$(tomcat with.url "$file")"
|
URL="$(tomcat with.url "$file")"
|
||||||
fi
|
fi
|
||||||
i="$(printf "%s-1\n" "$i" | bc)"
|
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# these commands may fail; this is intentional
|
# these commands may fail; this is intentional
|
||||||
if [ "$MIME" = "text/html" ]; then
|
if [ "$MIME" = "text/html" ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user