From http://www.jwz.org/xscreensaver/xscreensaver-5.36.tar.gz
[xscreensaver] / OSX / installer.sh
1 #!/bin/sh
2 # XScreenSaver, Copyright © 2013-2016 Jamie Zawinski <jwz@jwz.org>
3 #
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation.  No representations are made about the suitability of this
9 # software for any purpose.  It is provided "as is" without express or 
10 # implied warranty.
11 #
12 # The guts of the installer.  Copies the screen savers out of the adjacent
13 # "Screen Savers" directory and into "/Library/Screen Savers/".  We do it
14 # this way instead of just including the screen savers in the package
15 # because that would double the size of the DMG.
16 #
17 # Created: 27-Jul-2013.
18
19 #exec >/tmp/xscreensaver.log 2>&1
20 #set -x
21
22 DEBUG=0
23 REQUIRED_SPACE=160      # MB. Highly approximate.
24
25 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"
26
27 function error() {
28   echo "XScreenSaver Installer: Error: $@" >&2
29
30   # Using "System Events" says "No user interaction allowed" on 10.9.
31   # But using "SystemUIServer" or "Automator Runner" still seems to work.
32   #
33   runner="System Events"
34   if [ -d "/System/Library/CoreServices/SystemUIServer.app" ]; then
35     runner="SystemUIServer"
36   elif [ -d "/System/Library/CoreServices/Automator Runner.app" ]; then
37     runner="Automator Runner"
38   fi
39
40   (
41     osascript <<__EOF__
42       tell app "$runner" to \
43         display dialog "$@" \
44         buttons "Bummer" \
45         default button 1 \
46         with icon 0 \
47         with title "Installation Error"
48 __EOF__
49   ) </dev/null >/dev/null 2>&1 &
50   exit 1
51 }
52
53
54 #if[ x"$DSTVOLUME"    = x ]; then error "DSTVOLUME unset";    fi
55 if [ x"$PACKAGE_PATH" = x ]; then error "PACKAGE_PATH unset"; fi
56 if [ x"$HOME"         = x ]; then error "HOME unset";         fi
57
58
59 echo "Destination: $DSTVOLUME" >&2
60
61 if [ x"$USER" = xjwz ]; then DEBUG=1; fi
62
63 if [ "$DEBUG" != 0 ]; then DSTVOLUME=/tmp; fi
64
65 SRC=`dirname "$PACKAGE_PATH"`/"Screen Savers"
66 DST1="$DSTVOLUME/Library/Screen Savers"
67 DST2="$DSTVOLUME/Applications"
68 PU="$DSTVOLUME/$HOME/Library/Screen Savers"
69
70 # Because of Sparkle.framework weirdness, "XScreenSaverUpdater.app" is
71 # in the DMG as a compressed tar file instead of an app, and we unpack
72 # it when installing.  Without this, auto-updates won't work: If there's
73 # an .app there, Sparkle thinks that "XScreenSaverUpdater.app" is the
74 # thing it should be updating instead of "Install Everything.pkg".
75 #
76 UPDATER_SRC="XScreenSaver.updater"
77 UPDATER_DST="XScreenSaverUpdater.app"
78
79
80 cd "$SRC" || error "The 'Screen Savers' folder does not exist.
81
82 You can't copy the installer out of the Disk Image!"
83
84
85 free=`df -k "$DSTVOLUME" |
86      tail -1 | head -1 | awk '{print $4}'`
87 need=`echo $REQUIRED_SPACE \* 1024 | bc`
88 if [ "$free" -lt "$need" ]; then
89  free=`echo $free / 1024 | bc`
90  error "Not enough disk space: $free MB available, $REQUIRED_SPACE MB required."
91 fi
92
93
94 mkdir -p "$DST1" || error "Unable to create directory $DST1/"
95 mkdir -p "$DST2" || error "Unable to create directory $DST2/"
96
97 # Install the savers and the updater in /System/Library/Screen Savers/
98 # Install the other apps in /Applications/
99 #
100 for f in *.{saver,app} "$UPDATER_SRC" ; do
101   EXT=`echo "$f" | sed 's/^.*\.//'`
102   if [ "$f" = "$UPDATER_SRC" ]; then
103     DST="$DST1"
104   elif [ "$EXT" = "app" ]; then
105     DST="$DST2"
106   else
107     DST="$DST1"
108   fi
109
110   DD="$DST/$f"
111
112   echo "Installing $DD" >&2
113   rm -rf "$DD" || error "Unable to delete $DD"
114
115   if [ "$f" = "$UPDATER_SRC" ]; then
116     ( cd "$DST/" && tar -xzf - ) < "$f" || error "Unable to unpack $f in $DST/"
117   else
118     cp -pR "$f" "$DD" || error "Unable to install $f in $DST/"
119   fi
120
121   # Eliminate the "this was downloaded from the interweb" warning.
122   xattr -r -d com.apple.quarantine "$DD"
123
124   if [ "$EXT" = "app" ]; then
125     # Eliminate the "this is from an unknown developer" warning.
126     spctl --add "$DD"
127   fi
128
129   # If this saver or app is also installed in the per-user directory,
130   # delete that copy so that we don't have conflicts.
131   #
132   if [ "$DEBUG" = 0 ]; then
133     rm -rf "$PU/$f"
134   fi
135 done
136
137 # Launch System Preferences with the Screen Saver pane selected.
138 #
139 open /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane &
140
141 exit 0