#!/bin/bash
Check if a keyword is provided
if [ -z “$1” ]; then
echo “Error: Please provide the backup keyword.”
echo “Usage: $0 ”
exit 1
fi
KEYWORD=“$1”
BACKUP_DIR=“/home/greg/Documents/backup/desktops/plasma_backup_${KEYWORD}”
Check if backup directory exists
if [ ! -d “$BACKUP_DIR” ]; then
echo “Error: Backup directory $BACKUP_DIR does not exist.”
exit 1
fi
List of expected files/directories with their original paths
declare -A CONFIG_FILES=(
[“plasma-org.kde.plasma.desktop-appletsrc”]=“$HOME/.config/plasma-org.kde.plasma.desktop-appletsrc”
[“kdeglobals”]=“$HOME/.config/kdeglobals”
[“plasmarc”]=“$HOME/.config/plasmarc”
[“kwinrc”]=“$HOME/.config/kwinrc”
[“kscreenrc”]=“$HOME/.config/kscreenrc”
[“plasma”]=“$HOME/.local/share/plasma”
[“desktoptheme”]=“$HOME/.local/share/plasma/desktoptheme”
[“icons”]=“$HOME/.local/share/icons”
[“applications”]=“$HOME/.local/share/applications”
)
Restore files by removing the keyword prefix
for KEY in “${!CONFIG_FILES[@]}”; do
for FILE in “$BACKUP_DIR”/*_“$KEY”; do
if [ -e “$FILE” ]; then
DEST=“${CONFIG_FILES[$KEY]}”
mkdir -p “$(dirname “$DEST”)”
cp -r “$FILE” “$DEST” && echo “Restored $FILE to $DEST” || echo “Error: Failed to restore $FILE”
else
echo “Warning: No backup found for $KEY in $BACKUP_DIR”
fi
done
done
Restore application launcher icon settings
if ls “$BACKUP_DIR”/${KEYWORD}launcher_icon_settings.txt >/dev/null 2>&1; then
for LAUNCHER_SETTINGS in “$BACKUP_DIR”/${KEYWORD}launcher_icon_settings.txt; do
echo “Found launcher settings at $LAUNCHER_SETTINGS”
# Extract icon setting
ICON=$(grep “icon=” “$LAUNCHER_SETTINGS” | cut -d’=’ -f2)
if [ -n “$ICON” ]; then
# Find the applet ID for org.kde.plasma.kickoff
APPLET_ID=$(grep -B 5 “plugin=org.kde.plasma.kickoff” “$HOME/.config/plasma-org.kde.plasma.desktop-appletsrc” | grep -o “[Containments][[0-9]][Applets][[0-9]]” | head -1)
if [ -n “$APPLET_ID” ]; then
kwriteconfig5 --file “$HOME/.config/plasma-org.kde.plasma.desktop-appletsrc” --group “$APPLET_ID” --group “Configuration” --group “General” --key “icon” “$ICON”
echo “Applied launcher icon: $ICON”
else
echo “Warning: Could not find applet ID for org.kde.plasma.kickoff. Manual merge into $HOME/.config/plasma-org.kde.plasma.desktop-appletsrc required.”
fi
else
echo “Warning: No icon setting found in $LAUNCHER_SETTINGS”
fi
done
else
echo “Warning: No launcher settings found in $BACKUP_DIR”
fi
Clear Plasma cache
rm -rf “$HOME/.cache/*” && echo “Cleared Plasma cache” || echo “Error: Failed to clear cache”
Extract and apply the global theme
GLOBAL_THEME=“”
if [ -f “$HOME/.config/kdeglobals” ]; then
GLOBAL_THEME=$(grep “LookAndFeelPackage=” “$HOME/.config/kdeglobals” | cut -d’=’ -f2)
fi
if [ -n “$GLOBAL_THEME” ] && command -v plasma-apply-lookandfeel >/dev/null 2>&1; then
echo “Found global theme: $GLOBAL_THEME”
plasma-apply-lookandfeel -a “$GLOBAL_THEME” && echo “Applied global theme: $GLOBAL_THEME” || echo “Error: Failed to apply global theme $GLOBAL_THEME”
else
echo “Warning: Could not determine global theme or plasma-apply-lookandfeel not found. Falling back to desktop theme.”
Try desktop theme as fallback
DESKTOP_THEME=“”
if [ -f “$HOME/.config/plasmarc” ]; then
DESKTOP_THEME=$(grep “theme=” “$HOME/.config/plasmarc” | cut -d’=’ -f2)
fi
if [ -z “$DESKTOP_THEME” ] && [ -f “$HOME/.config/kdeglobals” ]; then
DESKTOP_THEME=$(grep “plasmaTheme=” “$HOME/.config/kdeglobals” | cut -d’=’ -f2)
fi
if [ -n “$DESKTOP_THEME” ] && command -v plasma-apply-desktoptheme >/dev/null 2>&1; then
echo “Found desktop theme: $DESKTOP_THEME”
plasma-apply-desktoptheme “$DESKTOP_THEME” && echo “Applied desktop theme: $DESKTOP_THEME” || echo “Error: Failed to apply desktop theme $DESKTOP_THEME”
else
echo “Warning: Could not determine desktop theme or plasma-apply-desktoptheme not found. Try manually applying the theme via System Settings.”
fi
fi
Apply icon theme
ICON_THEME=“”
if [ -f “$HOME/.config/kdeglobals” ]; then
ICON_THEME=$(grep “Theme=” “$HOME/.config/kdeglobals” | grep -v “ColorScheme” | cut -d’=’ -f2)
fi
if [ -n “$ICON_THEME” ] && command -v plasma-apply-icontheme >/dev/null 2>&1; then
echo “Found icon theme: $ICON_THEME”
plasma-apply-icontheme “$ICON_THEME” && echo “Applied icon theme: $ICON_THEME” || echo “Error: Failed to apply icon theme $ICON_THEME”
elif [ -n “$ICON_THEME” ]; then
kwriteconfig5 --file “$HOME/.config/kdeglobals” --group “Icons” --key “Theme” “$ICON_THEME” && echo “Set icon theme via kwriteconfig5: $ICON_THEME” || echo “Error: Failed to set icon theme via kwriteconfig5”
else
echo “Warning: Could not determine icon theme or plasma-apply-icontheme not found”
fi
Apply cursor theme
CURSOR_THEME=“”
if [ -f “$HOME/.config/kdeglobals” ]; then
CURSOR_THEME=$(grep “cursorThemeName=” “$HOME/.config/kdeglobals” | cut -d’=’ -f2)
fi
if [ -n “$CURSOR_THEME” ] && command -v plasma-apply-cursortheme >/dev/null 2>&1; then
echo “Found cursor theme: $CURSOR_THEME”
plasma-apply-cursortheme “$CURSOR_THEME” && echo “Applied cursor theme: $CURSOR_THEME” || echo “Error: Failed to apply cursor theme $CURSOR_THEME”
elif [ -n “$CURSOR_THEME” ]; then
kwriteconfig5 --file “$HOME/.config/kdeglobals” --group “KDE” --key “cursorThemeName” “$CURSOR_THEME” && echo “Set cursor theme via kwriteconfig5: $CURSOR_THEME” || echo “Error: Failed to set cursor theme via kwriteconfig5”
else
echo “Warning: Could not determine cursor theme or plasma-apply-cursortheme not found”
fi
Restart Plasma
kquitapp5 plasmashell && echo “Stopped plasmashell” || echo “Error: Failed to stop plasmashell”
sleep 2
kstart5 plasmashell && echo “Restarted plasmashell” || echo “Error: Failed to restart plasmashell”
echo “Restore completed from $BACKUP_DIR”