diff options
-rw-r--r-- | Makefile | 19 | ||||
-rwxr-xr-x | noita-backup | 57 |
2 files changed, 76 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5e08a1e --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +DESTDIR= +PREFIX=/usr/local +PREFIX_EXEC=$(PREFIX) +BINDIR=$(PREFIX_EXEC)/bin + +all: + @echo Nothing to do + +install: + install -m755 -DT noita-backup $(DESTDIR)$(BINDIR)/backup-noita + ln -fsr $(DESTDIR)$(BINDIR)/backup-noita $(DESTDIR)$(BINDIR)/destroy-noita + ln -fsr $(DESTDIR)$(BINDIR)/backup-noita $(DESTDIR)$(BINDIR)/restore-noita + +uninstall: + rm -f $(DESTDIR)$(BINDIR)/backup-noita + rm -f $(DESTDIR)$(BINDIR)/destroy-noita + rm -f $(DESTDIR)$(BINDIR)/restore-noita + +.PHONY: all install uninstall diff --git a/noita-backup b/noita-backup new file mode 100755 index 0000000..9489de7 --- /dev/null +++ b/noita-backup @@ -0,0 +1,57 @@ +#!/bin/sh +XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" +for datadir in "$XDG_DATA_HOME" /usr/local/share /usr/share; do + NOITA_BACKUP_ICON="$datadir/icons/noita.png" + if [ -e "$NOITA_BACKUP_ICON" ]; then + break # Contains value even if not found + fi +done +COMPAT_DRIVE_C="$XDG_DATA_HOME/Steam/steamapps/compatdata/881100/pfx/drive_c" +NOITA_SAVE_DIR="$COMPAT_DRIVE_C/users/steamuser/AppData/LocalLow/Nolla_Games_Noita" +NOITA_BACKUP_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/noita-backup" + +notify() { + notify-send -i "$NOITA_BACKUP_ICON" "Noita Backup" "$@" +} + +stamp() { + date +%Y-%m-%d-%H-%m-%S +} + +backup() { + id=$(notify -p "Creating a backup...") + filename="save00.bak.$(stamp)" + if mkdir -p "$NOITA_BACKUP_DIR" && cp -r "$NOITA_SAVE_DIR/save00" "$NOITA_BACKUP_DIR/$filename"; then + notify -r $id "Saved as $filename" + else + notify -r $id "Could not backup the save" + fi +} + +restore() { + latest="$(find "$NOITA_BACKUP_DIR" -name 'save00.bak.*' | sort -r | head -n1)" + if [ -z "$latest" ]; then + notify "No backups to restore from" + return + fi + filename=$(basename "$latest") + save="$NOITA_SAVE_DIR/save00" + restored="$NOITA_BACKUP_DIR/save00.restored.$(stamp)" + id=$(notify -p "Restoring $filename...") + if mv "$save" "$restored" && cp -r "$latest" "$save"; then + notify -r $id "Restored save from $filename" + else + notify -r $id "Could not restore save" + fi +} + +destroy() { + rm -rf "$NOITA_BACKUP_DIR" + notify "Removed all saves" +} + +case "$0" in + *backup-noita) backup;; + *restore-noita) restore;; + *destroy-noita) destroy;; +esac |