Skip to content
Snippets Groups Projects
Commit 2b713d37 authored by Frédéric Dalleau's avatar Frédéric Dalleau :sun_with_face:
Browse files

Merge branch 'wip/andrunko/T5563+18.12' into '18.12'

Fix script to remove some bashisms

See merge request !2
parents 70cc8140 c250b10f
Branches apertis/v2025pre
No related tags found
1 merge request!2Fix script to remove some bashisms
#!/bin/bash #!/bin/sh
# vim: set sts=4 sw=4 et tw=0 : # vim: set sts=4 sw=4 et tw=0 :
set -e set -e
...@@ -43,23 +43,23 @@ _kill_monitor_return() { ...@@ -43,23 +43,23 @@ _kill_monitor_return() {
return $1 return $1
} }
bash_arrays_to_gvariant_as() { stringlist_to_gvariant_as() {
local i converted="['$1'" local i converted="['$1'"
shift shift
for i in "$@"; do for i in $@; do
converted+=", '$i'" converted="$converted, '$i'"
done done
converted+="]" converted="$converted]"
echo "${converted}" echo "${converted}"
} }
_check_uris_have_thumbnail() { _check_uris_have_thumbnail() {
local size=$1 local size=$1
local uris=$2 shift
for i in "${uris[@]}"; do for i in $@; do
local thumb="${HOME}/.cache/thumbnails/${size}/$(echo -n "${i}" | md5sum | cut -f1 -d\ ).png" local thumb="${HOME}/.cache/thumbnails/${size}/$(echo -n "${i}" | md5sum | cut -f1 -d\ ).png"
say $thumb say $thumb
if [[ ! -f "${thumb}" ]]; then if [ ! -f "${thumb}" ]; then
whine "Couldn't find thumbnail $thumb, file $i didn't get thumbnailed!?" whine "Couldn't find thumbnail $thumb, file $i didn't get thumbnailed!?"
ret=1 ret=1
fi fi
...@@ -74,20 +74,22 @@ _generate_thumbnails() { ...@@ -74,20 +74,22 @@ _generate_thumbnails() {
local size="$1" local size="$1"
local special_dir="$2" local special_dir="$2"
shift 2 shift 2
files=("$@") files=$@
logfile="${WORKDIR}/monitor-tumblerd.log" logfile="${WORKDIR}/monitor-tumblerd.log"
addr="org.freedesktop.thumbnails.Thumbnailer1" addr="org.freedesktop.thumbnails.Thumbnailer1"
obj_path="/org/freedesktop/thumbnails/Thumbnailer1" obj_path="/org/freedesktop/thumbnails/Thumbnailer1"
method="org.freedesktop.thumbnails.Thumbnailer1.Queue" method="org.freedesktop.thumbnails.Thumbnailer1.Queue"
uris=() uris=""
filetypes=() filetypes=""
for i in "${files[@]}"; do # FIXME: This doesn't do whitespace/special character escaping, etc
for i in ${files}; do
# Tumbler's AppArmor profile doesn't necessarily let it read the # Tumbler's AppArmor profile doesn't necessarily let it read the
# apertis-tests directory if we're running uninstalled. Copy the # apertis-tests directory if we're running uninstalled. Copy the
# file to a more realistic location, which exercises the AppArmor # file to a more realistic location, which exercises the AppArmor
# profile better anyway. # profile better anyway.
if [ $(( $RANDOM % 2 )) = 0 ] && [ -e "/home/shared/$special_dir" ]; then _rand=$(od -A n -N 2 -t u2 /dev/urandom)
if [ $(( $_rand % 2 )) = 0 ] && [ -e "/home/shared/$special_dir" ]; then
copy="/home/shared/$special_dir/apertis-tests__$(basename "$i")" copy="/home/shared/$special_dir/apertis-tests__$(basename "$i")"
else else
copy="$HOME/$special_dir/apertis-tests__$(basename "$i")" copy="$HOME/$special_dir/apertis-tests__$(basename "$i")"
...@@ -96,9 +98,8 @@ _generate_thumbnails() { ...@@ -96,9 +98,8 @@ _generate_thumbnails() {
cp -v "$i" "$copy" cp -v "$i" "$copy"
# Need path relative to / # Need path relative to /
# FIXME: This doesn't do whitespace/special character escaping, etc uris="${uris} file://$copy"
uris+=("file://$copy") filetypes="${filetypes} $(file --mime-type "$copy" | cut -d ":" -f 2 | tr -d ' ')"
filetypes+=($(file --mime-type "$copy" | cut -d ":" -f 2 | tr -d ' '))
done done
# Clear out old thumbnails. # Clear out old thumbnails.
...@@ -109,8 +110,8 @@ _generate_thumbnails() { ...@@ -109,8 +110,8 @@ _generate_thumbnails() {
# Files to thumbnail # Files to thumbnail
${GDBUS} call --session --dest "${addr}" --object-path "${obj_path}" \ ${GDBUS} call --session --dest "${addr}" --object-path "${obj_path}" \
--method "${method}" \ --method "${method}" \
"$(bash_arrays_to_gvariant_as "${uris[@]}")" \ "$(stringlist_to_gvariant_as ${uris})" \
"$(bash_arrays_to_gvariant_as "${filetypes[@]}")" \ "$(stringlist_to_gvariant_as ${filetypes})" \
"${size}" foreground 0 "${size}" foreground 0
# Wait for thumbnailing to finish # Wait for thumbnailing to finish
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment