-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·291 lines (255 loc) · 9.82 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·291 lines (255 loc) · 9.82 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#!/bin/bash
set -euo pipefail
REPO="DinN0000/DotBrain"
APP_NAME="DotBrain"
APP_BUNDLE="$APP_NAME.app"
INSTALL_DIR="$HOME/Applications"
APP_PATH="$INSTALL_DIR/$APP_BUNDLE"
EXECUTABLE="$APP_PATH/Contents/MacOS/$APP_NAME"
LAUNCHAGENT_DIR="$HOME/Library/LaunchAgents"
PLIST_NAME="com.dotbrain.app"
PLIST_PATH="$LAUNCHAGENT_DIR/$PLIST_NAME.plist"
CURL_OPTS=(--fail --location --silent --show-error --retry 3 --retry-delay 1 --retry-connrefused)
echo "=== DotBrain 설치 ==="
echo ""
# Detect architecture
ARCH=$(uname -m)
echo "시스템: macOS $(sw_vers -productVersion) ($ARCH)"
# --- 릴리즈 정보 조회 ---
DMG_URL=""
DOWNLOAD_URL=""
ICON_URL=""
if [ -n "${1:-}" ]; then
TAG="$1"
echo "버전 지정: $TAG"
DMG_URL="https://github.com/$REPO/releases/download/$TAG/$APP_NAME-${TAG#v}.dmg"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$APP_NAME"
ICON_URL="https://github.com/$REPO/releases/download/$TAG/AppIcon.icns"
else
echo "최신 릴리즈 확인 중..."
if ! RELEASE_JSON=$(curl "${CURL_OPTS[@]}" "https://api.github.com/repos/$REPO/releases/latest"); then
echo "오류: 최신 릴리즈 정보를 가져오지 못했습니다. 네트워크 상태를 확인한 뒤 다시 시도해주세요."
echo "문제가 계속되면 https://github.com/$REPO/releases 에서 직접 다운로드하세요."
exit 1
fi
TAG=$(echo "$RELEASE_JSON" | grep '"tag_name"' | head -1 | sed -E 's/.*"([^"]+)".*/\1/') || true
if [ -z "$TAG" ]; then
echo "오류: 릴리즈 정보를 읽을 수 없습니다. (GitHub API 제한일 수 있음)"
echo "https://github.com/$REPO/releases 에서 직접 다운로드하세요."
exit 1
fi
# DMG asset (preferred)
DMG_URL=$(echo "$RELEASE_JSON" \
| grep '"browser_download_url"' \
| grep '\.dmg"' \
| head -1 \
| sed -E 's/.*"(https[^"]+)".*/\1/') || true
# Binary asset (fallback)
DOWNLOAD_URL=$(echo "$RELEASE_JSON" \
| grep '"browser_download_url"' \
| grep -v -E '\.(icns|txt|md|json|zip|tar|gz|sha256|dmg)' \
| head -1 \
| sed -E 's/.*"(https[^"]+)".*/\1/') || true
ICON_URL=$(echo "$RELEASE_JSON" \
| grep '"browser_download_url"' \
| grep "AppIcon.icns" \
| head -1 \
| sed -E 's/.*"(https[^"]+)".*/\1/') || true
fi
echo "버전: $TAG"
# Create temp directory
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
# --- Unload LaunchAgent + stop app (common for both paths) ---
launchctl bootout "gui/$(id -u)/$PLIST_NAME" 2>/dev/null || true
pkill -x "$APP_NAME" 2>/dev/null || true
sleep 1
# --- DMG 설치 경로 (우선) ---
INSTALLED_VIA_DMG=false
if [ -n "$DMG_URL" ]; then
echo "DMG 다운로드 중..."
if curl "${CURL_OPTS[@]}" "$DMG_URL" -o "$TMP_DIR/$APP_NAME.dmg" 2>/dev/null; then
# Verify DMG checksum if available
CHECKSUM_URL="https://github.com/$REPO/releases/download/$TAG/checksums.txt"
if curl "${CURL_OPTS[@]}" "$CHECKSUM_URL" -o "$TMP_DIR/checksums.txt" 2>/dev/null; then
DMG_FILENAME="$APP_NAME-${TAG#v}.dmg"
EXPECTED=$(grep " ${DMG_FILENAME}$" "$TMP_DIR/checksums.txt" | awk '{print $1}')
if [ -n "$EXPECTED" ]; then
ACTUAL=$(shasum -a 256 "$TMP_DIR/$APP_NAME.dmg" | awk '{print $1}')
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "오류: DMG 체크섬 불일치! 다운로드가 손상되었을 수 있습니다."
echo " 예상: $EXPECTED"
echo " 실제: $ACTUAL"
exit 1
fi
echo "✓ DMG 체크섬 확인 완료"
fi
fi
echo "DMG 마운트 중..."
MOUNT_OUTPUT=$(hdiutil attach "$TMP_DIR/$APP_NAME.dmg" -nobrowse -readonly 2>/dev/null) || true
if [ -n "$MOUNT_OUTPUT" ]; then
MOUNT_POINT=$(echo "$MOUNT_OUTPUT" | tail -1 | awk -F'\t' '{print $NF}' | xargs)
if [ -d "$MOUNT_POINT/$APP_BUNDLE" ]; then
echo "DMG에서 앱 복사 중..."
mkdir -p "$INSTALL_DIR"
rm -rf "$APP_PATH"
cp -R "$MOUNT_POINT/$APP_BUNDLE" "$APP_PATH"
hdiutil detach "$MOUNT_POINT" -quiet 2>/dev/null || true
xattr -cr "$APP_PATH" 2>/dev/null || true
INSTALLED_VIA_DMG=true
echo "✓ DMG에서 앱 설치 완료: $APP_PATH"
else
hdiutil detach "$MOUNT_POINT" -quiet 2>/dev/null || true
echo "경고: DMG 내 앱을 찾을 수 없습니다. 바이너리 설치로 전환합니다."
fi
else
echo "경고: DMG 마운트 실패. 바이너리 설치로 전환합니다."
fi
else
echo "경고: DMG 다운로드 실패. 바이너리 설치로 전환합니다."
fi
fi
# --- 바이너리 설치 경로 (fallback) ---
if [ "$INSTALLED_VIA_DMG" = false ]; then
if [ -z "$DOWNLOAD_URL" ]; then
echo "오류: 설치 가능한 에셋을 찾을 수 없습니다."
echo "https://github.com/$REPO/releases 에서 직접 다운로드하세요."
exit 1
fi
echo "바이너리 다운로드 중: $DOWNLOAD_URL"
curl "${CURL_OPTS[@]}" "$DOWNLOAD_URL" -o "$TMP_DIR/$APP_NAME"
chmod +x "$TMP_DIR/$APP_NAME"
# Verify checksum if available
CHECKSUM_URL="https://github.com/$REPO/releases/download/$TAG/checksums.txt"
if curl "${CURL_OPTS[@]}" "$CHECKSUM_URL" -o "$TMP_DIR/checksums.txt" 2>/dev/null; then
EXPECTED=$(grep " ${APP_NAME}$" "$TMP_DIR/checksums.txt" | awk '{print $1}')
ACTUAL=$(shasum -a 256 "$TMP_DIR/$APP_NAME" | awk '{print $1}')
if [ -z "$EXPECTED" ]; then
echo "오류: checksums.txt에서 $APP_NAME 항목을 찾지 못했습니다."
exit 1
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "오류: 체크섬 불일치! 다운로드가 손상되었을 수 있습니다."
echo " 예상: $EXPECTED"
echo " 실제: $ACTUAL"
exit 1
fi
echo "✓ 체크섬 확인 완료"
fi
# Download icon
if [ -n "${ICON_URL:-}" ]; then
if ! curl "${CURL_OPTS[@]}" "$ICON_URL" -o "$TMP_DIR/AppIcon.icns"; then
echo "경고: 아이콘 다운로드 실패, 기본 아이콘으로 계속 진행합니다."
fi
fi
# .app 번들 생성
echo "앱 번들 생성 중..."
mkdir -p "$INSTALL_DIR"
rm -rf "$APP_PATH"
mkdir -p "$APP_PATH/Contents/MacOS"
mkdir -p "$APP_PATH/Contents/Resources"
cp "$TMP_DIR/$APP_NAME" "$EXECUTABLE"
if [ -f "$TMP_DIR/AppIcon.icns" ]; then
cp "$TMP_DIR/AppIcon.icns" "$APP_PATH/Contents/Resources/AppIcon.icns"
fi
APP_VERSION=$(echo "$TAG" | sed 's/^v//')
echo "버전: $APP_VERSION"
cat > "$APP_PATH/Contents/Info.plist" << INFOPLIST
<?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>CFBundleName</key>
<string>DotBrain</string>
<key>CFBundleDisplayName</key>
<string>DotBrain</string>
<key>CFBundleIdentifier</key>
<string>com.hwaa.dotbrain</string>
<key>CFBundleVersion</key>
<string>$APP_VERSION</string>
<key>CFBundleShortVersionString</key>
<string>$APP_VERSION</string>
<key>CFBundleExecutable</key>
<string>DotBrain</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSUIElement</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>api.anthropic.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
INFOPLIST
xattr -cr "$APP_PATH" 2>/dev/null || true
echo "✓ 앱 설치 완료: $APP_PATH"
fi
# --- LaunchAgent 등록 (로그인 시 자동 시작) ---
echo ""
echo "로그인 시 자동 시작 설정 중..."
launchctl bootout "gui/$(id -u)/$PLIST_NAME" 2>/dev/null || true
mkdir -p "$LAUNCHAGENT_DIR"
cat > "$PLIST_PATH" << PLIST
<?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_NAME</string>
<key>ProgramArguments</key>
<array>
<string>$EXECUTABLE</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>ProcessType</key>
<string>Interactive</string>
</dict>
</plist>
PLIST
launchctl bootstrap "gui/$(id -u)" "$PLIST_PATH"
echo "✓ 자동 시작 등록 완료"
# --- 바로 실행 ---
echo ""
echo "앱을 시작합니다..."
if ! launchctl kickstart "gui/$(id -u)/$PLIST_NAME" 2>/dev/null; then
echo "경고: LaunchAgent 시작 실패, 앱을 직접 실행합니다."
open "$APP_PATH"
fi
echo ""
echo "================================================"
echo " 설치 완료!"
echo " 메뉴바에서 ·‿· 아이콘을 확인하세요."
echo ""
echo " - ~/Applications에서 앱을 확인할 수 있습니다"
echo " - 로그인 시 자동으로 시작됩니다"
echo " - 비정상 종료 시 자동으로 재시작됩니다"
echo "================================================"
echo ""
echo "제거하려면:"
echo " pkill -f $APP_NAME; \\"
echo " launchctl bootout gui/\$(id -u)/$PLIST_NAME; \\"
echo " rm -rf $APP_PATH; \\"
echo " rm -f $PLIST_PATH; \\"
echo " echo \"제거 완료\""