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