2019-10-05 19:58:08 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2019-10-07 20:48:17 +02:00
|
|
|
|
# Purpose {{{
|
|
|
|
|
## Try to centralize all game's save 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 Steam's
|
|
|
|
|
## userdata to a remote directory (Nextcloud, remote mount,…).
|
|
|
|
|
## Then create a symlink in userdata directory to the remote game
|
|
|
|
|
## directory.
|
|
|
|
|
##
|
|
|
|
|
## 2. If a directory doesn't exist, check if a remote one is
|
|
|
|
|
## available and symlink it.
|
|
|
|
|
##
|
2019-10-08 00:08:15 +02:00
|
|
|
|
## 3. List directories without symlinks.
|
2019-10-07 20:48:17 +02:00
|
|
|
|
##
|
|
|
|
|
## KISS : Only manage save directories from Steam userdata. For other
|
|
|
|
|
## paths ($XDG_DATA_HOME,…) check other scripts.
|
|
|
|
|
# }}}
|
|
|
|
|
|
2019-10-05 19:58:08 +02:00
|
|
|
|
# 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-08 18:22:44 +02:00
|
|
|
|
steam_compatdata=".steam/steam/steamapps/compatdata"
|
2019-10-05 20:40:50 +02:00
|
|
|
|
|
2019-10-07 22:56:53 +02:00
|
|
|
|
## List of Steam games to backup {{{
|
|
|
|
|
### 760 − Steam Screenshots − https://steamdb.info/app/760/
|
|
|
|
|
### 35700 − Trine Enchanted Edition − https://pcgamingwiki.com/wiki/Trine_Enchanted_Edition
|
|
|
|
|
### 35720 − Trine 2 Complete Story − https://pcgamingwiki.com/wiki/Trine_2
|
2019-10-08 18:22:44 +02:00
|
|
|
|
### 55230 − Saints Row: The Third − https://pcgamingwiki.com/wiki/Saints_Row:_The_Third
|
2019-10-05 20:40:50 +02:00
|
|
|
|
### 204360 − Castle Crashers − https://pcgamingwiki.com/wiki/Castle_Crashers
|
2019-10-07 22:56:53 +02:00
|
|
|
|
### 206420 − Saints Row IV − https://pcgamingwiki.com/wiki/Saints_Row_IV
|
|
|
|
|
### 218820 − Mercenary Kings − https://pcgamingwiki.com/wiki/Mercenary_Kings
|
|
|
|
|
### 247080 − Crypt of the Necrodancer − https://pcgamingwiki.com/wiki/Crypt_of_the_Necrodancer
|
|
|
|
|
### 255870 − PixelJunk Shooter − https://pcgamingwiki.com/wiki/PixelJunk_Shooter
|
|
|
|
|
### 312530 − Duck Game − https://pcgamingwiki.com/wiki/Duck_Game
|
|
|
|
|
### 359840 − Shift Happens − https://pcgamingwiki.com/wiki/Shift_Happens
|
2019-10-08 18:22:44 +02:00
|
|
|
|
steam_games="760 35700 35720 55230 204360 206420 218820 247080 255870 312530 359840"
|
2019-10-07 22:56:53 +02:00
|
|
|
|
## }}}
|
2019-10-08 18:22:44 +02:00
|
|
|
|
# List of Steam saves in compatdata {{{
|
|
|
|
|
### 213670 − South Park: The Stick of Truth − https://pcgamingwiki.com/wiki/South_Park:_The_Stick_of_Truth
|
|
|
|
|
### 359840 − Shift Happens − https://pcgamingwiki.com/wiki/Shift_Happens
|
|
|
|
|
### 480490 − Prey (2017) − https://pcgamingwiki.com/wiki/Prey_(2017)
|
|
|
|
|
### 686200 − Door Kickers: Action Squad − https://pcgamingwiki.com/wiki/Door_Kickers:_Action_Squad
|
|
|
|
|
steam_compatdata_games="686200"
|
|
|
|
|
# }}}
|
|
|
|
|
# List of Steam saves in steamapps {{{
|
|
|
|
|
### 274190 − Broforce − https://pcgamingwiki.com/wiki/Broforce
|
|
|
|
|
# }}}
|
2019-10-07 22:56:53 +02:00
|
|
|
|
## Ids without backups in userdata {{{
|
2019-10-08 00:08:15 +02:00
|
|
|
|
### 7 − Unknown
|
2019-10-07 22:56:53 +02:00
|
|
|
|
### 620 − Portal 2 − https://pcgamingwiki.com/wiki/Portal_2
|
|
|
|
|
### 49520 − Borderlands 2 − https://pcgamingwiki.com/wiki/Borderlands_2
|
|
|
|
|
### 219150 − Hotline Miami − https://pcgamingwiki.com/wiki/Hotline_Miami
|
|
|
|
|
### 241100 − Steam Controller Configs − https://steamdb.info/app/241100/
|
|
|
|
|
### 242680 − Nuclear Throne − https://pcgamingwiki.com/wiki/Nuclear_Throne
|
|
|
|
|
### 251470 − TowerFall Ascension − https://pcgamingwiki.com/wiki/TowerFall_Ascension
|
|
|
|
|
### 255870 − PixelJunk Shooter − https://pcgamingwiki.com/wiki/PixelJunk_Shooter
|
|
|
|
|
### 268990 − The Dishwasher: Vampire Smile − https://pcgamingwiki.com/wiki/The_Dishwasher:_Vampire_Smile
|
|
|
|
|
### 295790 − Never Alone − https://pcgamingwiki.com/wiki/Never_Alone
|
|
|
|
|
### 416600 − Full Metal Furies − https://pcgamingwiki.com/wiki/Full_Metal_Furies
|
|
|
|
|
### 474210 − Butcher − https://pcgamingwiki.com/wiki/Butcher
|
|
|
|
|
### 697660 − Jump Gunners − https://pcgamingwiki.com/wiki/Jump_Gunners
|
|
|
|
|
### 728880 − Overcooked! 2 − https://pcgamingwiki.com/wiki/Overcooked!_2
|
2019-10-08 00:08:15 +02:00
|
|
|
|
ignore_pattern_steam_id="(7|620|49520|55230|213670|219150|241100|242680|251470|255870|268990|274190|295790|416600|474210|480490|686200|697660|728880|config|ugc|ugcmsgcache|\.)$"
|
2019-10-07 22:56:53 +02:00
|
|
|
|
## }}}
|
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-08 00:08:15 +02:00
|
|
|
|
|
|
|
|
|
local_unmanaged_games_list="/tmp/unmanaged_games_list"
|
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() {
|
2019-10-05 21:07:13 +02:00
|
|
|
|
_game_id="${1}"
|
|
|
|
|
_local_game_path="${local_steam_userdata}/${_game_id}"
|
|
|
|
|
_remote_game_path="${remote_steam_userdata}/${_game_id}"
|
2019-10-05 20:54:04 +02:00
|
|
|
|
|
|
|
|
|
## If a remote directory doesn't already exists for this game
|
2019-10-05 21:07:13 +02:00
|
|
|
|
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."
|
2019-10-05 20:54:04 +02:00
|
|
|
|
else
|
2019-10-05 21:07:13 +02:00
|
|
|
|
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."
|
2019-10-05 20:54:04 +02:00
|
|
|
|
exit 5
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
2019-10-05 21:06:33 +02:00
|
|
|
|
# Symlink one Steam save game dir from remote to local {{{
|
|
|
|
|
symlink_steam_game_dir() {
|
|
|
|
|
_game_id="${1}"
|
|
|
|
|
_local_game_path="${local_steam_userdata}/${_game_id}"
|
|
|
|
|
_remote_game_path="${remote_steam_userdata}/${_game_id}"
|
|
|
|
|
|
|
|
|
|
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 Steam game — Symlink remote data of ${_game_id} to local storage."
|
|
|
|
|
else
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Symlink Steam game — ${_game_id} doesn't have remote data."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
2019-10-05 20:54:04 +02:00
|
|
|
|
# }}}
|
|
|
|
|
|
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-08 18:22:44 +02:00
|
|
|
|
# Manage Steam userdata 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."
|
2019-10-08 00:08:15 +02:00
|
|
|
|
;;
|
2019-10-05 20:40:50 +02:00
|
|
|
|
## 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."
|
2019-10-05 21:06:33 +02:00
|
|
|
|
symlink_steam_game_dir "${game_id}"
|
2019-10-05 20:40:50 +02:00
|
|
|
|
;;
|
|
|
|
|
*)
|
2019-10-08 18:22:44 +02:00
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "Data of ${game_id} (userdata) − ${local_game_path} are not managed. Type: ${local_game_path_type}. Abort"
|
2019-10-08 18:25:02 +02:00
|
|
|
|
exit 3
|
2019-10-05 20:40:50 +02:00
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
done
|
2019-10-07 20:48:17 +02:00
|
|
|
|
# }}}
|
2019-10-08 18:22:44 +02:00
|
|
|
|
# Manage Steam compadata save game {{{
|
|
|
|
|
for game_id in ${steam_compatdata_games}; do
|
|
|
|
|
local_game_path="${HOME}/${steam_compatdata}/${game_id}"
|
|
|
|
|
local_game_path_type="$(file "${local_game_path}" | 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 compatdata for loop — The data of ${game_id} are already symlinked to .... Skip."
|
|
|
|
|
;;
|
|
|
|
|
## Data is still a directory, try to move it
|
|
|
|
|
"directory")
|
|
|
|
|
### TODO :
|
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "Steam compatdata for loop − The data of ${game_id} − ${local_game_path} need to move."
|
|
|
|
|
;;
|
|
|
|
|
## Data can't be managed
|
|
|
|
|
"cannot")
|
|
|
|
|
[ "${debug}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Steam compatdata for loop — The data of ${game_id} − ${local_game_path} doesn't exist. Skip."
|
|
|
|
|
### TODO : Try to symlink
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "Data of ${game_id} (compatdata) − ${local_game_path} are not managed. Type: ${local_game_path_type}. Abort : $(file "${local_game_path}")"
|
|
|
|
|
exit 3
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
# }}}
|
|
|
|
|
# List userdata unmanage game id {{{
|
2019-10-08 00:08:15 +02:00
|
|
|
|
cd -- "${local_steam_userdata}" || exit 1
|
|
|
|
|
rm -f -- "${local_unmanaged_games_list}"
|
|
|
|
|
find . -maxdepth 1 -type d | grep -vE "${ignore_pattern_steam_id}" > "${local_unmanaged_games_list}"
|
|
|
|
|
if [ -s "${local_unmanaged_games_list}" ]; then
|
|
|
|
|
printf '\e[1;35m%-6s\e[m\n' "List of unmanaged directories :"
|
|
|
|
|
cat "${local_unmanaged_games_list}"
|
|
|
|
|
fi
|
|
|
|
|
rm -f -- "${local_unmanaged_games_list}"
|
|
|
|
|
cd -- - > /dev/null || exit 1
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
exit 0
|