-
-
Save labre/8121c3c19c68addac432e86abd585b92 to your computer and use it in GitHub Desktop.
Wineprefix tmpfs synchronization sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##invocation | |
if [[ $# == 0 ]]; then | |
cat <<-EOF | |
Usage: | |
${0} "\${WINEPREFIX}" [ "\${game_name}" ] | |
EOF | |
exit 0 | |
fi | |
# tmpfs mount point, e.g. /mnt/fast | |
declare tmpfsDir=/mnt/fast | |
# lutris games folder, e.g. /mnt/space/lutris/games | |
declare lutrisGamesDir=/mnt/space/lutris/games | |
# maximum tmpfs size in Gibibytes (base 1024) | |
# tmpfs could also be mounted with a size option of this size | |
declare maxTmpfsSize=70 | |
declare -p tmpfsDir lutrisGamesDir maxTmpfsSize | |
if ! echo "${1}" | grep -q "${tmpfsDir}"; then | |
exit 0 | |
fi | |
declare dest=$(find "${lutrisGamesDir}" -type d -name "${1##*/}") | |
declare gameName="${2}" | |
declare src="${1}" | |
declare -p src | |
if [[ -z "${gameName}" ]]; then | |
gameName="${1##*/}" | |
fi | |
declare -p dest gameName | |
# Note: One rsync process is spawned for generator, sender and | |
# receiver, which results in copying to prefix subdirectory | |
# removing the prefix folder suffix because of that | |
dest="${dest%/*}" | |
rsync -au --no-i-r --info=progress2 "${src}" "${dest}" | \ | |
stdbuf -i0 -o0 -e0 tr '\r' '\n' | \ | |
stdbuf -i0 -o0 -e0 awk -f ~/scripts/rsync.awk | \ | |
zenity --progress --text="Copying ${gameName} from ram" \ | |
--auto-kill --title="Copy from ram" --auto-close | |
# auto-kill is not reliable for the 3 processes | |
killall rsync |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $# == 0 ]]; then | |
cat <<-EOF | |
Usage: | |
${0} "\${WINEPREFIX}" [ "\${game_name}" ] | |
EOF | |
exit 0 | |
fi | |
# tmpfs mount point, e.g. /mnt/fast | |
declare tmpfsDir=/mnt/schnell | |
# lutris games folder, e.g. /mnt/space/lutris/games | |
declare lutrisGamesDir=/mnt/platz/lutris/games | |
# maximum tmpfs size in Gibibytes (base 1024) | |
# tmpfs could also be mounted with a size option of this size | |
declare maxTmpfsSize=70 | |
declare -p tmpfsDir lutrisGamesDir maxTmpfsSize | |
if ! echo "${1}" | grep -q "${tmpfsDir}"; then | |
exit 0 | |
fi | |
declare src=$(find "${lutrisGamesDir}" -type d -name "${1##*/}") | |
declare dest="${1}" | |
declare gameName="${2}" | |
declare -p src | |
declare -i srcSize=$(du -s --block-size=1G "${src}" | grep -oe '^[[:digit:]]\+') | |
declare -i fsSize=$(du -s --block-size=1G "${tmpfsDir}" | grep -oe '^[[:digit:]]\+') | |
declare -p srcSize fsSize | |
if (( ${srcSize} + ${fsSize} > ${maxTmpfsSize} )) && [[ ! -d "${dest}" ]]; then | |
[[ -n "${tmpfsDir}" ]] && rm -rf "${tmpfsDir}"/* | |
fi | |
if [[ -z "${gameName}" ]]; then | |
gameName="${1##*/}" | |
fi | |
declare -p dest gameName | |
# Note: One rsync process is spawned for generator, sender and | |
# receiver, which results in copying to prefix subdirectory | |
# omitting the prefix folder suffix because of that | |
rsync -au --no-i-r --info=progress2 "${src}" "${tmpfsDir}" | \ | |
stdbuf -i0 -o0 -e0 tr '\r' '\n' | \ | |
stdbuf -i0 -o0 -e0 awk -f ~/scripts/rsync.awk | \ | |
zenity --progress --text="Copying ${gameName} to ram" \ | |
--auto-kill --title="Copy to ram" --auto-close | |
# auto-kill would kill just one rsync process | |
killall rsync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment