From f04a485b48efc8f3a0ccd3c8b4f22625e4fdfd7a Mon Sep 17 00:00:00 2001 From: Daniele Cattaneo Date: Tue, 22 Jan 2019 00:40:13 +0100 Subject: [PATCH] Update the postinstall script for the Spotlight plugin to work properly when installing for a single user. --- .../PackageResources/Scripts/postinstall | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/WindowsAppsImporter/PackageResources/Scripts/postinstall b/WindowsAppsImporter/PackageResources/Scripts/postinstall index d0fbd1e..e227d6f 100755 --- a/WindowsAppsImporter/PackageResources/Scripts/postinstall +++ b/WindowsAppsImporter/PackageResources/Scripts/postinstall @@ -1,10 +1,18 @@ #!/bin/bash -x +whoami macosv=($(sw_vers -productVersion | sed 's/\./ /g')) echo macos version ${macosv[*]} if [[ ${macosv[1]} -gt 12 ]]; then com='/usr/bin/mdutil -r ' + run_as_root=1 else com='/usr/bin/mdimport -d3 -r ' -fi; -su $USER -c "${com}$2/Library/Spotlight/WindowsAppsImporter.mdimporter; echo returned \$?"; + run_as_root=0 +fi +if [[ ( "$EUID" -eq 0 ) && ( "$run_as_root" -eq 0 ) ]]; then + su $USER -c "${com}$2/Library/Spotlight/WindowsAppsImporter.mdimporter; echo returned \$?"; +else + ${com}$2/Library/Spotlight/WindowsAppsImporter.mdimporter + echo returned $?; +fi exit 0