Repository navigation
Expand file tree
/
Copy pathinstall
More file actions
executable file
·102 lines (92 loc) · 2.71 KB
/
Copy pathinstall
File metadata and controls
executable file
·102 lines (92 loc) · 2.71 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/zsh
set -euo pipefail
setopt extended_glob
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
root="${0:A:h}"
bin="$root/sshclip"
label="com.sshclip.agent"
plist="$HOME/Library/LaunchAgents/$label.plist"
log_dir="$HOME/Library/Logs"
hosts=("$@")
uid="$(id -u)"
usage() {
print "Usage: ./install HOST [HOST ...]"
print " or: SSHCLIP_HOSTS=host1,host2 ./install"
}
valid_host() {
[[ "$1" == [A-Za-z0-9._-]## && "$1" != -* ]]
}
xml_escape() {
local s="$1"
s="${s//&/&}"
s="${s//</<}"
s="${s//>/>}"
print -r -- "$s"
}
if (( ${#hosts[@]} == 0 )); then
if [[ -n "${SSHCLIP_HOSTS:-}" ]]; then
hosts=("${(@s:,:)SSHCLIP_HOSTS}")
else
usage >&2
exit 2
fi
fi
for host in "${hosts[@]}"; do
valid_host "$host" || {
print -ru2 -- "install: unsafe SSH host alias: $host"
exit 2
}
done
mkdir -p "$HOME/Library/LaunchAgents" "$log_dir"
chmod +x "$bin"
mkdir -p "$HOME/.local/bin"
ln -sf "$bin" "$HOME/.local/bin/sshclip"
{
print '<?xml version="1.0" encoding="UTF-8"?>'
print '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"'
print ' "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
print '<plist version="1.0">'
print '<dict>'
print ' <key>Label</key>'
print " <string>$label</string>"
print ' <key>ProgramArguments</key>'
print ' <array>'
print " <string>$(xml_escape "$bin")</string>"
for host in "${hosts[@]}"; do
print " <string>$(xml_escape "$host")</string>"
done
print ' </array>'
print ' <key>EnvironmentVariables</key>'
print ' <dict>'
print ' <key>SSHCLIP_STARTUP_SCREENSHOT_SECONDS</key>'
print ' <string>0</string>'
print ' <key>SSHCLIP_POLL</key>'
print ' <string>0.2</string>'
print ' </dict>'
print ' <key>RunAtLoad</key>'
print ' <true/>'
print ' <key>KeepAlive</key>'
print ' <true/>'
print ' <key>StandardOutPath</key>'
print " <string>$(xml_escape "$log_dir/sshclip.log")</string>"
print ' <key>StandardErrorPath</key>'
print " <string>$(xml_escape "$log_dir/sshclip.err.log")</string>"
print '</dict>'
print '</plist>'
} > "$plist"
chmod 0644 "$plist"
plutil -lint "$plist" >/dev/null
launchctl bootout "gui/$uid/$label" 2>/dev/null || true
launchctl bootout "gui/$uid" "$plist" 2>/dev/null || true
launchctl bootstrap "gui/$uid" "$plist"
launchctl kickstart -k "gui/$uid/$label"
print "sshclip is running for: ${hosts[*]}"
print "After verifying Termius detection, follow the active tab with:"
print " ~/.local/bin/sshclip target termius"
print "Select one active upload host with:"
print " ~/.local/bin/sshclip target HOST"
print "Upload to every configured host with:"
print " ~/.local/bin/sshclip target all"
print "Logs:"
print " $log_dir/sshclip.log"
print " $log_dir/sshclip.err.log"