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.

371 lines
9.7 KiB

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