Skip to content

Commit 79d52f9

Browse files
committed
feat: install/uninstall scripts and launch plists
- launchdaemon plist: keeps tomehelper alive as root on every boot - launchagent plist: opens tome.app on login for current user - install.sh: builds both targets, installs app to /applications, helper to /library/privilegedhelpertools, loads daemon and agent - uninstall.sh: stops services, cleans /etc/hosts, removes all files
1 parent c0c3561 commit 79d52f9

4 files changed

Lines changed: 172 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>com.andrewzhou.tome</string>
7+
<key>ProgramArguments</key>
8+
<array>
9+
<string>/usr/bin/open</string>
10+
<string>-a</string>
11+
<string>/Applications/Tome.app</string>
12+
</array>
13+
<key>RunAtLoad</key>
14+
<true/>
15+
<key>KeepAlive</key>
16+
<false/>
17+
</dict>
18+
</plist>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>Label</key>
6+
<string>com.andrewzhou.tome.helper</string>
7+
<key>ProgramArguments</key>
8+
<array>
9+
<string>/Library/PrivilegedHelperTools/TomeHelper</string>
10+
</array>
11+
<key>KeepAlive</key>
12+
<true/>
13+
<key>RunAtLoad</key>
14+
<true/>
15+
<key>StandardErrorPath</key>
16+
<string>/var/log/tome-helper.log</string>
17+
<key>StandardOutPath</key>
18+
<string>/var/log/tome-helper.log</string>
19+
</dict>
20+
</plist>

scripts/install.sh

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env bash
2+
# Tome install script
3+
# Builds and installs the Tome app and its privileged helper daemon.
4+
# Usage: sudo ./scripts/install.sh
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
REPO_DIR="$(dirname "$SCRIPT_DIR")"
10+
BUILD_DIR="$REPO_DIR/build"
11+
APP_DEST="/Applications/Tome.app"
12+
HELPER_DEST="/Library/PrivilegedHelperTools/TomeHelper"
13+
DAEMON_PLIST_SRC="$REPO_DIR/launchdaemons/com.andrewzhou.tome.helper.plist"
14+
DAEMON_PLIST_DEST="/Library/LaunchDaemons/com.andrewzhou.tome.helper.plist"
15+
AGENT_PLIST_SRC="$REPO_DIR/launchagents/com.andrewzhou.tome.plist"
16+
AGENT_PLIST_DEST="$HOME/Library/LaunchAgents/com.andrewzhou.tome.plist"
17+
LOG_FILE="/var/log/tome-helper.log"
18+
SHARED_DIR="/Library/Application Support/Tome"
19+
20+
if [[ "$EUID" -ne 0 ]]; then
21+
echo "Please run as root: sudo ./scripts/install.sh"
22+
exit 1
23+
fi
24+
25+
CURRENT_USER=$(stat -f "%Su" /dev/console)
26+
echo "Installing Tome for user: $CURRENT_USER"
27+
28+
# ---------- Build ----------
29+
echo "Building..."
30+
mkdir -p "$BUILD_DIR"
31+
32+
xcodebuild \
33+
-project "$REPO_DIR/Tome.xcodeproj" \
34+
-scheme Tome \
35+
-configuration Release \
36+
-derivedDataPath "$BUILD_DIR/DerivedData" \
37+
SYMROOT="$BUILD_DIR" \
38+
build
39+
40+
xcodebuild \
41+
-project "$REPO_DIR/Tome.xcodeproj" \
42+
-scheme TomeHelper \
43+
-configuration Release \
44+
-derivedDataPath "$BUILD_DIR/DerivedData" \
45+
SYMROOT="$BUILD_DIR" \
46+
build
47+
48+
# ---------- Stop existing services ----------
49+
echo "Stopping existing services..."
50+
launchctl unload "$DAEMON_PLIST_DEST" 2>/dev/null || true
51+
sudo -u "$CURRENT_USER" launchctl unload "$AGENT_PLIST_DEST" 2>/dev/null || true
52+
killall Tome 2>/dev/null || true
53+
killall TomeHelper 2>/dev/null || true
54+
55+
# ---------- Install app ----------
56+
echo "Installing Tome.app..."
57+
rm -rf "$APP_DEST"
58+
cp -R "$BUILD_DIR/Release/Tome.app" "$APP_DEST"
59+
60+
# ---------- Install helper ----------
61+
echo "Installing TomeHelper..."
62+
mkdir -p /Library/PrivilegedHelperTools
63+
cp "$BUILD_DIR/Release/TomeHelper" "$HELPER_DEST"
64+
chmod 755 "$HELPER_DEST"
65+
chown root:wheel "$HELPER_DEST"
66+
67+
# ---------- Shared data dir ----------
68+
mkdir -p "$SHARED_DIR"
69+
chmod 777 "$SHARED_DIR"
70+
71+
# ---------- Log file ----------
72+
touch "$LOG_FILE"
73+
chmod 644 "$LOG_FILE"
74+
75+
# ---------- LaunchDaemon ----------
76+
echo "Installing LaunchDaemon..."
77+
cp "$DAEMON_PLIST_SRC" "$DAEMON_PLIST_DEST"
78+
chown root:wheel "$DAEMON_PLIST_DEST"
79+
chmod 644 "$DAEMON_PLIST_DEST"
80+
launchctl load -w "$DAEMON_PLIST_DEST"
81+
82+
# ---------- LaunchAgent (for current user) ----------
83+
echo "Installing LaunchAgent..."
84+
AGENT_DIR="$(eval echo "~$CURRENT_USER")/Library/LaunchAgents"
85+
mkdir -p "$AGENT_DIR"
86+
cp "$AGENT_PLIST_SRC" "$AGENT_DIR/com.andrewzhou.tome.plist"
87+
chown "$CURRENT_USER" "$AGENT_DIR/com.andrewzhou.tome.plist"
88+
sudo -u "$CURRENT_USER" launchctl load -w "$AGENT_DIR/com.andrewzhou.tome.plist"
89+
90+
echo ""
91+
echo "✓ Tome installed successfully."
92+
echo " App: $APP_DEST"
93+
echo " Helper: $HELPER_DEST"
94+
echo " Daemon: $DAEMON_PLIST_DEST"
95+
echo ""
96+
echo "Launching Tome..."
97+
sudo -u "$CURRENT_USER" open -a "$APP_DEST"

scripts/uninstall.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# Tome uninstall script
3+
# Usage: sudo ./scripts/uninstall.sh
4+
5+
set -e
6+
7+
if [[ "$EUID" -ne 0 ]]; then
8+
echo "Please run as root: sudo ./scripts/uninstall.sh"
9+
exit 1
10+
fi
11+
12+
CURRENT_USER=$(stat -f "%Su" /dev/console)
13+
AGENT_PLIST="$(eval echo "~$CURRENT_USER")/Library/LaunchAgents/com.andrewzhou.tome.plist"
14+
DAEMON_PLIST="/Library/LaunchDaemons/com.andrewzhou.tome.helper.plist"
15+
16+
echo "Stopping services..."
17+
launchctl unload "$DAEMON_PLIST" 2>/dev/null || true
18+
sudo -u "$CURRENT_USER" launchctl unload "$AGENT_PLIST" 2>/dev/null || true
19+
killall Tome 2>/dev/null || true
20+
killall TomeHelper 2>/dev/null || true
21+
22+
echo "Removing hosts entries..."
23+
HOSTS_FILE="/etc/hosts"
24+
TMP=$(mktemp)
25+
awk '/# tome-block-start/{skip=1} /# tome-block-end/{skip=0; next} !skip' "$HOSTS_FILE" > "$TMP"
26+
mv "$TMP" "$HOSTS_FILE"
27+
dscacheutil -flushcache
28+
killall -HUP mDNSResponder 2>/dev/null || true
29+
30+
echo "Removing files..."
31+
rm -rf /Applications/Tome.app
32+
rm -f /Library/PrivilegedHelperTools/TomeHelper
33+
rm -f "$DAEMON_PLIST"
34+
rm -f "$AGENT_PLIST"
35+
rm -rf "/Library/Application Support/Tome"
36+
37+
echo "✓ Tome uninstalled."

0 commit comments

Comments
 (0)