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.

369 lines
9.6 KiB

  1. #!/bin/bash
  2. # Set up Wine Staging + DXVK on Arch Linux & Variants
  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. # DO NOT RUN INDIVIDUALLY, ONLY VIA ../updatewine.sh PARENT SCRIPT!
  19. ########################################################
  20. datedir="${1}"
  21. ########################################################
  22. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  23. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  24. ########################################################
  25. # Parse input arguments
  26. i=0
  27. for arg in ${@:2}; do
  28. args[$i]="${arg}"
  29. let i++
  30. done
  31. # Must be a true array as defined above, not a single index list!
  32. #args="${@:2}"
  33. for check in ${args[@]}; do
  34. case ${check} in
  35. --no-staging)
  36. NO_STAGING=
  37. ;;
  38. --no-install)
  39. NO_INSTALL=
  40. # Do not check for PlayOnLinux wine prefixes
  41. NO_POL=
  42. ;;
  43. --no-wine)
  44. NO_WINE=
  45. ;;
  46. --no-dxvk)
  47. NO_DXVK=
  48. ;;
  49. --no-pol)
  50. NO_POL=
  51. ;;
  52. esac
  53. done
  54. ###########################################################
  55. ARCH_BUILDROOT="${PWD}"
  56. function Arch_intCleanup() {
  57. rm -rf ${ARCH_BUILDROOT}/{0-wine-staging-git/{wine-patches,*.tar.xz},0-dxvk-git/{dxvk-git,*.tar.xz}}
  58. exit 0
  59. }
  60. # Allow interruption of the script at any time (Ctrl + C)
  61. trap "Arch_intCleanup" INT
  62. ###########################################################
  63. function ccacheCheck() {
  64. if [[ $(pacman -Q | awk '{print $1}' | grep -wE "ccache" | wc -l) -eq 0 ]]; then
  65. echo -e "NOTE: Please consider using 'ccache' for faster compilation times.\nInstall it by typing 'sudo pacman -S ccache'\n"
  66. fi
  67. }
  68. ###########################################################
  69. # Validate all files exist
  70. function checkFiles() {
  71. local wine_files=('30-win32-aliases.conf' 'PKGBUILD')
  72. local dxvk_files=('PKGBUILD')
  73. function validatefiles() {
  74. local list=${1}
  75. local name=${2}
  76. local path=${3}
  77. for file in ${list[@]}; do
  78. if [[ ! -f "${path}/${file}" ]]; then
  79. echo -e "Could not locate file ${} for ${name}. Aborting\n"
  80. exit 1
  81. fi
  82. done
  83. }
  84. if [[ ! -v NO_WINE ]]; then
  85. validatefiles "${wine_files[*]}" Wine "${ARCH_BUILDROOT}/0-wine-staging-git"
  86. fi
  87. if [[ ! -v NO_DXVK ]]; then
  88. validatefiles "${dxvk_files[*]}" DXVK "${ARCH_BUILDROOT}/0-dxvk-git"
  89. fi
  90. }
  91. ###########################################################
  92. # Disable or enable Wine Staging, depending on user's
  93. # choice
  94. function checkStaging() {
  95. # Enable Wine Staging
  96. if [[ ! -v NO_STAGING ]]; then
  97. sed -i 's/enable_staging=[0-9]/enable_staging=1/' "${ARCH_BUILDROOT}/0-wine-staging-git/PKGBUILD"
  98. wine_name="wine-staging-git"
  99. # Enable Wine, disable Staging
  100. else
  101. sed -i 's/enable_staging=[0-9]/enable_staging=0/' "${ARCH_BUILDROOT}/0-wine-staging-git/PKGBUILD"
  102. wine_name="wine"
  103. fi
  104. }
  105. ###########################################################
  106. # Check package dependencies beforehand, just to avoid
  107. # annoying situations which could occur later while the script
  108. # is already running.
  109. # Just for "packages which are not found" array <=> ERRPKGS
  110. # We need to set it outside of checkDepends function
  111. # because it is a global variable for all checked packages
  112. l=0
  113. function checkDepends() {
  114. # The first and the second argument
  115. local packagedir=${1}
  116. local package=${2}
  117. # We get necessary variables to check from this file
  118. local file="./${packagedir}/PKGBUILD"
  119. # All but the (zero), the first and the second argument
  120. # We check the value of these file variables
  121. local file_vars=${@:3}
  122. for var in ${file_vars[*]}; do
  123. # Get the variable and set it as a new variable in the current shell
  124. # This is applicable only to variable arrays! Do not use if the variable is not an array.
  125. local field=$(awk "/^${var}/,/)/" ${file} | sed -r "s/^${var}=|[)|(|']//g")
  126. local i=0
  127. for parse in ${field[*]}; do
  128. if [[ ! $parse =~ ^# ]]; then
  129. local PKGS[$i]=$(printf '%s' $parse | sed 's/[=|>|<].*$//')
  130. let i++
  131. fi
  132. done
  133. # Sort list and delete duplicate index values
  134. local PKGS=($(sort -u <<< "${PKGS[*]}"))
  135. for pkg in ${PKGS[*]}; do
  136. if [[ $(printf $(pacman -Q ${pkg} &>/dev/null)$?) -ne 0 ]]; then
  137. ERRPKGS[$l]=${pkg}
  138. echo -e "\e[91mError:\e[0m Dependency '${pkg}' not found, required by '${package}' (${file} => ${var})"
  139. let l++
  140. fi
  141. done
  142. done
  143. echo -e "\e[92m==>\e[0m\e[1m Dependency check for ${package} done.\e[0m\n"
  144. }
  145. function check_alldeps() {
  146. if [[ -v ERRPKGS ]]; then
  147. echo -e "The following dependencies are missing:\n\e[91m\
  148. $(for o in ${ERRPKGS[@]}; do printf '%s\n' ${o}; done)\
  149. \e[0m\n"
  150. exit 1
  151. fi
  152. }
  153. ###########################################################
  154. function prepare_env() {
  155. # Copy Wine patch files
  156. cp -rf ${ARCH_BUILDROOT}/../wine_custom_patches ${ARCH_BUILDROOT}/0-wine-staging-git/wine-patches
  157. # Create identifiable directory for this build
  158. mkdir -p ${ARCH_BUILDROOT}/compiled_pkg/"${datedir}"
  159. }
  160. ###########################################################
  161. # Remove any existing pkg,src or tar.xz packages left by previous pacman commands
  162. function cleanUp() {
  163. rm -rf ${ARCH_BUILDROOT}/*/{pkg,src,*.tar.xz}
  164. rm -rf ${ARCH_BUILDROOT}/0-wine-staging-git/{*.patch}
  165. }
  166. ###########################################################
  167. function build_pkg() {
  168. local pkgname=${1}
  169. local pkgname_friendly=${2}
  170. local pkgdir=${3}
  171. local cleanlist=${4}
  172. # Create package and install it to the system
  173. cd "${ARCH_BUILDROOT}"/${pkgdir}
  174. bash -c "updpkgsums && makepkg"
  175. # After successful compilation...
  176. if [[ $(ls ${pkgname}-*tar.xz | wc -l) -ne 0 ]]; then
  177. if [[ ! -v NO_INSTALL ]]; then
  178. yes | sudo pacman -U ${pkgname}-*.tar.xz
  179. fi
  180. mv ${pkgname}-*.tar.xz ${ARCH_BUILDROOT}/compiled_pkg/${datedir}/ && \
  181. echo -e "\nCompiled ${pkgname_friendly} is stored at '$(readlink -f ${ARCH_BUILDROOT}/compiled_pkg/${datedir}/)/'\n"
  182. for rml in ${cleanlist[*]}; do
  183. rm -rf "${ARCH_BUILDROOT}/${pkgdir}/${rml}"
  184. done
  185. else
  186. echo -e "Error occured while compliling ${pkgname} from source.\n"
  187. for rml in ${cleanlist[*]}; do
  188. rm -rf "${ARCH_BUILDROOT}/${pkgdir}/${rml}"
  189. done
  190. exit 1
  191. fi
  192. cd "${ARCH_BUILDROOT}"
  193. }
  194. ##########################################################
  195. function updatePOL() {
  196. # Check whether we will update user's PoL wine prefixes
  197. if [[ ! -v NO_POL ]]; then
  198. # Check existence of PoL default folder in user's homedir
  199. if [[ ! -d "$HOME/.PlayOnLinux" ]]; then
  200. echo -e "Warning. Couldn't find PoL directories in the user's $USERNAME homedir.\n"
  201. return 0
  202. fi
  203. fi
  204. if [[ ! -v NO_WINE ]]; then
  205. # If a new Wine Staging version was installed and 'System' version of Wine has been used in
  206. # PoL wineprefix configurations, update those existing PoL wineprefixes
  207. for wineprefix in $(find $HOME/.PlayOnLinux/wineprefix -mindepth 1 -maxdepth 1 -type d); do
  208. if [[ -d ${wineprefix}/dosdevices ]]; then
  209. # If VERSION string exists, skip updating that prefix.
  210. if [[ $(printf $(grep -ril "VERSION" ${wineprefix}/playonlinux.cfg &> /dev/null)$?) -ne 0 ]]; then
  211. WINEPREFIX=${wineprefix} wineboot -u
  212. fi
  213. fi
  214. done
  215. fi
  216. if [[ ! -v NO_DXVK ]]; then
  217. for wineprefix in $(find $HOME/.PlayOnLinux/wineprefix -mindepth 1 -maxdepth 1 -type d); do
  218. if [[ -d ${wineprefix}/dosdevices ]]; then
  219. WINEPREFIX=${wineprefix} setup_dxvk
  220. fi
  221. done
  222. fi
  223. }
  224. ##########################################################
  225. # Clean these temporary folders & files files
  226. # TODO Shall we remove git folders or keep them?
  227. dxvk_cleanlist=('pkg' 'src' '*.tar.xz') # dxvk-git
  228. wine_cleanlist=('*.patch' '*.diff' 'pkg' 'src' 'wine-patches' '*.tar.xz') # wine-*git
  229. ##########################################################
  230. # Validate all buildtime files
  231. checkFiles
  232. # Check whether we build Wine or Wine Staging
  233. checkStaging
  234. # Check whether we have ccache installed
  235. ccacheCheck
  236. # Prepare building environment: copy patches and create timestamped folder for compiled packages
  237. prepare_env
  238. # Clean all previous trash we may have
  239. cleanUp
  240. #########################
  241. # Check Wine & DXVK dependencies, depending on whether these packages
  242. # are to be built
  243. echo -e "\e[1mINFO:\e[0m Checking dependencies for packages.\n"
  244. if [[ ! -v NO_WINE ]]; then
  245. checkDepends "0-wine-staging-git" "${wine_name}" _depends makedepends
  246. fi
  247. if [[ ! -v NO_DXVK ]]; then
  248. checkDepends "0-dxvk-git" "dxvk-git" depends makedepends
  249. fi
  250. check_alldeps
  251. #########################
  252. # Compile Wine & DXVK, depending on whether these packages
  253. # are to be built
  254. if [[ ! -v NO_WINE ]]; then
  255. build_pkg wine "${wine_name}" "0-wine-staging-git" "${wine_cleanlist[*]}"
  256. fi
  257. if [[ ! -v NO_DXVK ]]; then
  258. build_pkg dxvk DXVK "0-dxvk-git" "${dxvk_cleanlist[*]}"
  259. fi
  260. #########################
  261. # Update user's PlayonLinux wine prefixes if needed
  262. if [[ ! -v NO_POL ]]; then
  263. echo -e "Updating your PlayOnLinux Wine prefixes.\n"
  264. updatePOL
  265. fi