109 lines
3.5 KiB
Bash
109 lines
3.5 KiB
Bash
#!/bin/sh
|
|
# backup-rice.sh - export desktop customization so a reinstall can restore it.
|
|
# Run as your normal user, inside the desktop session (dconf needs the session bus).
|
|
# Usage: sh backup-rice.sh [output-dir] (default: ~/rice-export)
|
|
|
|
set -e
|
|
|
|
[ "$(id -u)" -ne 0 ] || { echo "Run this as your normal user, not root."; exit 1; }
|
|
|
|
OUT="${1:-$HOME/rice-export}"
|
|
mkdir -p "$OUT"
|
|
RICE_LIST="$OUT/.rice-files.txt"
|
|
: > "$RICE_LIST"
|
|
|
|
# add <path relative to $HOME> (skipped if it doesn't exist)
|
|
add () {
|
|
if [ -e "$HOME/$1" ]; then
|
|
echo "$1" >> "$RICE_LIST"
|
|
fi
|
|
}
|
|
|
|
# Turn a file:// URI or plain path into a path relative to $HOME.
|
|
# Prints nothing for paths outside $HOME, files under ~/.cache, or missing files.
|
|
rel_home () {
|
|
p="$1"
|
|
p=${p#file://}
|
|
p=$(printf '%s' "$p" | sed 's/%20/ /g')
|
|
case "$p" in
|
|
"$HOME"/.cache/*) ;;
|
|
"$HOME"/*)
|
|
p=${p#"$HOME"/}
|
|
[ -f "$HOME/$p" ] && printf '%s\n' "$p"
|
|
;;
|
|
esac
|
|
return 0
|
|
}
|
|
|
|
# dump <dconf path> <name> (skipped if dconf is missing or the path is empty)
|
|
# The home directory is replaced with __HOME__ so the file works for any username.
|
|
dump () {
|
|
if command -v dconf >/dev/null 2>&1; then
|
|
data=$(dconf dump "$1" 2>/dev/null || true)
|
|
if [ -n "$data" ]; then
|
|
printf '%s\n' "$data" | sed "s#$HOME#__HOME__#g" > "$OUT/$2.dconf"
|
|
echo " settings: $1 -> $2.dconf"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
echo "Exporting to $OUT"
|
|
|
|
# ---------- desktop settings (dconf) ----------
|
|
dump /org/cinnamon/ cinnamon
|
|
dump /org/nemo/ nemo
|
|
dump /org/gnome/terminal/ terminal
|
|
|
|
# ---------- themes, icons, fonts, applets, GTK config ----------
|
|
for p in \
|
|
.themes .icons \
|
|
.local/share/themes .local/share/icons .local/share/fonts \
|
|
.local/share/cinnamon .config/cinnamon/spices \
|
|
.config/gtk-3.0/settings.ini .config/gtk-3.0/gtk.css \
|
|
.config/gtk-4.0/settings.ini .config/gtk-4.0/gtk.css \
|
|
.gtkrc-2.0 .config/fontconfig
|
|
do
|
|
add "$p"
|
|
done
|
|
|
|
# ---------- current wallpaper (skipped when it points into ~/.cache) ----------
|
|
BG=$(gsettings get org.cinnamon.desktop.background picture-uri 2>/dev/null || true)
|
|
BG=${BG#\'}
|
|
BG=${BG%\'}
|
|
rel=$(rel_home "$BG")
|
|
[ -z "$rel" ] || echo "$rel" >> "$RICE_LIST"
|
|
|
|
# ---------- Hydrapaper ----------
|
|
if command -v hydrapaper >/dev/null 2>&1 || [ -d "$HOME/.config/hydrapaper" ]; then
|
|
echo "Hydrapaper found"
|
|
dump /org/gabmus/hydrapaper/ hydrapaper
|
|
add .config/hydrapaper
|
|
add .local/share/hydrapaper
|
|
add .var/app/org.gabmus.hydrapaper
|
|
|
|
# Find the source images it merges: any image path in its settings or config files.
|
|
# (The dconf file holds __HOME__ now, so swap the real path back in for this scan.)
|
|
CANDIDATES=$( {
|
|
[ -f "$OUT/hydrapaper.dconf" ] && sed "s#__HOME__#$HOME#g" "$OUT/hydrapaper.dconf"
|
|
find "$HOME/.config/hydrapaper" "$HOME/.local/share/hydrapaper" -type f -exec cat {} + 2>/dev/null
|
|
} | grep -aoE "(file://)?/[^'\",]+\.(png|jpe?g|webp|bmp)" || true )
|
|
|
|
printf '%s\n' "$CANDIDATES" | while IFS= read -r uri; do
|
|
[ -n "$uri" ] || continue
|
|
rel=$(rel_home "$uri")
|
|
[ -z "$rel" ] || echo "$rel" >> "$RICE_LIST"
|
|
done
|
|
else
|
|
echo "Hydrapaper not installed, skipping"
|
|
fi
|
|
|
|
# ---------- build the archive ----------
|
|
if [ -s "$RICE_LIST" ]; then
|
|
sort -u "$RICE_LIST" -o "$RICE_LIST"
|
|
tar czf "$OUT/rice.tar.gz" -C "$HOME" -T "$RICE_LIST"
|
|
echo " archive: rice.tar.gz ($(du -h "$OUT/rice.tar.gz" | cut -f1))"
|
|
fi
|
|
rm -f "$RICE_LIST"
|
|
|
|
echo
|
|
ls -lh "$OUT" |