Fix browser detection and remove standalone configuration script
- Rewrite browser detection to check config directories instead of commands - Fix Brave browser detection and configuration (was not being reported) - Add proper support for Chromium installed via snap - Separate detection for each browser (Firefox, Brave, Chrome, Chromium) - Each browser now reports configuration success individually - Remove standalone configure-apps-for-tmpfs.sh script per user request - Keep all functionality in the all-in-one optimizer script - Update README to remove reference to standalone script Fixes: - Brave browser now properly detected via ~/.config/BraveSoftware - Chromium detected even when installed as snap package - All browsers report their configuration status - Cleaner, more reliable directory-based detection
This commit is contained in:
@@ -19,7 +19,6 @@ The **one-button optimizer** is an intelligent, interactive system optimizer tha
|
|||||||
### Quick Tools
|
### Quick Tools
|
||||||
|
|
||||||
- `./one-button-optimizer.sh` - **Main interactive optimizer** (recommended)
|
- `./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)
|
- `./quick-status-check.sh` - **Quick system status** overview (no changes)
|
||||||
- `./tmpfs-info.sh` - **Detailed tmpfs information** and configuration guide
|
- `./tmpfs-info.sh` - **Detailed tmpfs information** and configuration guide
|
||||||
- `./launcher.sh` - **Auto-sudo launcher** for the optimizer
|
- `./launcher.sh` - **Auto-sudo launcher** for the optimizer
|
||||||
|
|||||||
@@ -1,261 +0,0 @@
|
|||||||
#!/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!"
|
|
||||||
@@ -895,60 +895,12 @@ configure_applications_for_tmpfs() {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Chrome/Chromium
|
# Brave Browser
|
||||||
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
|
if [[ -d "$user_home/.config/BraveSoftware" ]]; then
|
||||||
mkdir -p /tmp/tmpfs-cache/browser/brave
|
mkdir -p /tmp/tmpfs-cache/browser/brave
|
||||||
|
mkdir -p "$user_home/.local/share/applications"
|
||||||
|
chown -R $current_user:$current_user /tmp/tmpfs-cache/browser/brave
|
||||||
|
|
||||||
local brave_desktop="$user_home/.local/share/applications/brave-browser.desktop"
|
local brave_desktop="$user_home/.local/share/applications/brave-browser.desktop"
|
||||||
cat > "$brave_desktop" << 'BRAVEEOF'
|
cat > "$brave_desktop" << 'BRAVEEOF'
|
||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
@@ -964,7 +916,57 @@ MimeType=text/html;text/xml;application/xhtml+xml;x-scheme-handler/http;x-scheme
|
|||||||
BRAVEEOF
|
BRAVEEOF
|
||||||
chown $current_user:$current_user "$brave_desktop" 2>/dev/null || true
|
chown $current_user:$current_user "$brave_desktop" 2>/dev/null || true
|
||||||
chmod +x "$brave_desktop" 2>/dev/null || true
|
chmod +x "$brave_desktop" 2>/dev/null || true
|
||||||
success " ✅ Brave configured to use tmpfs cache"
|
success " ✅ Brave Browser configured to use tmpfs cache"
|
||||||
|
((configured_count++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Google Chrome
|
||||||
|
if [[ -d "$user_home/.config/google-chrome" ]]; then
|
||||||
|
mkdir -p /tmp/tmpfs-cache/browser/google-chrome
|
||||||
|
mkdir -p "$user_home/.local/share/applications"
|
||||||
|
chown -R $current_user:$current_user /tmp/tmpfs-cache/browser/google-chrome
|
||||||
|
|
||||||
|
local chrome_desktop="$user_home/.local/share/applications/google-chrome.desktop"
|
||||||
|
cat > "$chrome_desktop" << '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
|
||||||
|
chown $current_user:$current_user "$chrome_desktop" 2>/dev/null || true
|
||||||
|
chmod +x "$chrome_desktop" 2>/dev/null || true
|
||||||
|
success " ✅ Google Chrome configured to use tmpfs cache"
|
||||||
|
((configured_count++))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Chromium
|
||||||
|
if [[ -d "$user_home/.config/chromium" ]]; then
|
||||||
|
mkdir -p /tmp/tmpfs-cache/browser/chromium
|
||||||
|
mkdir -p "$user_home/.local/share/applications"
|
||||||
|
chown -R $current_user:$current_user /tmp/tmpfs-cache/browser/chromium
|
||||||
|
|
||||||
|
local chromium_desktop="$user_home/.local/share/applications/chromium-browser.desktop"
|
||||||
|
cat > "$chromium_desktop" << '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
|
||||||
|
chown $current_user:$current_user "$chromium_desktop" 2>/dev/null || true
|
||||||
|
chmod +x "$chromium_desktop" 2>/dev/null || true
|
||||||
|
success " ✅ Chromium configured to use tmpfs cache"
|
||||||
((configured_count++))
|
((configured_count++))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user