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