-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·51 lines (42 loc) · 1.14 KB
/
build.sh
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
#!/usr/bin/env bash
set -u
PROJECT=logind
IDENTIFIER=com.doggles.$PROJECT
ROOT_DIR=$(dirname "$0")
# check if run.sh and plist are in folder
if [ ! -f "$ROOT_DIR"/$IDENTIFIER.plist ] || [ ! -f "$ROOT_DIR"/run.sh ]; then
echo "Required files not found"
exit 99
fi
# remove .build/ if exists
[ -d "$ROOT_DIR"/.build ] && rm -rf "${ROOT_DIR:?}"/.build
# create pkgbuild staging dirs
mkdir -p \
"$ROOT_DIR"/.build/ROOT/Library/LaunchDaemons \
"$ROOT_DIR"/.build/ROOT/usr/local/$PROJECT \
"$ROOT_DIR"/.build/scripts
# copy plist
cp \
"$ROOT_DIR"/$IDENTIFIER.plist \
"$ROOT_DIR"/.build/ROOT/Library/LaunchDaemons
# copy script
cp \
"$ROOT_DIR"/run.sh \
"$ROOT_DIR"/.build/ROOT/usr/local/$PROJECT
# create postinstall
cat > "$ROOT_DIR"/.build/scripts/postinstall <<SCRIPT
#!/usr/bin/env bash
chmod +x /usr/local/$PROJECT/run.sh
launchctl load -w /Library/LaunchDaemons/$IDENTIFIER.plist
SCRIPT
# build package
pkgbuild \
--root "$ROOT_DIR"/.build/ROOT \
--scripts "$ROOT_DIR"/.build/scripts \
--ownership recommended \
--identifier $IDENTIFIER \
"$ROOT_DIR"/$PROJECT.pkg
# cleanup
_cleanup() { rm -rf "${ROOT_DIR:?}"/.build; }
trap '_cleanup' EXIT
exit