Add automatic application configuration for tmpfs caches

- Auto-detect and configure Firefox cache location in prefs.js
- Auto-create optimized .desktop launchers for Chrome/Chromium/Brave
- Auto-configure NPM and Pip cache directories
- Auto-link KDE/Plasma thumbnail cache to tmpfs
- Add configure_applications_for_tmpfs() function with smart detection
- Backup original configs before modification
- Set proper ownership and permissions for all cache directories
- Replace manual setup instructions with automatic configuration
- Show progress of configured applications with count
- Update next steps to reflect automatic setup

Benefits:
- Zero post-setup manual configuration needed
- Immediate performance improvement on app restart
- Safer with automatic backups and proper permissions
- Better user experience with clear progress reporting
This commit is contained in:
mindesbunister
2025-10-06 09:25:01 +02:00
parent 548dc1d0d3
commit 8e5e370e09
2 changed files with 203 additions and 35 deletions

View File

@@ -809,10 +809,13 @@ EOF
success "tmpfs cache optimization enabled ($profile profile)"
# Show detailed information about what was set up
# Automatically configure detected applications
configure_applications_for_tmpfs
# Show summary of what was configured
echo ""
echo "📋 tmpfs Setup Details:"
echo "======================"
echo "📋 tmpfs Setup Complete:"
echo "======================="
echo ""
echo "🔧 Created tmpfs mount points:"
mount | grep "tmpfs.*tmpfs-cache" | while read -r line; do
@@ -821,41 +824,173 @@ EOF
echo " 📁 $mount_point - Size: $size"
done
echo ""
echo "💡 How to use these optimizations:"
echo ""
echo "🌐 Browser Cache (/tmp/tmpfs-cache/browser):"
echo " • Chrome: Set cache to /tmp/tmpfs-cache/browser/chrome"
echo " • Firefox: Set cache to /tmp/tmpfs-cache/browser/firefox"
echo " • Manual: ln -sf /tmp/tmpfs-cache/browser ~/.cache/browser-backup"
echo ""
echo "💻 Development Cache (/tmp/tmpfs-cache/development):"
echo " • NPM: npm config set cache /tmp/tmpfs-cache/development/npm"
echo " • Pip: export PIP_CACHE_DIR=/tmp/tmpfs-cache/development/pip"
echo " • Docker: Configure build cache to use this mount"
echo ""
echo "🎨 IDE Cache (/tmp/tmpfs-cache/ide):"
echo " • VS Code: Link ~/.vscode to /tmp/tmpfs-cache/ide/vscode"
echo " • JetBrains: Configure temp/cache directories"
echo ""
if [[ "$XDG_CURRENT_DESKTOP" == *"KDE"* ]] || [[ "$DESKTOP_SESSION" == *"plasma"* ]]; then
echo "🖥️ KDE Cache (/tmp/tmpfs-cache/kde):"
echo " • Baloo: kwriteconfig5 --file baloofilerc --group 'Basic Settings' --key 'Indexing-Enabled' false"
echo " • Thumbnails: Link ~/.cache/thumbnails to /tmp/tmpfs-cache/kde/thumbnails"
echo " • Plasma cache: Automatically used by system"
echo ""
fi
echo "📦 Package Cache (Automatically configured):"
echo " • APT cache is already bound to /var/cache/apt → tmpfs"
echo " • Reduces SSD wear during package operations"
echo ""
echo "⚡ Performance Benefits:"
echo " • 🚀 Faster cache access (RAM speed vs SSD)"
echo " • <EFBFBD> Faster cache access (RAM speed vs SSD)"
echo " • 💿 Reduced SSD wear and tear"
echo " • 🧹 Automatic cleanup on reboot"
echo " • 🔋 Lower power consumption for cache operations"
}
configure_applications_for_tmpfs() {
log "Auto-configuring applications to use tmpfs caches..."
echo ""
local configured_count=0
local current_user=$(logname 2>/dev/null || echo $SUDO_USER)
local user_home=$(eval echo ~$current_user)
# Browser Configuration
echo "🌐 Configuring Browsers:"
# Firefox
for firefox_profile in "$user_home"/.mozilla/firefox/*.default* "$user_home"/.mozilla/firefox/*.default-release*; do
if [[ -d "$firefox_profile" ]]; then
local prefs_file="$firefox_profile/prefs.js"
if [[ -f "$prefs_file" ]]; then
# Backup original
cp "$prefs_file" "$prefs_file.backup.$(date +%s)" 2>/dev/null || true
# Remove old cache settings
sed -i '/browser.cache.disk.parent_directory/d' "$prefs_file" 2>/dev/null || true
# Add new cache location
echo 'user_pref("browser.cache.disk.parent_directory", "/tmp/tmpfs-cache/browser/firefox");' >> "$prefs_file"
# Create cache directory
mkdir -p /tmp/tmpfs-cache/browser/firefox
chown -R $current_user:$current_user /tmp/tmpfs-cache/browser/firefox
success " ✅ Firefox configured to use tmpfs cache"
((configured_count++))
fi
fi
done
# Chrome/Chromium
if command -v google-chrome &>/dev/null || command -v chromium &>/dev/null; then
local chrome_dir="$user_home/.config/google-chrome"
local chromium_dir="$user_home/.config/chromium"
for browser_dir in "$chrome_dir" "$chromium_dir"; do
if [[ -d "$browser_dir" ]]; then
local browser_name=$(basename "$browser_dir")
mkdir -p /tmp/tmpfs-cache/browser/$browser_name
# Create wrapper script to launch with cache dir
local desktop_file=""
if [[ "$browser_name" == "google-chrome" ]]; then
desktop_file="$user_home/.local/share/applications/google-chrome.desktop"
cat > "$desktop_file" << 'CHROMEOF'
[Desktop Entry]
Version=1.0
Name=Google Chrome (tmpfs optimized)
Exec=google-chrome --disk-cache-dir=/tmp/tmpfs-cache/browser/google-chrome %U
StartupNotify=true
Terminal=false
Icon=google-chrome
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;
CHROMEOF
else
desktop_file="$user_home/.local/share/applications/chromium.desktop"
cat > "$desktop_file" << 'CHROMIUMEOF'
[Desktop Entry]
Version=1.0
Name=Chromium (tmpfs optimized)
Exec=chromium --disk-cache-dir=/tmp/tmpfs-cache/browser/chromium %U
StartupNotify=true
Terminal=false
Icon=chromium
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;
CHROMIUMEOF
fi
chown $current_user:$current_user "$desktop_file" 2>/dev/null || true
chmod +x "$desktop_file" 2>/dev/null || true
success "$browser_name configured to use tmpfs cache"
((configured_count++))
fi
done
fi
# Brave
if [[ -d "$user_home/.config/BraveSoftware" ]]; then
mkdir -p /tmp/tmpfs-cache/browser/brave
local brave_desktop="$user_home/.local/share/applications/brave-browser.desktop"
cat > "$brave_desktop" << 'BRAVEEOF'
[Desktop Entry]
Version=1.0
Name=Brave Browser (tmpfs optimized)
Exec=brave-browser --disk-cache-dir=/tmp/tmpfs-cache/browser/brave %U
StartupNotify=true
Terminal=false
Icon=brave-browser
Type=Application
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme-handler/https;
BRAVEEOF
chown $current_user:$current_user "$brave_desktop" 2>/dev/null || true
chmod +x "$brave_desktop" 2>/dev/null || true
success " ✅ Brave configured to use tmpfs cache"
((configured_count++))
fi
# Development Tools Configuration
echo ""
echo "💻 Configuring Development Tools:"
# NPM
if command -v npm &>/dev/null; then
sudo -u $current_user npm config set cache /tmp/tmpfs-cache/development/npm 2>/dev/null && \
success " ✅ NPM cache configured" && ((configured_count++))
fi
# Pip
if command -v pip3 &>/dev/null || command -v pip &>/dev/null; then
mkdir -p "$user_home/.config/pip"
cat > "$user_home/.config/pip/pip.conf" << 'PIPEOF'
[global]
cache-dir = /tmp/tmpfs-cache/development/pip
PIPEOF
chown $current_user:$current_user "$user_home/.config/pip/pip.conf" 2>/dev/null || true
success " ✅ Pip cache configured" && ((configured_count++))
fi
# KDE/Plasma Configuration
if [[ "$XDG_CURRENT_DESKTOP" == *"KDE"* ]] || [[ "$DESKTOP_SESSION" == *"plasma"* ]]; then
echo ""
echo "🖥️ Configuring KDE/Plasma:"
# Link thumbnails
if [[ -d "$user_home/.cache/thumbnails" ]]; then
mv "$user_home/.cache/thumbnails" "$user_home/.cache/thumbnails.backup.$(date +%s)" 2>/dev/null || true
fi
mkdir -p /tmp/tmpfs-cache/kde/thumbnails
ln -sf /tmp/tmpfs-cache/kde/thumbnails "$user_home/.cache/thumbnails"
chown -R $current_user:$current_user /tmp/tmpfs-cache/kde/thumbnails
success " ✅ KDE thumbnail cache linked to tmpfs"
((configured_count++))
fi
echo ""
if [[ $configured_count -gt 0 ]]; then
success "🎉 Automatically configured $configured_count applications!"
echo ""
log "💡 Changes will take effect when you restart the configured applications"
else
log " No applications detected for automatic configuration"
echo " You can manually configure other applications to use:"
echo " • Browser cache: /tmp/tmpfs-cache/browser/"
echo " • Dev tools: /tmp/tmpfs-cache/development/"
echo " • IDE cache: /tmp/tmpfs-cache/ide/"
fi
}
tune_kernel() {
if [[ $SETUP_KERNEL != true ]]; then
return 0
@@ -1034,10 +1169,10 @@ show_final_status() {
echo ""
echo "🎯 Next Steps:"
echo " 1. <EFBFBD> Reboot to ensure all optimizations persist"
echo " 2. 🌐 Configure applications to use tmpfs caches (see details above)"
echo " 3. 📊 Monitor usage: df -h | grep tmpfs-cache"
echo " 4. 🔍 Check status anytime: ./quick-status-check.sh"
echo " 1. 🔄 Restart configured applications (browsers, IDEs) to use new cache locations"
echo " 2. 📊 Monitor cache usage: df -h | grep tmpfs-cache"
echo " 3. 🔍 Check status anytime: ./quick-status-check.sh"
echo " 4. <EFBFBD> Optional: Reboot to verify all optimizations persist"
echo ""
echo "💡 Useful Commands:"
echo " • Check tmpfs usage: df -h /tmp/tmpfs-cache/*"