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