Automate installation of DXVK, D9VK + Wine/Wine Staging & update GPU drivers + PlayonLinux wineprefixes (Debian/Ubuntu/Mint/Arch Linux/Manjaro)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
8.2 KiB

6 years ago
  1. #!/bin/bash
  2. # getsource - Simple script to set up Wine Staging + DXVK for PoL wineprefixes
  3. # Copyright (C) 2018 Pekka Helenius
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ###########################################################
  18. # Your system username (who has PoL profile // existing Wine prefixes)
  19. # Get it by running 'whoami'
  20. USER=fincer
  21. ###########################################################
  22. # REQUIREMENTS:
  23. # - Arch Linux or equivalent (uses pacman)
  24. #
  25. # - Existing PlayonLinux package installation and $HOME/.PlayOnLinux folder
  26. # with all relevant subfolders
  27. #
  28. # - git, sudo, pwd...etc.
  29. #
  30. # - dxvk-git and wine-staging-git package dependencies installed
  31. # (see PKGBUILD files ./PKGBUILD and ./0-dxvk-git/PKGBUILD for details)
  32. #
  33. # - Internet connection
  34. #
  35. # - GPU Vulkan support and the most recent Nvidia/AMD drivers
  36. ###########################################################
  37. # Usage
  38. # Run with sudo
  39. #
  40. # # sudo bash ./updatewine.sh
  41. #
  42. # NOTE: All commands are executed as user (defined above).
  43. # Only commands which require root permissions are ones
  44. # which install packages wine-staging-git and dxvk into
  45. # your system
  46. # All regular user commands have prefix 'cmd' below
  47. # Switches:
  48. #
  49. # --refresh
  50. #
  51. # Check for new Staging/DXVK releases, update PoL Wine prefixes if needed
  52. # Does a comparison between local & remote git repos
  53. #
  54. # --check
  55. #
  56. # Check for new Staging/DXVK releases
  57. # Does a comparison between local & remote git repos
  58. #
  59. # --force
  60. #
  61. # Force Wine Staging & DXVK installation
  62. #
  63. ###########################################################
  64. # Get current date
  65. CURDATE=$(date "+%d-%m-%Y %H:%M:%S")
  66. # This variable value is automatically generated. DO NOT CHANGE.
  67. LASTUPDATE=
  68. # This variable value is automatically generated. DO NOT CHANGE.
  69. WINE_VERSION=
  70. ###########################################################
  71. # Switches
  72. if [[ "${1}" == "--refresh" ]]; then
  73. WINE_INSTALL=
  74. CHECK=
  75. fi
  76. if [[ "${1}" == "--check" ]]; then
  77. CHECK=
  78. fi
  79. if [[ "${1}" == "--force" ]] || [[ $WINE_VERSION == "" ]] || [[ $LASTUPDATE == "" ]]; then
  80. WINE_INSTALL=
  81. FORCE_INSTALL=
  82. fi
  83. ###########################################################
  84. if [[ $UID -ne 0 ]]; then
  85. echo "Run as root or sudo"
  86. exit 1
  87. fi
  88. echo -e "\nLast update: $LASTUPDATE\n"
  89. ORG_CURDIR=$(pwd)
  90. cmd() {
  91. sudo -u $USER bash -c "${*}"
  92. }
  93. ###########################################################
  94. # Check for existing PoL user folder
  95. if [[ ! -d /home/$USER/.PlayOnLinux ]]; then
  96. echo "No existing PlayonLinux profiles in $USER's home folder. Aborting"
  97. exit 1
  98. fi
  99. ###########################################################
  100. # Check internet connection
  101. function netCheck() {
  102. if [[ $(echo $(wget --delete-after -q -T 5 github.com -o -)$?) -ne 0 ]]; then
  103. echo -e "\nInternet connection failed (GitHub). Please check your connection and try again.\n"
  104. exit 1
  105. fi
  106. }
  107. ###########################################################
  108. # Local/Remote git comparisons
  109. function gitCheck() {
  110. netCheck
  111. if [[ -v $FORCE_INSTALL ]]; then
  112. NEEDSBUILD=1
  113. return 0
  114. fi
  115. if [[ ! -d "${1}" ]]; then
  116. NEEDSBUILD=1
  117. return 1
  118. fi
  119. echo -e "=> Checking ${2} GIT for changes\n"
  120. local CURDIR="${PWD}"
  121. cd "${1}"
  122. local LOCAL_GIT=$(git rev-parse @)
  123. local REMOTE_GIT=$(git ls-remote origin -h refs/heads/master | awk '{print $1}')
  124. echo -e "\t${2}:\n\tlocal git: $LOCAL_GIT\n\tremote git: $REMOTE_GIT"
  125. if [[ $LOCAL_GIT != $REMOTE_GIT ]]; then
  126. # true
  127. echo -e "\e[91m\n\t${2} needs to be updated\e[0m\n"
  128. NEEDSBUILD=1
  129. else
  130. # false
  131. echo -e "\e[92m\n\t${2} is updated\e[0m\n"
  132. NEEDSBUILD=0
  133. fi
  134. cd "${CURDIR}"
  135. }
  136. ###########################################################
  137. # Remove any existing pkg,src or tar.xz packages left by previous pacman commands
  138. cmd "rm -rf ./*/{pkg,src,*.tar.xz}"
  139. cmd "rm -f ./0-wine-staging-git/*.patch"
  140. if [[ $? -ne 0 ]]; then
  141. echo "Could not remove previous pacman-generated Wine source folders"
  142. exit 1
  143. fi
  144. ###########################################################
  145. # Do git check for Wine Staging
  146. gitCheck ./wine-staging-git Wine
  147. # If needs build and --check switch is not used
  148. if [[ $NEEDSBUILD -eq 1 ]] && [[ ! -v CHECK ]]; then
  149. # Create wine-staging-git package and install it to the system
  150. cd "${ORG_CURDIR}"/0-wine-staging-git
  151. cmd "updpkgsums && makepkg"
  152. if [[ $? -eq 0 ]]; then
  153. pacman -U --noconfirm wine-*.tar.xz
  154. else
  155. exit 1
  156. fi
  157. if [[ $? -eq 0 ]]; then
  158. cmd "rm -rf ./{*.patch,pkg,src,*.tar.xz}"
  159. WINE_INSTALL=
  160. WINE_VERSION_UPDATE=$(pacman -Qi wine-staging-git | grep 'Version' | awk '{print $NF}')
  161. else
  162. exit 1
  163. fi
  164. cd ..
  165. fi
  166. #############################
  167. # Create dxvk-git package and install it to the system
  168. gitCheck ./0-dxvk-git/dxvk-git DXVK
  169. # If needs build and --check switch is not used
  170. if [[ $NEEDSBUILD -eq 1 ]] && [[ ! -v CHECK ]]; then
  171. # Create dxvk-git package and install it to the system
  172. cd "${ORG_CURDIR}"/0-dxvk-git
  173. cmd "updpkgsums && makepkg"
  174. if [[ $? -eq 0 ]]; then
  175. pacman -U --noconfirm dxvk-git*.tar.xz
  176. else
  177. exit 1
  178. fi
  179. if [[ $? -eq 0 ]]; then
  180. cmd "rm -rf ./{pkg,src,dxvk-git*.tar.xz}"
  181. else
  182. exit 1
  183. fi
  184. fi
  185. cd ..
  186. # If a new Wine Staging version was installed and 'System' version of Wine has been used in
  187. # PoL wineprefix configurations, update those existing PoL wineprefixes
  188. if [[ -v WINE_INSTALL ]]; then
  189. for wineprefix in $(find /home/$USER/.PlayOnLinux/wineprefix -mindepth 1 -maxdepth 1 -type d); do
  190. if [[ -d ${wineprefix}/dosdevices ]]; then
  191. # If VERSION string exists, skip updating that prefix.
  192. if [[ $(printf $(grep -ril "VERSION" ${wineprefix}/playonlinux.cfg &> /dev/null)$?) -ne 0 ]]; then
  193. # If currently installed Wine version is not same than we just built.
  194. if [[ -v WINE_VERSION_UPDATE ]]; then
  195. if [[ "${WINE_VERSION}" != "${WINE_VERSION_UPDATE}" ]]; then
  196. cmd "WINEPREFIX=${wineprefix} wineboot -u"
  197. fi
  198. fi
  199. fi
  200. fi
  201. done
  202. # If a new Wine Staging version was installed, update WINE_VERSION string variable in this script file
  203. if [[ -v WINE_VERSION_UPDATE ]]; then
  204. cmd "sed -i 's/^WINE_VERSION=.*/WINE_VERSION=\"${WINE_VERSION_UPDATE}\"/' $ORG_CURDIR/updatewine.sh"
  205. fi
  206. fi
  207. # Install dxvk-git to every PlayOnLinux wineprefix
  208. if [[ $? -eq 0 ]]; then
  209. for wineprefix in $(find /home/$USER/.PlayOnLinux/wineprefix -mindepth 1 -maxdepth 1 -type d); do
  210. if [[ -d ${wineprefix}/dosdevices ]]; then
  211. if [[ $(printf $(grep -ril "\"d3d11\"=\"native\"" ${wineprefix}/user.reg &> /dev/null)$?) -ne 0 ]]; then
  212. cmd "WINEPREFIX=${wineprefix} setup_dxvk32"
  213. cmd "WINEPREFIX=${wineprefix} setup_dxvk64"
  214. fi
  215. # For D3D10 DXVK support
  216. if [[ $(printf $(grep -ril "\"\*d3dcompiler_43\"=\"native\"" ${wineprefix}/user.reg &> /dev/null)$?) -ne 0 ]]; then
  217. cmd "WINEPREFIX=${wineprefix} winetricks d3dcompiler_43"
  218. fi
  219. fi
  220. done
  221. fi
  222. # Update LASTUPDATE variable string, if --check switch is not used + a new Wine Staging version is used or NEEDSBUILD variable is set to 1
  223. if [[ ! -v CHECK ]]; then
  224. if [[ -v WINE_INSTALL ]] || [[ $NEEDSBUILD -eq 1 ]]; then
  225. cmd "sed -i 's/^LASTUPDATE=.*/LASTUPDATE=\"$CURDATE\"/' $ORG_CURDIR/updatewine.sh"
  226. fi
  227. fi
  228. # Unset various env vars
  229. unset CHECK
  230. unset WINE_INSTALL
  231. unset FORCE_INSTALL