This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles-old/dotfiles/scripts/savegame_backup

42 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# Simple two way game-save sync
# NOTE: This will ALLWAYS replace the backups with local folders,
# even if they are empty folders
command -v xdg-user-dir &> /dev/null &&
DOCUMETS="$(xdg-user-dir DOCUMENTS)" ||
DOCUMETS=~/Documents
SAVES_DIR="$DOCUMETS/GameSaves/"
test -d "$SAVES_DIR" || exit 1
test_rsync(){
test -d "$1" && {
mkdir -p $(dirname "$2")
cp --recursive --no-target-directory "$1" "$2"
}
}
game_save(){
GAME_NAME="$1"; shift
INSTALL_DIR="${1/"~"/$HOME}/"; shift
BACKUP_DIR="$SAVES_DIR/$GAME_NAME/"
test_rsync "$INSTALL_DIR" "$BACKUP_DIR" ||
test_rsync "$BACKUP_DIR" "$INSTALL_DIR" ||
echo "Nothing to do for $GAME_NAME"
while test -n "$1"
do
find "$BACKUP_DIR" -name "$1" -delete
shift
done
}
game_save mindustry "~/.local/share/Mindustry"
game_save minecraft "~/.minecraft/saves"
game_save factorio "~/.factorio" '_autosave*.zip' '*.sync-conflict-*'
game_save cuphead "~/Games/cuphead/drive_c/users/lelgenio/Application Data/Cuphead"