forked from dteoh/SlowQuitApps
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-dmg.sh
More file actions
executable file
·195 lines (163 loc) · 6.87 KB
/
build-dmg.sh
File metadata and controls
executable file
·195 lines (163 loc) · 6.87 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
#!/bin/bash
set -e
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo "================================================================================"
echo " SlowQuitApps DMG Builder v1.0"
echo "================================================================================"
# Resolve version info
VERSION=$(grep -A 1 "CFBundleShortVersionString" SlowQuitApps/SlowQuitApps-Info.plist | grep string | sed 's/.*<string>\(.*\)<\/string>.*/\1/')
TIMESTAMP=$(date +%Y%m%d)
DMG_NAME="SlowQuitApps-v${VERSION}-Release.dmg"
echo -e "${BLUE}[INFO]${NC} Project: SlowQuitApps"
echo -e "${BLUE}[INFO]${NC} Version: ${VERSION}"
echo -e "${BLUE}[INFO]${NC} Configuration: Release"
echo -e "${BLUE}[INFO]${NC} Timestamp: ${TIMESTAMP}"
echo -e "${BLUE}[INFO]${NC} Output DMG: ${DMG_NAME}"
echo ""
# Validate project files
echo -e "${BLUE}[INFO]${NC} Validating project files..."
if [ ! -f "SlowQuitApps.xcodeproj/project.pbxproj" ]; then
echo -e "${RED}[ERROR]${NC} project.pbxproj not found!"
exit 1
fi
echo -e "${GREEN}[INFO]${NC} Project validation passed ✓"
echo ""
# Clean leftover builds
echo -e "${BLUE}[INFO]${NC} Cleaning previous builds..."
rm -rf build/
rm -rf dmgs/
rm -rf dmg_final_*
echo -e "${GREEN}[INFO]${NC} Cleaned DerivedData"
echo -e "${GREEN}[INFO]${NC} Cleaned temporary files"
echo ""
# Build archive
echo -e "${BLUE}[INFO]${NC} Building archive (Release)..."
ARCHIVE_PATH="build/SlowQuitApps.xcarchive"
xcodebuild -project SlowQuitApps.xcodeproj -scheme SlowQuitApps -configuration Release clean archive -archivePath "${ARCHIVE_PATH}"
if [ $? -ne 0 ]; then
echo -e "${RED}[ERROR]${NC} Build failed!"
exit 1
fi
echo -e "${GREEN}[INFO]${NC} Build completed ✓"
echo ""
# Locate .app bundles
echo -e "${BLUE}[INFO]${NC} Extracting app bundles..."
APP_PATH="${ARCHIVE_PATH}/Products/Applications/SlowQuitApps.app"
LAUNCHER_PATH="${APP_PATH}/Contents/Library/LoginItems/SlowQuitAppsLauncher.app"
if [ ! -d "${APP_PATH}" ]; then
echo -e "${RED}[ERROR]${NC} App bundle not found at ${APP_PATH}"
exit 1
fi
if [ ! -d "${LAUNCHER_PATH}" ]; then
echo -e "${RED}[ERROR]${NC} Launcher bundle not found at ${LAUNCHER_PATH}"
exit 1
fi
echo -e "${GREEN}[INFO]${NC} App bundles ready ✓"
echo ""
# Prepare DMG payload
echo -e "${BLUE}[INFO]${NC} Creating DMG..."
DMG_DIR="dmg_final_${TIMESTAMP}"
mkdir -p "${DMG_DIR}"
DMG_APP_PATH="${DMG_DIR}/SlowQuitApps.app"
cp -R "${APP_PATH}" "${DMG_APP_PATH}"
# Ad-hoc sign so SMAppService accepts the helper
if command -v codesign >/dev/null 2>&1; then
echo -e "${BLUE}[INFO]${NC} Ad-hoc signing SlowQuitApps.app for SMAppService compatibility..."
if codesign --force --deep --options runtime --sign - "${DMG_APP_PATH}" >/tmp/sqa-codesign.log 2>&1; then
echo -e "${GREEN}[INFO]${NC} Code signing completed ✓"
else
echo -e "${YELLOW}[WARN]${NC} codesign failed, see /tmp/sqa-codesign.log (SMAppService may reject unsigned builds)"
fi
else
echo -e "${YELLOW}[WARN]${NC} codesign tool not found; login item registration may fail on macOS 13+"
fi
# Add Applications symlink for drag-and-drop
if [ ! -e "${DMG_DIR}/Applications" ]; then
ln -s /Applications "${DMG_DIR}/Applications"
fi
# Create upgrade helper app (AppleScript wrapper around shell script)
UPGRADE_APP="${DMG_DIR}/Upgrade SlowQuitApps.app"
cat <<'OSA' > /tmp/UpgradeSlowQuitApps.applescript
on run
set helperPath to POSIX path of ((path to me as text) & "Contents:Resources:upgrade-helper.sh")
do shell script "/bin/bash " & quoted form of helperPath with administrator privileges
end run
OSA
osacompile -o "${UPGRADE_APP}" /tmp/UpgradeSlowQuitApps.applescript >/dev/null 2>&1
rm -f /tmp/UpgradeSlowQuitApps.applescript
mkdir -p "${UPGRADE_APP}/Contents/Resources"
cat <<'SCRIPT' > "${UPGRADE_APP}/Contents/Resources/upgrade-helper.sh"
#!/bin/bash
set -euo pipefail
APP_NAME="SlowQuitApps.app"
DMG_DIR="$(cd "$(dirname "$0")/../../.." && pwd)"
SRC_PATH="${DMG_DIR}/${APP_NAME}"
DST_PATH="/Applications/${APP_NAME}"
CONSOLE_USER=$(stat -f '%Su' /dev/console)
if [ -z "$CONSOLE_USER" ] || [ "$CONSOLE_USER" = "root" ]; then
echo "Unable to determine the signed-in user. Please run while logged into the desktop."
exit 1
fi
CONSOLE_UID=$(id -u "$CONSOLE_USER")
echo "== SlowQuitApps Upgrade Assistant =="
echo ""
echo "Stopping running instances..."
pkill -x SlowQuitApps >/dev/null 2>&1 || true
pkill -x SlowQuitAppsLauncher >/dev/null 2>&1 || true
launchctl bootout gui/${CONSOLE_UID}/com.dteoh.SlowQuitAppsLauncher >/dev/null 2>&1 || true
echo ""
echo "Copying new version to /Applications (password might be required)..."
rm -rf "$DST_PATH"
ditto "$SRC_PATH" "$DST_PATH"
echo ""
echo "Requesting auto-start re-enable on next launch..."
sudo -u "$CONSOLE_USER" defaults delete com.dteoh.SlowQuitApps disableAutostart >/dev/null 2>&1 || true
sudo -u "$CONSOLE_USER" defaults write com.dteoh.SlowQuitApps disableAutostart -bool NO >/dev/null 2>&1
sudo -u "$CONSOLE_USER" defaults write com.dteoh.SlowQuitApps pendingAutoEnable -bool YES >/dev/null 2>&1
echo ""
echo "Relaunching SlowQuitApps..."
sudo -u "$CONSOLE_USER" open "$DST_PATH"
echo ""
echo "Upgrade complete. Auto-start will be re-enabled automatically on next launch."
SCRIPT
chmod +x "${UPGRADE_APP}/Contents/Resources/upgrade-helper.sh"
# Generate textual install instructions
cat <<'DOC' > "${DMG_DIR}/Install Instructions.txt"
SlowQuitApps Installation & Upgrade Guide
=========================================
Install:
1. Drag "SlowQuitApps.app" onto the "Applications" symlink.
2. Launch the app, grant Accessibility permissions, and enable auto-start if desired.
Upgrade:
1. Double-click "Upgrade SlowQuitApps.app". It stops running helpers, copies this build into /Applications (macOS may prompt for your password), and relaunches the updated app with auto-start queued to re-enable automatically.
2. Alternatively, disable SlowQuitAppsLauncher in System Settings → General → Login Items, quit SlowQuitApps, replace the .app manually, then re-enable auto-start.
DOC
# Build DMG
DMG_PATH="dmg_final_${TIMESTAMP}"
hdiutil create -srcfolder "${DMG_PATH}" -volname "SlowQuitApps" -ov -format UDZO "${DMG_NAME}"
if [ $? -ne 0 ]; then
echo -e "${RED}[ERROR]${NC} DMG creation failed!"
exit 1
fi
# Generate checksums
echo ""
echo -e "${BLUE}[INFO]${NC} Generating checksums..."
MD5=$(md5 -q "${DMG_NAME}")
CRC32=$(crc32 "${DMG_NAME}")
echo -e "${GREEN}[INFO]${NC} DMG created: ${DMG_NAME}"
echo -e "${GREEN}[INFO]${NC} Size: $(du -h "${DMG_NAME}" | cut -f1)"
echo -e "${GREEN}[INFO]${NC} MD5: ${MD5}"
echo -e "${GREEN}[INFO]${NC} CRC32: ${CRC32}"
echo ""
echo "================================================================================"
echo -e "${GREEN} DMG build completed successfully!${NC}"
echo "================================================================================"
echo "Output: ${DMG_NAME}"
echo "Checksum: ${CRC32}"
echo ""
exit 0