From 414fc560fab82396cc5a2501eab689c567330ccb Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 9 Oct 2019 20:30:17 +0200 Subject: [PATCH] Prepare backup of save game from XDG directories --- games/save.game.xdg | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 games/save.game.xdg diff --git a/games/save.game.xdg b/games/save.game.xdg new file mode 100755 index 0000000..5132548 --- /dev/null +++ b/games/save.game.xdg @@ -0,0 +1,66 @@ +#!/bin/sh + +# Purpose {{{ +## Try to centralize all game's save that respect XDG specifications in order to : +## easily backup all save +## easily restore it +## be able to access it from anywhere +## … all you can do with a Nextcloud (share, versionning,…) +## +## 1. Move save directories of a list of known games from XDG's +## directories to a remote directory (Nextcloud, remote mount,…). +## Then create a symlink in XDG directories to the remote game +## directory. +## +## 2. If a directory doesn't exist, check if a remote one is +## available and symlink it. +## +## KISS : Only manage save directories from Steam userdata. For other +## paths (Steam,…) check other scripts. +# }}} + +# Vars {{{ +debug=0 + +## XDG config {{{ +XDG_CONFIG_HOME="${HOME}/.config" +xdg_config="$(printf "%s" "${XDG_CONFIG_HOME}" | sed -e "s;${HOME}/;;")" + +config_games="..." +## }}} +## XDG data {{{ +XDG_DATA_HOME="${HOME}/.local/share" +xdg_data="$(printf "%s" "${XDG_DATA_HOME}" | sed -e "s;${HOME}/;;")" + +data_games="..." +## }}} + +remote_dir="${HOME}/Nextcloud/games/linux.sgl.script" + +# }}} + +# Tests {{{ + +## Ensure remote dir exist {{{ +if [ ! -d "${remote_dir}" ]; then + printf '\e[1;35m%-6s\e[m\n' "The directory for save game doesn't exists : ${remote_dir}" + exit 1 +fi +## }}} +## Ensure XDG directories exist {{{ +for xdg_dir in "${xdg_config}" "${xdg_data}"; do + local_xdg_path="${HOME}/${xdg_dir}" + if [ ! -d "${local_xdg_path}" ]; then + printf '\e[1;35m%-6s\e[m\n' "The XDG directory − ${xdg_dir} doesn't exists yet… Should it must be create (for restoration,…) [Y/n] ?" + read -r create_local_xdg + if [ "${create_local_xdg}" = "" ] || [ "${create_local_xdg}" = "Y" ] || [ "${create_local_xdg}" = "y" ]; then + mkdir -p -- "${local_xdg_path}" + else + printf '\e[1;35m%-6s\e[m\n' "XDG directory (${xdg_dir}) doesn't exists, abort script." + exit 2 + fi + fi +done +## }}} + +# }}}