From a403bd3e0d8105e7eec1827c7ac30d896716fef5 Mon Sep 17 00:00:00 2001 From: "Andre Moreira Magalhaes (andrunko)" <andre.magalhaes@collabora.co.uk> Date: Thu, 29 Nov 2018 01:20:05 +0000 Subject: [PATCH] Fix script to remove some bashisms Signed-off-by: Andre Moreira Magalhaes (andrunko) <andre.magalhaes@collabora.co.uk> --- run-test.sh | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/run-test.sh b/run-test.sh index c393b28..1a5431f 100755 --- a/run-test.sh +++ b/run-test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # vim: set sts=4 sw=4 et tw=0 : set -e @@ -43,23 +43,23 @@ _kill_monitor_return() { return $1 } -bash_arrays_to_gvariant_as() { +stringlist_to_gvariant_as() { local i converted="['$1'" shift - for i in "$@"; do - converted+=", '$i'" + for i in $@; do + converted="$converted, '$i'" done - converted+="]" + converted="$converted]" echo "${converted}" } _check_uris_have_thumbnail() { local size=$1 - local uris=$2 - for i in "${uris[@]}"; do + shift + for i in $@; do local thumb="${HOME}/.cache/thumbnails/${size}/$(echo -n "${i}" | md5sum | cut -f1 -d\ ).png" say $thumb - if [[ ! -f "${thumb}" ]]; then + if [ ! -f "${thumb}" ]; then whine "Couldn't find thumbnail $thumb, file $i didn't get thumbnailed!?" ret=1 fi @@ -74,20 +74,22 @@ _generate_thumbnails() { local size="$1" local special_dir="$2" shift 2 - files=("$@") + files=$@ logfile="${WORKDIR}/monitor-tumblerd.log" addr="org.freedesktop.thumbnails.Thumbnailer1" obj_path="/org/freedesktop/thumbnails/Thumbnailer1" method="org.freedesktop.thumbnails.Thumbnailer1.Queue" - uris=() - filetypes=() + uris="" + 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 # apertis-tests directory if we're running uninstalled. Copy the # file to a more realistic location, which exercises the AppArmor # 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")" else copy="$HOME/$special_dir/apertis-tests__$(basename "$i")" @@ -96,9 +98,8 @@ _generate_thumbnails() { cp -v "$i" "$copy" # Need path relative to / - # FIXME: This doesn't do whitespace/special character escaping, etc - uris+=("file://$copy") - filetypes+=($(file --mime-type "$copy" | cut -d ":" -f 2 | tr -d ' ')) + uris="${uris} file://$copy" + filetypes="${filetypes} $(file --mime-type "$copy" | cut -d ":" -f 2 | tr -d ' ')" done # Clear out old thumbnails. @@ -109,8 +110,8 @@ _generate_thumbnails() { # Files to thumbnail ${GDBUS} call --session --dest "${addr}" --object-path "${obj_path}" \ --method "${method}" \ - "$(bash_arrays_to_gvariant_as "${uris[@]}")" \ - "$(bash_arrays_to_gvariant_as "${filetypes[@]}")" \ + "$(stringlist_to_gvariant_as ${uris})" \ + "$(stringlist_to_gvariant_as ${filetypes})" \ "${size}" foreground 0 # Wait for thumbnailing to finish -- GitLab