From http://www.jwz.org/xscreensaver/xscreensaver-5.25.tar.gz
[xscreensaver] / OSX / installer.sh
1 #!/bin/sh
2 # XScreenSaver, Copyright © 2013 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 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"
23
24 REQUIRED_SPACE=140      # MB. Highly approximate.
25
26 DEBUG=0
27
28 if [ x"$USER" = xjwz ]; then
29   DEBUG=1
30 fi
31
32 echo "Destination: $DSTVOLUME" >&2
33
34 if [ "$DEBUG" != 0 ]; then
35   DSTVOLUME=/tmp
36 fi
37
38 SRC=`dirname "$PACKAGE_PATH"`/"Screen Savers"
39 DST1="$DSTVOLUME/Library/Screen Savers"
40 DST2="$DSTVOLUME/Applications"
41 PU="$DSTVOLUME/$HOME/Library/Screen Savers"
42 UPDATER="XScreenSaverUpdater.app"
43
44 function error() {
45   echo "Error: $@" >&2
46   (
47     osascript <<__EOF__
48       tell app "System Events" to display dialog "$@" buttons "Bummer" default button 1 with icon 0 with title "Installation Error"
49 __EOF__
50   ) </dev/null >/dev/null 2>&1 &
51   exit 1
52 }
53
54 cd "$SRC" || error "The 'Screen Savers' folder does not exist.
55
56 You can't copy the installer out of the Disk Image!"
57
58
59 free=`df -k "$DSTVOLUME" |
60      tail -1 | head -1 | awk '{print $4}'`
61 need=`echo $REQUIRED_SPACE \* 1024 | bc`
62 if [ "$free" -lt "$need" ]; then
63  free=`echo $free / 1024 | bc`
64  error "Not enough disk space: $free MB available, $REQUIRED_SPACE MB required."
65 fi
66
67
68 mkdir -p "$DST1" || error "Unable to create directory $DST1/"
69 mkdir -p "$DST2" || error "Unable to create directory $DST2/"
70
71 # Install the savers and the updater in /System/Library/Screen Savers/
72 # Install the other apps in /Applications/
73 #
74 for f in *.{saver,app} ; do
75   EXT=`echo "$f" | sed 's/^.*\.//'`
76   if [ "$EXT" = "app" -a "$f" != "$UPDATER" ]; then
77     DST="$DST2"
78   else
79     DST="$DST1"
80   fi
81   DD="$DST/$f"
82   echo "Installing $DD" >&2
83   rm -rf "$DD" || error "Unable to delete $DD"
84   cp -pR "$f" "$DST/" || error "Unable to install $f in $DST/"
85
86   # Eliminate the "this was downloaded from the interweb" warning.
87   xattr -r -d com.apple.quarantine "$DD"
88
89   if [ "$EXT" = "app" ]; then
90     # Eliminate the "this is from an unknown developer" warning.
91     spctl --add "$DD"
92   fi
93
94   # If this saver or app is also installed in the per-user directory,
95   # delete that copy so that we don't have conflicts.
96   #
97   if [ "$DEBUG" = 0 ]; then
98     rm -rf "$PU/$f"
99   fi
100 done
101
102 # Launch System Preferences with the Screen Saver pane selected.
103 #
104 open /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane &
105
106 exit 0