-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·36 lines (29 loc) · 1.01 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·36 lines (29 loc) · 1.01 KB
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
#!/bin/bash
# Builds the app, drops it into /Applications and launches it.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
DEST="/Applications/SleepSwitch.app"
"$ROOT/build.sh"
if pgrep -x SleepSwitch >/dev/null; then
echo "Stopping the running copy…"
pkill -x SleepSwitch || true
sleep 1
fi
# After an install from the .pkg the bundle belongs to root and a plain rm cannot
# remove it: the inner directories are root-owned and not writable. Hence sudo.
SUDO=""
if [ -e "$DEST" ] && [ ! -w "$DEST/Contents" ]; then
echo "/Applications holds a copy installed from the package (owned by root)."
echo "Replacing it needs an administrator password."
SUDO="sudo"
fi
$SUDO rm -rf "$DEST"
$SUDO cp -R "$ROOT/build/SleepSwitch.app" "$DEST"
echo "Installed: $DEST"
if [ -n "$SUDO" ]; then
# After sudo cp the bundle would stay root-only; hand it back so the next
# install needs no password.
sudo chown -R "$(id -u):$(id -g)" "$DEST"
fi
open "$DEST"
echo "The icon is now on the right-hand side of the menu bar."