-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_app.sh
More file actions
executable file
·102 lines (92 loc) · 3.92 KB
/
install_app.sh
File metadata and controls
executable file
·102 lines (92 loc) · 3.92 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/bash
set -e
APP_NAME="Insomnia"
BUILD_DIR=".build/release"
APP_BUNDLE="${APP_NAME}.app"
CONTENTS_DIR="${APP_BUNDLE}/Contents"
MACOS_DIR="${CONTENTS_DIR}/MacOS"
RESOURCES_DIR="${CONTENTS_DIR}/Resources"
echo "Using Swift Version: $(swift --version)"
echo "Building ${APP_NAME} in release mode..."
swift build -c release
# Create .app structure
echo "Creating ${APP_BUNDLE} structure..."
rm -rf "${APP_BUNDLE}"
mkdir -p "${MACOS_DIR}"
mkdir -p "${RESOURCES_DIR}"
# Copy executable
cp "${BUILD_DIR}/${APP_NAME}" "${MACOS_DIR}/"
# Copy resources (if they exist in a bundle)
# SPM resources are often in a separate bundle or adjacent.
# For 'process' resources in executable, they might be inside the binary or in a separate bundle directory.
# We'll check for the bundle.
RESOURCE_BUNDLE="${BUILD_DIR}/${APP_NAME}_${APP_NAME}Core.bundle"
if [ -d "$RESOURCE_BUNDLE" ]; then
echo "Copying resources from ${RESOURCE_BUNDLE}..."
cp -r "$RESOURCE_BUNDLE" "${RESOURCES_DIR}/"
fi
# Also check for direct assets if strictly executable
RESOURCE_BUNDLE_2="${BUILD_DIR}/${APP_NAME}_${APP_NAME}.bundle"
if [ -d "$RESOURCE_BUNDLE_2" ]; then
echo "Copying resources from ${RESOURCE_BUNDLE_2}..."
cp -r "$RESOURCE_BUNDLE_2" "${RESOURCES_DIR}/"
fi
# Create Info.plist
# We read the one from local if available, or generate a minimal one
if [ -f "insomnia/Info.plist" ]; then
echo "Copying and configuring Info.plist..."
cp "insomnia/Info.plist" "${CONTENTS_DIR}/Info.plist"
# Replace Xcode variables
sed -i '' 's/$(EXECUTABLE_NAME)/'"${APP_NAME}"'/g' "${CONTENTS_DIR}/Info.plist"
sed -i '' 's/$(PRODUCT_NAME)/'"${APP_NAME}"'/g' "${CONTENTS_DIR}/Info.plist"
sed -i '' 's/$(PRODUCT_BUNDLE_IDENTIFIER)/com.karansangha.'"${APP_NAME}"'/g' "${CONTENTS_DIR}/Info.plist"
sed -i '' 's/$(MACOSX_DEPLOYMENT_TARGET)/13.0/g' "${CONTENTS_DIR}/Info.plist"
else
echo "Generating Info.plist..."
cat > "${CONTENTS_DIR}/Info.plist" <<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>CFBundleExecutable</key>
<string>${APP_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.karansangha.${APP_NAME}</string>
<key>CFBundleName</key>
<string>${APP_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>13.0</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
EOF
fi
# Need to handle icon specifically if it's in Assets.xcassets
# Compilation usually handles this if we use xcodebuild, but with SPM it's trickier.
# For now, we rely on the resources copied above. If AppIcon is in xcassets, it needs to be compiled to icns.
# We'll skip complex icon compilation for this simple script unless the user has 'iconutil'.
if [ -d "insomnia/Assets.xcassets/AppIcon.appiconset" ]; then
echo "Compiling AppIcon..."
if xcrun actool insomnia/Assets.xcassets --compile "${RESOURCES_DIR}" --platform macosx --minimum-deployment-target 13.0 --app-icon AppIcon --output-partial-info-plist /tmp/partial.plist; then
echo "Asset compilation successful."
else
echo "Warning: icon compilation failed. Falling back to copying raw images."
# Copy raw pngs to Resources root so Image("name") can find them
find insomnia/Assets.xcassets -name "*.png" -exec cp {} "${RESOURCES_DIR}/" \;
fi
fi
# Ad-hoc sign the app to prevent some local Gatekeeper/Permission issues
echo "Signing app (ad-hoc)..."
codesign --force --deep --sign - "${APP_BUNDLE}"
echo "------------------------------------------------"
echo "Done! App created at $(pwd)/${APP_BUNDLE}"
echo "To install: mv ${APP_BUNDLE} /Applications/"
echo "To run: open ${APP_BUNDLE}"
echo "------------------------------------------------"