2019-10-05 19:58:08 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Vars {{{
|
2019-10-05 20:40:50 +02:00
|
|
|
|
debug=0
|
|
|
|
|
|
2019-10-05 20:05:14 +02:00
|
|
|
|
## Steam {{{
|
|
|
|
|
steam_id="112595584"
|
|
|
|
|
steam_userdata=".steam/steam/userdata/${steam_id}"
|
2019-10-05 20:40:50 +02:00
|
|
|
|
|
|
|
|
|
## List of Steam games to backup
|
|
|
|
|
### 204360 − Castle Crashers − https://pcgamingwiki.com/wiki/Castle_Crashers
|
|
|
|
|
steam_games="1 204360 17"
|
2019-10-05 20:05:14 +02:00
|
|
|
|
## }}}
|
|
|
|
|
|
2019-10-05 19:58:08 +02:00
|
|
|
|
remote_dir="${HOME}/Nextcloud/games/linux.sgl.script"
|
2019-10-05 20:05:14 +02:00
|
|
|
|
remote_steam_userdata="${remote_dir}/${steam_userdata}"
|
2019-10-05 19:58:08 +02:00
|
|
|
|
|
2019-10-05 20:05:14 +02:00
|
|
|
|
local_steam_userdata="${HOME}/${steam_userdata}"
|
2019-10-05 19:58:08 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
2019-10-05 20:54:04 +02:00
|
|
|
|
# Functions {{{
|
|
|
|
|
# Move one Steam save game dir {{{
|
|
|
|
|
move_steam_game_dir() {
|
|
|
|
|
local game_id="${1}"
|
|
|
|
|
local local_game_path="${local_steam_userdata}/${game_id}"
|
|
|
|
|
local remote_game_path="${remote_steam_userdata}/${game_id}"
|
|
|
|
|
|
|
|
|
|
## If a remote directory doesn't already exists for this game
|
|
|
|
|
if [ ! -d "${remote_game_path}" ]; then
|
|
|
|
|
mv -- "${local_game_path}" "${remote_game_path}"
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "Move Steam game − The data of ${game_id} − ${local_game_path} moved to remote storage."
|
|
|
|
|
ln -s -- "${remote_game_path}" "${local_game_path}"
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "Move Steam game − Symlink remote to data of ${game_id} to local storage."
|
|
|
|
|
else
|
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "Move Steam game − ${game_id} already have data on remote storage : ${remote_game_path}. Abort to avoid to delete data."
|
|
|
|
|
exit 5
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
# }}}
|
|
|
|
|
|
2019-10-05 19:58:08 +02:00
|
|
|
|
# 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 Steam dir exist {{{
|
2019-10-05 20:05:14 +02:00
|
|
|
|
if [ ! -d "${local_steam_userdata}" ]; then
|
2019-10-05 19:58:08 +02:00
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "The Steam directory for your ID (${steam_id}) doesn't exists yet… Should it must be create (for restoration,…) [Y/n] ?"
|
2019-10-05 20:05:14 +02:00
|
|
|
|
read -r create_local_steam_userdata
|
|
|
|
|
if [ "${create_local_steam_userdata}" = "" ] || [ "${create_local_steam_userdata}" = "Y" ] || [ "${create_local_steam_userdata}" = "y" ]; then
|
|
|
|
|
mkdir -p -- "${local_steam_userdata}"
|
2019-10-05 19:58:08 +02:00
|
|
|
|
else
|
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "Steam directory doesn't exists, abort script."
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
## }}}
|
|
|
|
|
|
|
|
|
|
# }}}
|
2019-10-05 20:40:50 +02:00
|
|
|
|
|
2019-10-05 20:54:04 +02:00
|
|
|
|
# Manage Steam save game {{{
|
2019-10-05 20:40:50 +02:00
|
|
|
|
for game_id in ${steam_games}; do
|
|
|
|
|
local_game_path="${local_steam_userdata}/${game_id}"
|
|
|
|
|
local_game_path_type="$(file ${local_steam_userdata}/${game_id} | cut -d' ' -f2)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case ${local_game_path_type} in
|
|
|
|
|
## Data is already a symlink
|
|
|
|
|
"symbolic")
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Steam for loop — The data of ${game_id} are already symlinked to .... Skip."
|
|
|
|
|
;;
|
|
|
|
|
## Data is still a directory
|
|
|
|
|
"directory")
|
|
|
|
|
move_steam_game_dir "${game_id}"
|
|
|
|
|
;;
|
|
|
|
|
## Data can't be managed
|
|
|
|
|
"cannot")
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Steam for loop — The data of ${game_id} − ${local_game_path} doesn't exist. Skip."
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "Data of ${game_id} − ${local_game_path} are not managed. Type: ${local_game_path_type}. Abort"
|
|
|
|
|
exit 3
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2019-10-05 20:54:04 +02:00
|
|
|
|
# }}}
|
2019-10-05 20:40:50 +02:00
|
|
|
|
|
|
|
|
|
done
|