Skip to content

Commit a567b07

Browse files
author
Alex Wilson
committed
OSX package scripts and Makefile target
1 parent fb28d42 commit a567b07

File tree

6 files changed

+115
-5
lines changed

6 files changed

+115
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/pivy-tool
66
/pivy-zfs
77
/pivy-box
8+
/macosx/*.pkg
9+
/macosx/root

Makefile

+25-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ CURL = curl -k
1515
prefix ?= /opt/pivy
1616
bindir ?= $(prefix)/bin
1717

18+
VERSION = 0.1.4
19+
1820
SYSTEM := $(shell uname -s)
1921
ifeq ($(SYSTEM), Linux)
2022
PCSC_CFLAGS = $(shell pkg-config --cflags libpcsclite)
@@ -288,9 +290,10 @@ pivy-agent: $(AGENT_OBJS) $(LIBRESSL_LIB)/libcrypto.a
288290
clean:
289291
rm -f pivy-tool $(PIVTOOL_OBJS)
290292
rm -f pivy-agent $(AGENT_OBJS)
291-
rm -f piv-zfs $(PIVZFS_OBJS)
292-
rm -f ebox $(EBOX_OBJS)
293+
rm -f pivy-box $(EBOX_OBJS)
294+
rm -f pivy-zfs $(PIVZFS_OBJS)
293295
rm -fr .dist
296+
rm -fr macosx/root macosx/*.pkg
294297

295298
distclean: clean
296299
rm -fr libressl
@@ -318,6 +321,26 @@ install_common: pivy-tool pivy-agent pivy-box
318321

319322
ifeq ($(SYSTEM), Darwin)
320323
install: install_common
324+
install -o root -g wheel -m 0755 -d $(DESTDIR)/etc/paths.d
325+
echo "$(bindir)" > $(DESTDIR)/etc/paths.d/pivy
326+
install -o root -g wheel -m 0755 -d $(DESTDIR)$(prefix)/share
327+
install -o root -g wheel -m 0644 macosx/net.cooperi.pivy-agent.plist \
328+
$(DESTDIR)$(prefix)/share
329+
330+
.PHONY: package
331+
package:
332+
$(MAKE) install DESTDIR=macosx/root/ prefix=/opt/pivy
333+
pkgbuild --root macosx/root \
334+
--identifier net.cooperi.pivy \
335+
--version $(VERSION) \
336+
--ownership recommended \
337+
--scripts macosx/scripts \
338+
macosx/output.pkg
339+
productbuild --distribution macosx/distribution.xml \
340+
--resources macosx/resources \
341+
--package-path macosx \
342+
--version $(VERSION) \
343+
macosx/pivy-$(VERSION).pkg
321344

322345
.dist/net.cooperi.pivy-agent.plist: net.cooperi.pivy-agent.plist .dist pivy-tool
323346
@./pivy-tool list

macosx/distribution.xml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0"?>
2+
<installer-gui-script minSpecVersion="1">
3+
<title>pivy</title>
4+
<organization>org.someid</organization>
5+
<domains enable_localSystem="true"/>
6+
<options customize="never" require-scripts="true" rootVolumeOnly="true" />
7+
<!-- Define documents displayed at various steps -->
8+
<welcome file="welcome.html" mime-type="text/html" />
9+
<license file="license.html" mime-type="text/html" />
10+
<conclusion file="conclusion.html" mime-type="text/html" />
11+
<!-- List all component packages -->
12+
<pkg-ref id="net.cooperi.pivy"
13+
version="0"
14+
auth="root">output.pkg</pkg-ref>
15+
<!-- List them again here. They can now be organized
16+
as a hierarchy if you want. -->
17+
<choices-outline>
18+
<line choice="net.cooperi.pivy"/>
19+
</choices-outline>
20+
<!-- Define each choice above -->
21+
<choice
22+
id="net.cooperi.pivy"
23+
visible="false"
24+
title="pivy tools"
25+
description="pivy tools"
26+
start_selected="true">
27+
<pkg-ref id="net.cooperi.pivy"/>
28+
</choice>
29+
</installer-gui-script>

net.cooperi.pivy-agent.plist macosx/net.cooperi.pivy-agent.plist

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
<string>@@GUID@@</string>
1212
<string>-K</string>
1313
<string>@@CAK@@</string>
14+
<string>-i</string>
15+
<string>-a</string>
16+
<string>@@HOME@@/.ssh/pivy-agent.sock</string>
1417
</array>
15-
<key>StandardOutPath</key>
16-
<string>@@HOME@@/.ssh/agent.env</string>
1718
<key>StandardErrorPath</key>
18-
<string>@@HOME@@/.ssh/agent.out</string>
19+
<string>@@HOME@@/Library/Logs/pivy-agent.log</string>
1920
<key>RunAtLoad</key>
2021
<true/>
2122
<key>KeepAlive</key>

macosx/scripts/postinstall

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
set -ex
3+
user="$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')"
4+
HOME="/Users/${user}"
5+
uagents="$HOME/Library/LaunchAgents"
6+
plist="net.cooperi.pivy-agent.plist"
7+
prefix="/opt/pivy"
8+
bindir="$prefix/bin"
9+
10+
while true; do
11+
/usr/bin/osascript -e 'display dialog "Please insert your YubiKey and press OK"'
12+
13+
# XXX: we just take the first one we see?
14+
while IFS=: read rdrname guid chuid ykpiv; do
15+
# check it's been set up with a CHUID
16+
if [[ "$chuid" == "false" && "$ykpiv" == "true" ]]; then
17+
# if it hasn't set up a basic one + 9e key so we can pin it.
18+
# the user can do the rest with pivy-tool later.
19+
$bindir/pivy-tool -g $guid init
20+
# "init" changes the guid
21+
guid=$($bindir/pivy-tool list -p | \
22+
/usr/bin/grep "$rdrname" | /usr/bin/awk -F: '{print $2}')
23+
$bindir/pivy-tool -g $guid -a eccp256 generate 9e
24+
fi
25+
cak="$($bindir/pivy-tool -g $guid pubkey 9e)"
26+
27+
/usr/bin/su "${user}" -c "/bin/mkdir -p \"${uagents}\""
28+
# substitute placeholders in the plist
29+
/bin/cat /opt/pivy/share/net.cooperi.pivy-agent.plist | \
30+
/usr/bin/sed -e "s|@@GUID@@|${guid}|g" -e "s|@@CAK@@|${cak}|g" \
31+
-e "s|@@HOME@@|${HOME}|g" \
32+
> "${uagents}/${plist}"
33+
chown "${user}" "${uagents}/${plist}"
34+
35+
/usr/bin/su "${user}" -c "/bin/launchctl load \"${uagents}/${plist}\""
36+
37+
if ! /usr/bin/grep pivy-agent /etc/profile >/dev/null 2>/dev/null; then
38+
echo '# pivy-agent' >> /etc/profile
39+
echo 'if [[ ! -e "$SSH_AUTH_SOCK" || "$SSH_AUTH_SOCK" == *"launchd"* ]]; then' >> /etc/profile
40+
echo ' SSH_AUTH_SOCK=$HOME/.ssh/pivy-agent.sock; export SSH_AUTH_SOCK;' >>/etc/profile
41+
echo 'fi' >>/etc/profile
42+
fi
43+
exit 0
44+
done < <($bindir/pivy-tool -p list)
45+
done

macosx/scripts/preinstall

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -ex
3+
user="$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')"
4+
HOME="/Users/${user}"
5+
uagents="$HOME/Library/LaunchAgents"
6+
plist="net.cooperi.pivy-agent.plist"
7+
8+
if /usr/bin/su "$user" -c "/bin/launchctl list \"net.cooperi.pivy-agent\"" > /dev/null; then
9+
/usr/bin/su "$user" -c "/bin/launchctl unload \"$uagents/$plist\""
10+
fi

0 commit comments

Comments
 (0)