-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·51 lines (44 loc) · 1.34 KB
/
install.sh
File metadata and controls
executable file
·51 lines (44 loc) · 1.34 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
50
51
#!/bin/bash
SERVICE_NAME="screen-lock-detector"
PLIST_ID="$USER.screen-lock-detector"
INSTALL_DIR="$HOME/Library/Application Support/ScreenLockDetector"
PLIST_FILE="$HOME/Library/LaunchAgents/$PLIST_ID.plist"
echo "Creating directory..."
mkdir -p "$INSTALL_DIR"
echo "Compiling..."
swiftc -O -whole-module-optimization -o $SERVICE_NAME ScreenLockDetector.swift
echo "Installing binary..."
cp $SERVICE_NAME "$INSTALL_DIR/"
chmod 755 "$INSTALL_DIR/$SERVICE_NAME"
echo "Creating plist..."
cat > "$PLIST_FILE" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>$PLIST_ID</string>
<key>ProgramArguments</key>
<array>
<string>$INSTALL_DIR/$SERVICE_NAME</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/$SERVICE_NAME.log</string>
<key>StandardErrorPath</key>
<string>/tmp/$SERVICE_NAME.error.log</string>
<key>ProcessType</key>
<string>Background</string>
<key>Nice</key>
<integer>10</integer>
</dict>
</plist>
EOF
echo "Loading service..."
launchctl unload "$PLIST_FILE" 2>/dev/null
launchctl load "$PLIST_FILE"
echo "Done! Service status:"
launchctl list | grep $PLIST_ID