-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·96 lines (76 loc) · 2.28 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·96 lines (76 loc) · 2.28 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
#!/bin/zsh
set -e
set -u
set -o pipefail
API_URL="https://api.github.com/repos/bleeeet/TermiPet/releases/latest"
ASSET_GLOB="TermiPet-v*-macOS.zip"
APP_PATH="/Applications/TermiPet.app"
BACKUP_DIR="$HOME/Library/Application Support/TermiPet/InstallBackups"
info() {
printf "==> %s\n" "$1"
}
fail() {
printf "TermiPet install failed: %s\n" "$1" >&2
exit 1
}
require_command() {
command -v "$1" >/dev/null 2>&1 || fail "missing required command: $1"
}
macos_major_version() {
sw_vers -productVersion | awk -F. '{ print $1 }'
}
require_command curl
require_command awk
require_command unzip
require_command ditto
require_command xattr
if [ "$(uname -s)" != "Darwin" ]; then
fail "TermiPet only supports macOS."
fi
if [ "$(macos_major_version)" -lt 13 ]; then
fail "TermiPet requires macOS 13.0 or later."
fi
WORK_DIR="$(mktemp -d "${TMPDIR:-/tmp}/termipet-install.XXXXXX")"
ZIP_PATH="$WORK_DIR/TermiPet.zip"
info "Fetching latest TermiPet release"
ASSET_URL="$(
curl -fsSL "$API_URL" |
awk -F'"' '/browser_download_url/ && /TermiPet-v.*-macOS\.zip/ { print $4; exit }'
)"
if [ -z "$ASSET_URL" ]; then
fail "could not find a release asset matching $ASSET_GLOB."
fi
info "Downloading $ASSET_URL"
curl -fL "$ASSET_URL" -o "$ZIP_PATH"
info "Unpacking TermiPet"
unzip -q "$ZIP_PATH" -d "$WORK_DIR"
APP_SOURCE="$(find "$WORK_DIR" -name "TermiPet.app" -type d -print -quit)"
if [ -z "$APP_SOURCE" ]; then
fail "downloaded archive did not contain TermiPet.app."
fi
if pgrep -x TermiPet >/dev/null 2>&1; then
info "Closing the running TermiPet app"
osascript -e 'tell application "TermiPet" to quit' >/dev/null 2>&1 || true
sleep 1
fi
if [ -d "$APP_PATH" ]; then
mkdir -p "$BACKUP_DIR"
BACKUP_PATH="$BACKUP_DIR/TermiPet-$(date +%Y%m%d-%H%M%S).app"
info "Moving existing app to $BACKUP_PATH"
if [ -w "/Applications" ]; then
mv "$APP_PATH" "$BACKUP_PATH"
else
sudo mv "$APP_PATH" "$BACKUP_PATH"
fi
fi
info "Installing TermiPet to $APP_PATH"
if [ -w "/Applications" ]; then
ditto "$APP_SOURCE" "$APP_PATH"
else
sudo ditto "$APP_SOURCE" "$APP_PATH"
fi
info "Clearing macOS quarantine attributes"
xattr -cr "$APP_PATH" 2>/dev/null || true
info "Launching TermiPet"
open "$APP_PATH"
info "Done. Temporary files are in $WORK_DIR"