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.

380 lines
10 KiB

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