install_gog_game.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/bash
  2. # fail if any commands fails
  3. set -e
  4. # debug log
  5. #set -x
  6. # Set superuser privileges command if not set
  7. if [[ -z $su ]]; then
  8. export su="sudo"
  9. fi
  10. show_usage() {
  11. printf "Usage: $0 [options [parameters]]\n"
  12. printf "\n"
  13. printf "Commands:\n"
  14. printf " -i|--install [game name from lgogdownloader list]\n"
  15. printf " -l|--list (list available games in gog account)\n"
  16. printf "\n"
  17. printf "Options:\n"
  18. printf " --dxvk (installs dxvk to WINEPREFIX path after installation)\n"
  19. printf " --win (installs the windows version of the game)\n"
  20. printf " --lin (installs the linux version of the game)\n"
  21. printf "\n"
  22. printf " -l|--list, list available wad files\n"
  23. printf " -h|--help, Print help\n"
  24. exit
  25. }
  26. install_lgogdownloader() {
  27. lgog_downloader=$(pacman -Qs lgogdownloader-qt5-git)
  28. if [ "$lgog_downloader" = "" ]; then
  29. paru -S lgogdownloader-qt5
  30. else
  31. echo "INFO: lgogdownloader currently installed"
  32. fi
  33. echo -e "\033[33;5mINFO: If running for first time you need to type: '$ lgogdownloader --login --enable-login-gui'\033[0m"
  34. }
  35. # Check command
  36. if [ -z "$1" ]; then
  37. show_usage
  38. fi
  39. if { [ "$1" = --help ] || [ "$1" = -h ];}; then
  40. show_usage
  41. fi
  42. if { [ "$1" = --list ] || [ "$1" = -l ];}; then
  43. install_lgogdownloader
  44. lgogdownloader --list
  45. exit
  46. fi
  47. # Parse parameters
  48. while [ -n "$1" ]; do
  49. case "$1" in
  50. --install | -i)
  51. shift
  52. echo "INFO: Installing game: $1"
  53. game=$1
  54. ;;
  55. --dxvk)
  56. echo "INFO: Installing dxvk after game install"
  57. install_dxvk="true"
  58. ;;
  59. --win)
  60. echo "INFO: Installing windows version..."
  61. version_windows="true"
  62. ;;
  63. --lin)
  64. echo "INFO: Installing linux version..."
  65. version_linux="true"
  66. ;;
  67. *)
  68. show_usage
  69. ;;
  70. esac
  71. shift
  72. done
  73. # set defaults
  74. if [ -z "$install_dxvk" ]; then
  75. install_dxvk="false"
  76. fi
  77. if [ -z "$version_windows" ]; then
  78. version_windows="true"
  79. fi
  80. if [ -z "$version_linux" ]; then
  81. version_linux="false"
  82. fi
  83. # Go to ~/Downloads directory
  84. mkdir -p ~/Downloads
  85. cd ~/Downloads || return
  86. # check if game is in gog list
  87. in_list=$(lgogdownloader --list | grep ${game})
  88. if [ ! $in_list = "" ]; then
  89. echo "INFO: $game is in list, downloading..."
  90. # Retry downloading cause of bad connection
  91. counter=0 limit=10
  92. while [ "$counter" -lt "$limit" ]; do
  93. response="$(
  94. echo "INFO: Downloading $game files..." |
  95. lgogdownloader --download --threads 8 --retries 60 --timeout 20 --lowspeed-rate 200 --lowspeed-timeout 30 --exclude patches --game $game
  96. )" &&
  97. break
  98. counter="$(( $counter + 1 ))"
  99. done
  100. #lgogdownloader --download --threads 8 --retries 60 --timeout 20 --lowspeed-rate 200 --lowspeed-timeout 30 --exclude patches --game $game
  101. else
  102. echo "INFO: $game is not in list, currently available games are:"
  103. lgogdownloader --list
  104. fi
  105. # Install game
  106. if [ "$version_windows" = "true" ]; then
  107. mkdir -p ~/Games/gog/
  108. export WINEPREFIX=~/Games/gog/${game}
  109. echo "INFO: Wine prefix: $WINEPREFIX"
  110. ## Show downloaded files
  111. echo "INFO: Downloaded files:"
  112. ls -lahF ~/Downloads/*${game}*/
  113. ## Select game installer file and install
  114. read -rp "INPUT: Please enter installer filename: " installer_file
  115. echo "INFO: Installer file: $installer_file"
  116. wine ~/Downloads/${game}/${installer_file}
  117. # Install dxvk if requested
  118. if [ $install_dxvk = "true" ]; then
  119. setup_dxvk install
  120. fi
  121. # Show installed game files
  122. echo "INFO: To run game type: '$ wine <game_executable>'"
  123. echo ""
  124. echo "INFO: Installed game executables:"
  125. ls -l $WINEPREFIX/drive_c/GOG\ Games/*/*.exe | grep -v unins000.exe | awk '{for(i=9;i<=NF;++i)printf $i""FS ; print ""}'
  126. elif [ "$version_linux" = "true" ]; then
  127. ## Show downloaded files
  128. echo "INFO: Downloaded files:"
  129. ls -lahF ~/Downloads/*${game}*/
  130. ## Select game installer file and install
  131. read -rp "INPUT: Please enter installer filename: " installer_file
  132. echo "INFO: Installer file: $installer_file"
  133. ~/Downloads/${game}/${installer_file}
  134. fi