Skip to content

Commit 0ec8d2b

Browse files
committed
fix installers #7
1 parent cb19c22 commit 0ec8d2b

File tree

11 files changed

+277
-98
lines changed

11 files changed

+277
-98
lines changed

.github/workflows/build-macos-arm-installer.yml

Lines changed: 123 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,37 @@ jobs:
167167
rm -rf Cleanuparr.iconset
168168
fi
169169
170+
# Create Launch Daemon plist
171+
cat > dist/Cleanuparr.app/Contents/Resources/com.cleanuparr.daemon.plist << EOF
172+
<?xml version="1.0" encoding="UTF-8"?>
173+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
174+
<plist version="1.0">
175+
<dict>
176+
<key>Label</key>
177+
<string>com.cleanuparr.daemon</string>
178+
<key>ProgramArguments</key>
179+
<array>
180+
<string>/Applications/Cleanuparr.app/Contents/MacOS/Cleanuparr</string>
181+
</array>
182+
<key>RunAtLoad</key>
183+
<true/>
184+
<key>KeepAlive</key>
185+
<true/>
186+
<key>StandardOutPath</key>
187+
<string>/var/log/cleanuparr.log</string>
188+
<key>StandardErrorPath</key>
189+
<string>/var/log/cleanuparr.error.log</string>
190+
<key>WorkingDirectory</key>
191+
<string>/Applications/Cleanuparr.app/Contents/MacOS</string>
192+
<key>EnvironmentVariables</key>
193+
<dict>
194+
<key>HTTP_PORTS</key>
195+
<string>11011</string>
196+
</dict>
197+
</dict>
198+
</plist>
199+
EOF
200+
170201
# Create Info.plist with proper configuration
171202
cat > dist/Cleanuparr.app/Contents/Info.plist << EOF
172203
<?xml version="1.0" encoding="UTF-8"?>
@@ -221,52 +252,118 @@ jobs:
221252
222253
- name: Create PKG installer
223254
run: |
224-
# Create postinstall script
255+
# Create preinstall script to handle existing installations
225256
mkdir -p scripts
257+
cat > scripts/preinstall << 'EOF'
258+
#!/bin/bash
259+
260+
# Stop and unload existing launch daemon if it exists
261+
if launchctl list | grep -q "com.cleanuparr.daemon"; then
262+
launchctl stop com.cleanuparr.daemon 2>/dev/null || true
263+
launchctl unload /Library/LaunchDaemons/com.cleanuparr.daemon.plist 2>/dev/null || true
264+
fi
265+
266+
# Stop any running instances of Cleanuparr
267+
pkill -f "Cleanuparr" || true
268+
sleep 2
269+
270+
# Remove old installation if it exists
271+
if [[ -d "/Applications/Cleanuparr.app" ]]; then
272+
rm -rf "/Applications/Cleanuparr.app"
273+
fi
274+
275+
# Remove old launch daemon plist if it exists
276+
if [[ -f "/Library/LaunchDaemons/com.cleanuparr.daemon.plist" ]]; then
277+
rm -f "/Library/LaunchDaemons/com.cleanuparr.daemon.plist"
278+
fi
279+
280+
exit 0
281+
EOF
282+
283+
chmod +x scripts/preinstall
284+
285+
# Create postinstall script
226286
cat > scripts/postinstall << 'EOF'
227287
#!/bin/bash
228288
229289
# Set proper permissions for the app bundle
230290
chmod -R 755 /Applications/Cleanuparr.app
231291
chmod +x /Applications/Cleanuparr.app/Contents/MacOS/Cleanuparr
232292
233-
# Create config directory in user's Application Support
234-
# Note: This runs as root during installation, so we need to handle user directories properly
235-
for user_home in /Users/*; do
236-
if [[ -d "$user_home" && ! "$user_home" =~ /(Shared|.localized)$ ]]; then
237-
user_name=$(basename "$user_home")
238-
if [[ "$user_name" != "root" ]]; then
239-
sudo -u "$user_name" mkdir -p "$user_home/Library/Application Support/Cleanuparr"
240-
sudo -u "$user_name" chmod 755 "$user_home/Library/Application Support/Cleanuparr"
241-
fi
242-
fi
243-
done
244-
245-
# Add to system PATH if not already there (optional)
246-
# ln -sf /Applications/Cleanuparr.app/Contents/MacOS/Cleanuparr /usr/local/bin/cleanuparr 2>/dev/null || true
293+
# Install the launch daemon
294+
cp /Applications/Cleanuparr.app/Contents/Resources/com.cleanuparr.daemon.plist /Library/LaunchDaemons/
295+
chown root:wheel /Library/LaunchDaemons/com.cleanuparr.daemon.plist
296+
chmod 644 /Library/LaunchDaemons/com.cleanuparr.daemon.plist
297+
298+
# Load and start the service
299+
launchctl load /Library/LaunchDaemons/com.cleanuparr.daemon.plist
300+
launchctl start com.cleanuparr.daemon
301+
302+
# Wait a moment for service to start
303+
sleep 3
304+
305+
# Create completion message
306+
cat > /tmp/cleanuparr_install_complete.txt << 'MSGEOF'
307+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
308+
Cleanuparr Installation Complete!
309+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
310+
311+
Cleanuparr is now running as a system service!
312+
313+
🌐 Web Interface: http://localhost:11011
314+
📁 Configuration: /Applications/Cleanuparr.app/Contents/MacOS/config/
315+
📋 Logs: /var/log/cleanuparr.log
316+
317+
The service will automatically start when your Mac boots.
318+
319+
🆘 Need Help? Visit: https://github.com/Cleanuparr/Cleanuparr
320+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
321+
MSGEOF
322+
323+
# Show completion message in Terminal (if available)
324+
if command -v osascript >/dev/null 2>&1; then
325+
osascript -e 'tell application "Terminal" to do script "cat /tmp/cleanuparr_install_complete.txt && echo && echo \"Press any key to close...\" && read -n 1 && exit"' 2>/dev/null || true
326+
fi
327+
328+
# Also display as system notification
329+
osascript -e 'display notification "Cleanuparr service started! Visit http://localhost:11011 in your browser." with title "Installation Complete"' 2>/dev/null || true
330+
331+
# Clean up
332+
rm -f /tmp/cleanuparr_install_complete.txt
247333
248334
exit 0
249335
EOF
250336
251337
chmod +x scripts/postinstall
252338
253-
# Create preinstall script to handle existing installations
254-
cat > scripts/preinstall << 'EOF'
339+
# Create uninstall script (optional, for user reference)
340+
cat > scripts/uninstall_cleanuparr.sh << 'EOF'
255341
#!/bin/bash
342+
# Cleanuparr Uninstall Script
343+
# Run this script with sudo to completely remove Cleanuparr
256344
257-
# Stop any running instances of Cleanuparr
258-
pkill -f "Cleanuparr" || true
259-
sleep 2
345+
echo "Stopping Cleanuparr service..."
346+
launchctl stop com.cleanuparr.daemon 2>/dev/null || true
347+
launchctl unload /Library/LaunchDaemons/com.cleanuparr.daemon.plist 2>/dev/null || true
260348
261-
# Remove old installation if it exists
262-
if [[ -d "/Applications/Cleanuparr.app" ]]; then
263-
rm -rf "/Applications/Cleanuparr.app"
264-
fi
349+
echo "Removing service files..."
350+
rm -f /Library/LaunchDaemons/com.cleanuparr.daemon.plist
265351
266-
exit 0
352+
echo "Removing application..."
353+
rm -rf /Applications/Cleanuparr.app
354+
355+
echo "Removing logs..."
356+
rm -f /var/log/cleanuparr.log
357+
rm -f /var/log/cleanuparr.error.log
358+
359+
echo "Cleanuparr has been completely removed."
360+
echo "Note: Configuration files in /Applications/Cleanuparr.app/Contents/MacOS/config/ have been removed with the app."
267361
EOF
268362
269-
chmod +x scripts/preinstall
363+
chmod +x scripts/uninstall_cleanuparr.sh
364+
365+
# Copy uninstall script to app bundle for user access
366+
cp scripts/uninstall_cleanuparr.sh dist/Cleanuparr.app/Contents/Resources/
270367
271368
# Determine package name
272369
if [[ "${{ github.ref }}" =~ ^refs/tags/ ]]; then

.github/workflows/build-macos-intel-installer.yml

Lines changed: 123 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,37 @@ jobs:
167167
rm -rf Cleanuparr.iconset
168168
fi
169169
170+
# Create Launch Daemon plist
171+
cat > dist/Cleanuparr.app/Contents/Resources/com.cleanuparr.daemon.plist << EOF
172+
<?xml version="1.0" encoding="UTF-8"?>
173+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
174+
<plist version="1.0">
175+
<dict>
176+
<key>Label</key>
177+
<string>com.cleanuparr.daemon</string>
178+
<key>ProgramArguments</key>
179+
<array>
180+
<string>/Applications/Cleanuparr.app/Contents/MacOS/Cleanuparr</string>
181+
</array>
182+
<key>RunAtLoad</key>
183+
<true/>
184+
<key>KeepAlive</key>
185+
<true/>
186+
<key>StandardOutPath</key>
187+
<string>/var/log/cleanuparr.log</string>
188+
<key>StandardErrorPath</key>
189+
<string>/var/log/cleanuparr.error.log</string>
190+
<key>WorkingDirectory</key>
191+
<string>/Applications/Cleanuparr.app/Contents/MacOS</string>
192+
<key>EnvironmentVariables</key>
193+
<dict>
194+
<key>HTTP_PORTS</key>
195+
<string>11011</string>
196+
</dict>
197+
</dict>
198+
</plist>
199+
EOF
200+
170201
# Create Info.plist with proper configuration
171202
cat > dist/Cleanuparr.app/Contents/Info.plist << EOF
172203
<?xml version="1.0" encoding="UTF-8"?>
@@ -221,52 +252,118 @@ jobs:
221252
222253
- name: Create PKG installer
223254
run: |
224-
# Create postinstall script
255+
# Create preinstall script to handle existing installations
225256
mkdir -p scripts
257+
cat > scripts/preinstall << 'EOF'
258+
#!/bin/bash
259+
260+
# Stop and unload existing launch daemon if it exists
261+
if launchctl list | grep -q "com.cleanuparr.daemon"; then
262+
launchctl stop com.cleanuparr.daemon 2>/dev/null || true
263+
launchctl unload /Library/LaunchDaemons/com.cleanuparr.daemon.plist 2>/dev/null || true
264+
fi
265+
266+
# Stop any running instances of Cleanuparr
267+
pkill -f "Cleanuparr" || true
268+
sleep 2
269+
270+
# Remove old installation if it exists
271+
if [[ -d "/Applications/Cleanuparr.app" ]]; then
272+
rm -rf "/Applications/Cleanuparr.app"
273+
fi
274+
275+
# Remove old launch daemon plist if it exists
276+
if [[ -f "/Library/LaunchDaemons/com.cleanuparr.daemon.plist" ]]; then
277+
rm -f "/Library/LaunchDaemons/com.cleanuparr.daemon.plist"
278+
fi
279+
280+
exit 0
281+
EOF
282+
283+
chmod +x scripts/preinstall
284+
285+
# Create postinstall script
226286
cat > scripts/postinstall << 'EOF'
227287
#!/bin/bash
228288
229289
# Set proper permissions for the app bundle
230290
chmod -R 755 /Applications/Cleanuparr.app
231291
chmod +x /Applications/Cleanuparr.app/Contents/MacOS/Cleanuparr
232292
233-
# Create config directory in user's Application Support
234-
# Note: This runs as root during installation, so we need to handle user directories properly
235-
for user_home in /Users/*; do
236-
if [[ -d "$user_home" && ! "$user_home" =~ /(Shared|.localized)$ ]]; then
237-
user_name=$(basename "$user_home")
238-
if [[ "$user_name" != "root" ]]; then
239-
sudo -u "$user_name" mkdir -p "$user_home/Library/Application Support/Cleanuparr"
240-
sudo -u "$user_name" chmod 755 "$user_home/Library/Application Support/Cleanuparr"
241-
fi
242-
fi
243-
done
244-
245-
# Add to system PATH if not already there (optional)
246-
# ln -sf /Applications/Cleanuparr.app/Contents/MacOS/Cleanuparr /usr/local/bin/cleanuparr 2>/dev/null || true
293+
# Install the launch daemon
294+
cp /Applications/Cleanuparr.app/Contents/Resources/com.cleanuparr.daemon.plist /Library/LaunchDaemons/
295+
chown root:wheel /Library/LaunchDaemons/com.cleanuparr.daemon.plist
296+
chmod 644 /Library/LaunchDaemons/com.cleanuparr.daemon.plist
297+
298+
# Load and start the service
299+
launchctl load /Library/LaunchDaemons/com.cleanuparr.daemon.plist
300+
launchctl start com.cleanuparr.daemon
301+
302+
# Wait a moment for service to start
303+
sleep 3
304+
305+
# Create completion message
306+
cat > /tmp/cleanuparr_install_complete.txt << 'MSGEOF'
307+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
308+
Cleanuparr Installation Complete!
309+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
310+
311+
Cleanuparr is now running as a system service!
312+
313+
🌐 Web Interface: http://localhost:11011
314+
📁 Configuration: /Applications/Cleanuparr.app/Contents/MacOS/config/
315+
📋 Logs: /var/log/cleanuparr.log
316+
317+
The service will automatically start when your Mac boots.
318+
319+
🆘 Need Help? Visit: https://github.com/Cleanuparr/Cleanuparr
320+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
321+
MSGEOF
322+
323+
# Show completion message in Terminal (if available)
324+
if command -v osascript >/dev/null 2>&1; then
325+
osascript -e 'tell application "Terminal" to do script "cat /tmp/cleanuparr_install_complete.txt && echo && echo \"Press any key to close...\" && read -n 1 && exit"' 2>/dev/null || true
326+
fi
327+
328+
# Also display as system notification
329+
osascript -e 'display notification "Cleanuparr service started! Visit http://localhost:11011 in your browser." with title "Installation Complete"' 2>/dev/null || true
330+
331+
# Clean up
332+
rm -f /tmp/cleanuparr_install_complete.txt
247333
248334
exit 0
249335
EOF
250336
251337
chmod +x scripts/postinstall
252338
253-
# Create preinstall script to handle existing installations
254-
cat > scripts/preinstall << 'EOF'
339+
# Create uninstall script (optional, for user reference)
340+
cat > scripts/uninstall_cleanuparr.sh << 'EOF'
255341
#!/bin/bash
342+
# Cleanuparr Uninstall Script
343+
# Run this script with sudo to completely remove Cleanuparr
256344
257-
# Stop any running instances of Cleanuparr
258-
pkill -f "Cleanuparr" || true
259-
sleep 2
345+
echo "Stopping Cleanuparr service..."
346+
launchctl stop com.cleanuparr.daemon 2>/dev/null || true
347+
launchctl unload /Library/LaunchDaemons/com.cleanuparr.daemon.plist 2>/dev/null || true
260348
261-
# Remove old installation if it exists
262-
if [[ -d "/Applications/Cleanuparr.app" ]]; then
263-
rm -rf "/Applications/Cleanuparr.app"
264-
fi
349+
echo "Removing service files..."
350+
rm -f /Library/LaunchDaemons/com.cleanuparr.daemon.plist
265351
266-
exit 0
352+
echo "Removing application..."
353+
rm -rf /Applications/Cleanuparr.app
354+
355+
echo "Removing logs..."
356+
rm -f /var/log/cleanuparr.log
357+
rm -f /var/log/cleanuparr.error.log
358+
359+
echo "Cleanuparr has been completely removed."
360+
echo "Note: Configuration files in /Applications/Cleanuparr.app/Contents/MacOS/config/ have been removed with the app."
267361
EOF
268362
269-
chmod +x scripts/preinstall
363+
chmod +x scripts/uninstall_cleanuparr.sh
364+
365+
# Copy uninstall script to app bundle for user access
366+
cp scripts/uninstall_cleanuparr.sh dist/Cleanuparr.app/Contents/Resources/
270367
271368
# Determine package name
272369
if [[ "${{ github.ref }}" =~ ^refs/tags/ ]]; then

0 commit comments

Comments
 (0)