From http://www.jwz.org/xscreensaver/xscreensaver-5.36.tar.gz
[xscreensaver] / OSX / installer.sh
index 120dd9d9b8bed3aa76d89da48b0afe36103a0c9d..fa92beb3a962e2ef84cb36da926d478e163aef3e 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-# XScreenSaver, Copyright © 2013-2014 Jamie Zawinski <jwz@jwz.org>
+# XScreenSaver, Copyright © 2013-2016 Jamie Zawinski <jwz@jwz.org>
 #
 # Permission to use, copy, modify, distribute, and sell this software and its
 # documentation for any purpose is hereby granted without fee, provided that
@@ -26,11 +26,20 @@ export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"
 
 function error() {
   echo "XScreenSaver Installer: Error: $@" >&2
+
+  # Using "System Events" says "No user interaction allowed" on 10.9.
+  # But using "SystemUIServer" or "Automator Runner" still seems to work.
+  #
+  runner="System Events"
+  if [ -d "/System/Library/CoreServices/SystemUIServer.app" ]; then
+    runner="SystemUIServer"
+  elif [ -d "/System/Library/CoreServices/Automator Runner.app" ]; then
+    runner="Automator Runner"
+  fi
+
   (
-    # Using "System Events" says "No user interaction allowed" on 10.9.
-    # But using "Automator Runner" still seems to work.
     osascript <<__EOF__
-      tell app "Automator Runner" to \
+      tell app "$runner" to \
         display dialog "$@" \
         buttons "Bummer" \
         default button 1 \
@@ -41,6 +50,7 @@ __EOF__
   exit 1
 }
 
+
 #if[ x"$DSTVOLUME"    = x ]; then error "DSTVOLUME unset";    fi
 if [ x"$PACKAGE_PATH" = x ]; then error "PACKAGE_PATH unset"; fi
 if [ x"$HOME"         = x ]; then error "HOME unset";         fi
@@ -56,7 +66,16 @@ SRC=`dirname "$PACKAGE_PATH"`/"Screen Savers"
 DST1="$DSTVOLUME/Library/Screen Savers"
 DST2="$DSTVOLUME/Applications"
 PU="$DSTVOLUME/$HOME/Library/Screen Savers"
-UPDATER="XScreenSaverUpdater.app"
+
+# Because of Sparkle.framework weirdness, "XScreenSaverUpdater.app" is
+# in the DMG as a compressed tar file instead of an app, and we unpack
+# it when installing.  Without this, auto-updates won't work: If there's
+# an .app there, Sparkle thinks that "XScreenSaverUpdater.app" is the
+# thing it should be updating instead of "Install Everything.pkg".
+#
+UPDATER_SRC="XScreenSaver.updater"
+UPDATER_DST="XScreenSaverUpdater.app"
+
 
 cd "$SRC" || error "The 'Screen Savers' folder does not exist.
 
@@ -78,17 +97,26 @@ mkdir -p "$DST2" || error "Unable to create directory $DST2/"
 # Install the savers and the updater in /System/Library/Screen Savers/
 # Install the other apps in /Applications/
 #
-for f in *.{saver,app} ; do
+for f in *.{saver,app} "$UPDATER_SRC" ; do
   EXT=`echo "$f" | sed 's/^.*\.//'`
-  if [ "$EXT" = "app" -a "$f" != "$UPDATER" ]; then
+  if [ "$f" = "$UPDATER_SRC" ]; then
+    DST="$DST1"
+  elif [ "$EXT" = "app" ]; then
     DST="$DST2"
   else
     DST="$DST1"
   fi
+
   DD="$DST/$f"
+
   echo "Installing $DD" >&2
   rm -rf "$DD" || error "Unable to delete $DD"
-  cp -pR "$f" "$DST/" || error "Unable to install $f in $DST/"
+
+  if [ "$f" = "$UPDATER_SRC" ]; then
+    ( cd "$DST/" && tar -xzf - ) < "$f" || error "Unable to unpack $f in $DST/"
+  else
+    cp -pR "$f" "$DD" || error "Unable to install $f in $DST/"
+  fi
 
   # Eliminate the "this was downloaded from the interweb" warning.
   xattr -r -d com.apple.quarantine "$DD"