Prepare functions for move and symlink

This commit is contained in:
Jeremy Gardais 2019-10-09 20:37:26 +02:00
parent 414fc560fa
commit e676cd3fe5
1 changed files with 41 additions and 0 deletions

View File

@ -39,6 +39,47 @@ remote_dir="${HOME}/Nextcloud/games/linux.sgl.script"
# }}} # }}}
# Functions {{{
# Move one save game dir {{{
move_game_dir() {
_game_name="${1}"
_game_dir="${2}"
_local_game_path="${HOME}/${_game_dir}/${_game_name}"
_remote_game_path="${remote_dir}/${_game_dir}/${_game_name}"
## If a remote directory doesn't already exists for this game
if [ ! -d "${_remote_game_path}" ]; then
### Ensure to create tree directories on remote storage
mkdir -p -- "$(dirname "${_remote_game_path}")"
### Move data to remote storage
mv -- "${_local_game_path}" "${_remote_game_path}"
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Move game The data of ${_game_name} ${_local_game_path} moved to remote storage."
### Then ask to create a symbolic link to local storage
symlink_game_dir "${_game_name}" "${_game_dir}"
else
printf '\e[1;35m%-6s\e[m\n' "Move game ${_game_name} already have data on remote storage: ${_remote_game_path}. Abort to avoid to override data."
exit 5
fi
}
# }}}
# Symlink one save game dir from remote to local {{{
symlink_game_dir() {
_game_name="${1}"
_game_dir="${2}"
_local_game_path="${HOME}/${_game_dir}/${_game_name}"
_remote_game_path="${remote_dir}/${_game_dir}/${_game_name}"
if [ -d "${_remote_game_path}" ]; then
ln -s -- "${_remote_game_path}" "${_local_game_path}"
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Symlink game — Symlink remote data of ${_game_name} to local storage."
else
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Symlink game — ${_game_name} doesn't have remote data."
fi
}
# }}}
# }}}
# Tests {{{ # Tests {{{
## Ensure remote dir exist {{{ ## Ensure remote dir exist {{{