Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·49 lines (41 loc) · 1.9 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·49 lines (41 loc) · 1.9 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
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
set -eu
# Installs the daily-use copy of zbar, separate from build/zbar.app. A rebuild
# empties build/zbar.app/Contents, so launching or pointing Login Items at the
# build output breaks them mid-build.
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
SOURCE="$ROOT/build/zbar.app"
DEST=${ZBAR_INSTALL_PATH:-/Applications/zbar.app}
LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister
"$ROOT/build-app.sh"
# No launch smoke test: a second zbar would fight the running one for the
# global hotkeys. A build that fails to sign or verify is not installed.
codesign --verify --deep --strict "$SOURCE"
PARENT=$(dirname -- "$DEST")
[ -w "$PARENT" ] || { printf '%s is not writable\n' "$PARENT" >&2; exit 1; }
# Contents is staged beside the target and swapped in, so the bundle is never
# left half-written and the .app inode that TCC grants and Login Items resolve
# through stays the same.
mkdir -p "$DEST"
STAGE="$DEST/Contents.new"
PREVIOUS="$DEST/Contents.old"
rm -rf "$STAGE" "$PREVIOUS"
cp -R "$SOURCE/Contents" "$STAGE"
if [ -d "$DEST/Contents" ]; then
mv "$DEST/Contents" "$PREVIOUS"
fi
mv "$STAGE" "$DEST/Contents"
rm -rf "$PREVIOUS"
codesign --verify --deep --strict "$DEST"
# Two bundles with the same identifier let LaunchServices resolve zbar to the
# build copy, which is missing during a rebuild. Only the installed copy stays
# registered; launching build/zbar.app re-registers it, so rerun this script
# after doing that.
"$LSREGISTER" -u "$SOURCE" >/dev/null 2>&1 || true
"$LSREGISTER" -f "$DEST"
if pgrep -f "$SOURCE/Contents/MacOS/zbar" >/dev/null 2>&1; then
printf 'note: zbar is running from %s; quit it and run: open "%s"\n' "$SOURCE" "$DEST" >&2
elif pgrep -f "$DEST/Contents/MacOS/zbar" >/dev/null 2>&1; then
printf 'note: a running zbar keeps the previous binary until you quit and relaunch it\n' >&2
fi
printf '%s\n' "$DEST"