Add application configuration prompt for already-optimized systems
- Add check for application configuration when system is already optimized - Prompt user to configure apps even if tmpfs mounts already exist - Create standalone configure-apps-for-tmpfs.sh script - Detect if applications are already configured (Firefox prefs check) - Skip redundant configuration attempts with 'already configured' messages - Add backup timestamp to avoid overwriting previous backups - Update README with new configuration script Benefits: - Users with existing tmpfs can now configure applications - Standalone script allows re-configuration without full optimizer run - Smarter detection prevents duplicate configurations - Better user experience for incremental optimization
This commit is contained in:
@@ -19,6 +19,7 @@ The **one-button optimizer** is an intelligent, interactive system optimizer tha
|
||||
### Quick Tools
|
||||
|
||||
- `./one-button-optimizer.sh` - **Main interactive optimizer** (recommended)
|
||||
- `./configure-apps-for-tmpfs.sh` - **Configure applications** to use tmpfs caches (browsers, dev tools)
|
||||
- `./quick-status-check.sh` - **Quick system status** overview (no changes)
|
||||
- `./tmpfs-info.sh` - **Detailed tmpfs information** and configuration guide
|
||||
- `./launcher.sh` - **Auto-sudo launcher** for the optimizer
|
||||
|
||||
261
configure-apps-for-tmpfs.sh
Executable file
261
configure-apps-for-tmpfs.sh
Executable file
@@ -0,0 +1,261 @@
|
||||
#!/bin/bash
|
||||
# Configure applications to use tmpfs caches
|
||||
# Run this after setting up tmpfs mounts to automatically configure your apps
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check if running as root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
error "This script must be run as root (use sudo)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🔧 Application tmpfs Cache Configurator"
|
||||
echo "======================================="
|
||||
echo ""
|
||||
|
||||
# Check if tmpfs mounts exist
|
||||
if ! mount | grep -q "tmpfs.*tmpfs-cache"; then
|
||||
error "No tmpfs-cache mounts found!"
|
||||
echo "Please run the optimizer first: sudo ./one-button-optimizer.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Found tmpfs cache mounts:"
|
||||
mount | grep "tmpfs.*tmpfs-cache" | awk '{print " • " $3}'
|
||||
echo ""
|
||||
|
||||
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
|
||||
# Check if already configured
|
||||
if grep -q "tmpfs-cache" "$prefs_file" 2>/dev/null; then
|
||||
log " ℹ️ Firefox already configured"
|
||||
((configured_count++))
|
||||
continue
|
||||
fi
|
||||
|
||||
# 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"
|
||||
if [[ -f "$desktop_file" ]] && grep -q "tmpfs-cache" "$desktop_file" 2>/dev/null; then
|
||||
log " ℹ️ Chrome already configured"
|
||||
((configured_count++))
|
||||
continue
|
||||
fi
|
||||
|
||||
mkdir -p "$user_home/.local/share/applications"
|
||||
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"
|
||||
if [[ -f "$desktop_file" ]] && grep -q "tmpfs-cache" "$desktop_file" 2>/dev/null; then
|
||||
log " ℹ️ Chromium already configured"
|
||||
((configured_count++))
|
||||
continue
|
||||
fi
|
||||
|
||||
mkdir -p "$user_home/.local/share/applications"
|
||||
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"
|
||||
|
||||
if [[ -f "$brave_desktop" ]] && grep -q "tmpfs-cache" "$brave_desktop" 2>/dev/null; then
|
||||
log " ℹ️ Brave already configured"
|
||||
((configured_count++))
|
||||
else
|
||||
mkdir -p "$user_home/.local/share/applications"
|
||||
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
|
||||
fi
|
||||
|
||||
# Development Tools Configuration
|
||||
echo ""
|
||||
echo "💻 Configuring Development Tools:"
|
||||
|
||||
# NPM
|
||||
if command -v npm &>/dev/null; then
|
||||
local npm_cache=$(sudo -u $current_user npm config get cache 2>/dev/null)
|
||||
if [[ "$npm_cache" == *"tmpfs-cache"* ]]; then
|
||||
log " ℹ️ NPM already configured"
|
||||
((configured_count++))
|
||||
else
|
||||
sudo -u $current_user npm config set cache /tmp/tmpfs-cache/development/npm 2>/dev/null && \
|
||||
success " ✅ NPM cache configured" && ((configured_count++))
|
||||
fi
|
||||
fi
|
||||
|
||||
# Pip
|
||||
if command -v pip3 &>/dev/null || command -v pip &>/dev/null; then
|
||||
if [[ -f "$user_home/.config/pip/pip.conf" ]] && grep -q "tmpfs-cache" "$user_home/.config/pip/pip.conf" 2>/dev/null; then
|
||||
log " ℹ️ Pip already configured"
|
||||
((configured_count++))
|
||||
else
|
||||
mkdir -p "$user_home/.config/pip"
|
||||
cat > "$user_home/.config/pip/pip.conf" << 'PIPEOF'
|
||||
[global]
|
||||
cache-dir = /tmp/tmpfs-cache/development/pip
|
||||
PIPEOF
|
||||
chown -R $current_user:$current_user "$user_home/.config/pip" 2>/dev/null || true
|
||||
success " ✅ Pip cache configured" && ((configured_count++))
|
||||
fi
|
||||
fi
|
||||
|
||||
# KDE/Plasma Configuration
|
||||
if [[ "$XDG_CURRENT_DESKTOP" == *"KDE"* ]] || [[ "$DESKTOP_SESSION" == *"plasma"* ]]; then
|
||||
echo ""
|
||||
echo "🖥️ Configuring KDE/Plasma:"
|
||||
|
||||
# Link thumbnails
|
||||
if [[ -L "$user_home/.cache/thumbnails" ]] && [[ "$(readlink -f "$user_home/.cache/thumbnails")" == *"tmpfs-cache"* ]]; then
|
||||
log " ℹ️ KDE thumbnails already configured"
|
||||
((configured_count++))
|
||||
else
|
||||
if [[ -d "$user_home/.cache/thumbnails" ]] && [[ ! -L "$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
|
||||
fi
|
||||
|
||||
echo ""
|
||||
if [[ $configured_count -gt 0 ]]; then
|
||||
success "🎉 Configured/verified $configured_count applications!"
|
||||
echo ""
|
||||
log "💡 Restart the configured applications to use tmpfs caches"
|
||||
echo ""
|
||||
echo "📊 Check cache usage with: df -h /tmp/tmpfs-cache/*"
|
||||
else
|
||||
log "ℹ️ No applications detected for automatic configuration"
|
||||
echo ""
|
||||
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
|
||||
}
|
||||
|
||||
# Run the configuration
|
||||
configure_applications_for_tmpfs
|
||||
|
||||
echo ""
|
||||
success "✅ Configuration complete!"
|
||||
@@ -550,6 +550,34 @@ analyze_and_prompt() {
|
||||
echo " df -h /tmp/tmpfs-cache/* # Check tmpfs usage"
|
||||
echo " swapon --show # Check zram status"
|
||||
echo ""
|
||||
|
||||
# Check if applications are already configured for tmpfs
|
||||
local current_user=$(logname 2>/dev/null || echo $SUDO_USER)
|
||||
local user_home=$(eval echo ~$current_user)
|
||||
local apps_configured=false
|
||||
|
||||
# Quick check if browsers are configured
|
||||
if [[ -f "$user_home/.mozilla/firefox"/*default*/prefs.js ]] && \
|
||||
grep -q "tmpfs-cache" "$user_home/.mozilla/firefox"/*default*/prefs.js 2>/dev/null; then
|
||||
apps_configured=true
|
||||
fi
|
||||
|
||||
if [[ ! $apps_configured ]]; then
|
||||
echo "📱 Application Configuration:"
|
||||
echo " ⚠️ Your applications are not yet configured to use tmpfs caches"
|
||||
echo ""
|
||||
read -p " Would you like to automatically configure your browsers and dev tools? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo ""
|
||||
configure_applications_for_tmpfs
|
||||
echo ""
|
||||
success "Configuration complete! Restart your applications to use tmpfs caches."
|
||||
fi
|
||||
else
|
||||
echo " ✅ Applications are configured to use tmpfs caches"
|
||||
fi
|
||||
echo ""
|
||||
echo "🎯 Your system is fully optimized for maximum performance!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user