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