summaryrefslogtreecommitdiffstats
path: root/OSX/installer.sh
blob: fa92beb3a962e2ef84cb36da926d478e163aef3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
# XScreenSaver, Copyright © 2013-2016 Jamie Zawinski <jwz@jwz.org>
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation.  No representations are made about the suitability of this
# software for any purpose.  It is provided "as is" without express or 
# implied warranty.
#
# The guts of the installer.  Copies the screen savers out of the adjacent
# "Screen Savers" directory and into "/Library/Screen Savers/".  We do it
# this way instead of just including the screen savers in the package
# because that would double the size of the DMG.
#
# Created: 27-Jul-2013.

#exec >/tmp/xscreensaver.log 2>&1
#set -x

DEBUG=0
REQUIRED_SPACE=160	# MB. Highly approximate.

export PATH="/bin:/sbin:/usr/bin:/usr/sbin:$PATH"

function error() {
  echo "XScreenSaver Installer: Error: $@" >&2

  # Using "System Events" says "No user interaction allowed" on 10.9.
  # But using "SystemUIServer" or "Automator Runner" still seems to work.
  #
  runner="System Events"
  if [ -d "/System/Library/CoreServices/SystemUIServer.app" ]; then
    runner="SystemUIServer"
  elif [ -d "/System/Library/CoreServices/Automator Runner.app" ]; then
    runner="Automator Runner"
  fi

  (
    osascript <<__EOF__
      tell app "$runner" to \
        display dialog "$@" \
        buttons "Bummer" \
        default button 1 \
        with icon 0 \
        with title "Installation Error"
__EOF__
  ) </dev/null >/dev/null 2>&1 &
  exit 1
}


#if[ x"$DSTVOLUME"    = x ]; then error "DSTVOLUME unset";    fi
if [ x"$PACKAGE_PATH" = x ]; then error "PACKAGE_PATH unset"; fi
if [ x"$HOME"         = x ]; then error "HOME unset";         fi


echo "Destination: $DSTVOLUME" >&2

if [ x"$USER" = xjwz ]; then DEBUG=1; fi

if [ "$DEBUG" != 0 ]; then DSTVOLUME=/tmp; fi

SRC=`dirname "$PACKAGE_PATH"`/"Screen Savers"
DST1="$DSTVOLUME/Library/Screen Savers"
DST2="$DSTVOLUME/Applications"
PU="$DSTVOLUME/$HOME/Library/Screen Savers"

# Because of Sparkle.framework weirdness, "XScreenSaverUpdater.app" is
# in the DMG as a compressed tar file instead of an app, and we unpack
# it when installing.  Without this, auto-updates won't work: If there's
# an .app there, Sparkle thinks that "XScreenSaverUpdater.app" is the
# thing it should be updating instead of "Install Everything.pkg".
#
UPDATER_SRC="XScreenSaver.updater"
UPDATER_DST="XScreenSaverUpdater.app"


cd "$SRC" || error "The 'Screen Savers' folder does not exist.

You can't copy the installer out of the Disk Image!"


free=`df -k "$DSTVOLUME" |
     tail -1 | head -1 | awk '{print $4}'`
need=`echo $REQUIRED_SPACE \* 1024 | bc`
if [ "$free" -lt "$need" ]; then
 free=`echo $free / 1024 | bc`
 error "Not enough disk space: $free MB available, $REQUIRED_SPACE MB required."
fi


mkdir -p "$DST1" || error "Unable to create directory $DST1/"
mkdir -p "$DST2" || error "Unable to create directory $DST2/"

# Install the savers and the updater in /System/Library/Screen Savers/
# Install the other apps in /Applications/
#
for f in *.{saver,app} "$UPDATER_SRC" ; do
  EXT=`echo "$f" | sed 's/^.*\.//'`
  if [ "$f" = "$UPDATER_SRC" ]; then
    DST="$DST1"
  elif [ "$EXT" = "app" ]; then
    DST="$DST2"
  else
    DST="$DST1"
  fi

  DD="$DST/$f"

  echo "Installing $DD" >&2
  rm -rf "$DD" || error "Unable to delete $DD"

  if [ "$f" = "$UPDATER_SRC" ]; then
    ( cd "$DST/" && tar -xzf - ) < "$f" || error "Unable to unpack $f in $DST/"
  else
    cp -pR "$f" "$DD" || error "Unable to install $f in $DST/"
  fi

  # Eliminate the "this was downloaded from the interweb" warning.
  xattr -r -d com.apple.quarantine "$DD"

  if [ "$EXT" = "app" ]; then
    # Eliminate the "this is from an unknown developer" warning.
    spctl --add "$DD"
  fi

  # If this saver or app is also installed in the per-user directory,
  # delete that copy so that we don't have conflicts.
  #
  if [ "$DEBUG" = 0 ]; then
    rm -rf "$PU/$f"
  fi
done

# Launch System Preferences with the Screen Saver pane selected.
#
open /System/Library/PreferencePanes/DesktopScreenEffectsPref.prefPane &

exit 0