Skip to content

Commit 8b17767

Browse files
committed
Error exit safeguard
1 parent 2a23735 commit 8b17767

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

scripts/proactive-disk-cleanup.sh

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# This script intelligently manages disk space by performing adaptive cleanup
55
# based on available space and removing unnecessary packages/directories.
66

7-
set -e
7+
# Note: Using best-effort approach - don't exit on cleanup failures
8+
# set -e
89

910
echo "=============================================="
1011
echo "🧹 PROACTIVE DISK SPACE MANAGEMENT"
@@ -33,8 +34,18 @@ else
3334
fi
3435

3536
echo "=== Cleaning package caches ==="
36-
sudo apt-get clean
37-
sudo apt-get autoremove -y --purge
37+
# Best-effort package cache cleanup - don't fail if apt is locked
38+
if sudo apt-get clean 2>/dev/null; then
39+
echo "✅ Package cache cleaned successfully"
40+
else
41+
echo "⚠️ Could not clean package cache (apt may be locked by another process)"
42+
fi
43+
44+
if sudo apt-get autoremove -y --purge 2>/dev/null; then
45+
echo "✅ Unused packages removed successfully"
46+
else
47+
echo "⚠️ Could not remove unused packages (apt may be locked by another process)"
48+
fi
3849

3950
echo "=== Checking installed packages that consume significant space ==="
4051
LARGE_PACKAGES="mysql-server-core-8.0 mysql-client-core-8.0 postgresql-14 postgresql-client-14 firefox google-chrome-stable microsoft-edge-stable thunderbird mono-complete azure-cli powershell kubectl helm"
@@ -119,8 +130,18 @@ echo "=== Docker cleanup ==="
119130
docker system prune -af --volumes || true
120131

121132
echo "=== Final cleanup ==="
122-
sudo apt-get autoremove -y --purge
123-
sudo apt-get autoclean
133+
# Best-effort final cleanup
134+
if sudo apt-get autoremove -y --purge 2>/dev/null; then
135+
echo "✅ Final autoremove completed successfully"
136+
else
137+
echo "⚠️ Could not complete final autoremove (apt may be locked)"
138+
fi
139+
140+
if sudo apt-get autoclean 2>/dev/null; then
141+
echo "✅ Package cache autoclean completed successfully"
142+
else
143+
echo "⚠️ Could not complete autoclean (apt may be locked)"
144+
fi
124145

125146
echo "=== Cleanup Summary ==="
126147
df -h
@@ -137,6 +158,8 @@ echo "└─ /tmp partition: $(df -h /tmp | tail -1 | awk '{print $4}') free"
137158

138159
echo ""
139160
echo "=== Validating minimum space requirement ==="
161+
# Re-enable strict error handling for final validation
162+
set -e
140163
if [ $FINAL_AVAILABLE_GB -lt 8 ]; then
141164
echo "❌ ERROR: Insufficient disk space (${FINAL_AVAILABLE_GB}GB). Need at least 8GB for kind cluster."
142165
echo "Available space breakdown:"

0 commit comments

Comments
 (0)