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.

616 lines
16 KiB

6 years ago
6 years ago
  1. #!/bin/env bash
  2. # Compile DXVK git on Debian/Ubuntu/Mint and 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. DXVKROOT="${PWD}"
  22. # datedir variable supplied by ../updatewine_debian.sh script file
  23. datedir="${1}"
  24. ########################################################
  25. # Divide input args into array indexes
  26. i=0
  27. for p in ${@:2}; do
  28. params[$i]=${p}
  29. let i++
  30. done
  31. ########################################################
  32. # Parse input git override hashes
  33. # This order is mandatory!
  34. # If you change the order or contents of 'githash_overrides'
  35. # array in ../updatewine.sh, make sure to update these
  36. # variables!
  37. #
  38. git_commithash_dxvk=${params[0]}
  39. git_commithash_glslang=${params[1]}
  40. git_commithash_meson=${params[2]}
  41. git_branch_dxvk=${params[4]}
  42. git_branch_glslang=${params[5]}
  43. git_branch_meson=${params[6]}
  44. ########################################################
  45. # Parse input arguments, filter user parameters
  46. # The range is defined in ../updatewine.sh
  47. # All input arguments are:
  48. # <datedir> 4*<githash_override> 4*<gitbranch_override> <args>
  49. # 0 1 2 3 4 5 6 7 8 9...
  50. # Filter all but <args>, i.e. the first 0-8 arguments
  51. i=0
  52. for arg in ${params[@]:8}; do
  53. args[$i]="${arg}"
  54. let i++
  55. done
  56. for check in ${args[@]}; do
  57. case ${check} in
  58. --no-install)
  59. NO_INSTALL=
  60. ;;
  61. --updateoverride)
  62. UPDATE_OVERRIDE=
  63. ;;
  64. --buildpkg-rm)
  65. BUILDPKG_RM=
  66. ;;
  67. esac
  68. done
  69. ########################################################
  70. # PRESENCE OF WINE
  71. # Check presence of Wine. Some version of Wine should
  72. # be found in the system in order to install DXVK.
  73. known_wines=(
  74. 'wine'
  75. 'wine-stable'
  76. 'wine32'
  77. 'wine64'
  78. 'libwine:amd64'
  79. 'libwine:i386'
  80. 'wine-git'
  81. 'wine-staging-git'
  82. )
  83. function runtimeCheck() {
  84. # Friendly name for this package
  85. local pkgreq_name=${1}
  86. # Known package names to check on Debian
  87. local known_pkgs=${2}
  88. # Check if any of these Wine packages are present on the system
  89. i=0
  90. for pkg in ${known_pkgs[@]}; do
  91. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -eq 0 ]]; then
  92. local pkglist[$i]=${pkg}
  93. let i++
  94. fi
  95. done
  96. if [[ -z ${pkglist[*]} ]]; then
  97. echo -e "\e[1mWARNING:\e[0m Not installing DXVK because \e[1m${pkgreq_name}\e[0m is missing on your system.\n\
  98. ${pkgreq_name} should be installed in order to use DXVK. Just compiling DXVK for later use.\n"
  99. # Do this check separately so we can warn about all missing runtime dependencies above
  100. if [[ ! -v NO_INSTALL ]]; then
  101. # Force --no-install switch
  102. NO_INSTALL=
  103. fi
  104. fi
  105. }
  106. ########################################################
  107. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  108. function DXVK_intCleanup() {
  109. rm -rf ${DXVKROOT}/{dxvk-git,meson,glslang}
  110. rm -rf ${DXVKROOT}/../compiled_deb/"${datedir}"
  111. exit 0
  112. }
  113. # Allow interruption of the script at any time (Ctrl + C)
  114. trap "DXVK_intCleanup" INT
  115. ########################################################
  116. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  117. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  118. ########################################################
  119. # Update all packages if UPDATE_OVERRIDE given
  120. if [[ -v UPDATE_OVERRIDE ]]; then
  121. echo -en "Updating all packages" && \
  122. if [[ $(printf $(sudo -n uptime &>/dev/null)$?) -ne 0 ]]; then printf " Please provide your sudo password.\n"; else printf "\n\n"; fi
  123. sudo apt update && sudo apt upgrade -y
  124. fi
  125. ########################################################
  126. # Check do we need to compile the package
  127. # given as input for this function
  128. function pkgcompilecheck() {
  129. local install_function=${1}
  130. local pkg=${2}
  131. local pkg_data=${3}
  132. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -ne 0 ]] || [[ -v UPDATE_OVERRIDE ]]; then
  133. ${install_function} ${pkg_data}
  134. fi
  135. }
  136. ########################################################
  137. # DXVK CUSTOM INSTALLATION HOOKS
  138. # These are custom installation instructions for DXVK
  139. # They are not used independently.
  140. function dxvk_install_custom() {
  141. # Use posix alternates for MinGW binaries
  142. function dxvk_posixpkgs() {
  143. local packages=(
  144. 'i686-w64-mingw32-g++'
  145. 'i686-w64-mingw32-gcc'
  146. 'x86_64-w64-mingw32-g++'
  147. 'x86_64-w64-mingw32-gcc'
  148. )
  149. for package in "${packages[@]}"; do
  150. local option=$(echo "" | sudo update-alternatives --config "${package}" | grep posix | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
  151. echo "${option}" | sudo update-alternatives --config "${package}" &> /dev/null
  152. if [[ $? -ne 0 ]]; then
  153. echo -e "\e[1mERROR:\e[0m Error occured while running 'update-alternatives' for '${package}'. Aborting\n"
  154. exit 1
  155. fi
  156. done
  157. }
  158. ############################
  159. # DXVK - CUSTOM PATCHES
  160. # Add and apply custom DXVK patches
  161. function dxvk_custompatches() {
  162. # Get our current directory, since we will change it during patching process below
  163. # We want to go back here after having applied the patches
  164. local CURDIR="${PWD}"
  165. # Check if the following folder exists, and proceed.
  166. if [[ -d "${DXVKROOT}/../../dxvk_custom_patches" ]]; then
  167. cp -r "${DXVKROOT}/../../dxvk_custom_patches/"*.{patch,diff} "${DXVKROOT}/${pkg_name}/" 2>/dev/null
  168. local dxvk_builddir_name=$(ls -l "${DXVKROOT}/${pkg_name}" | grep ^d | awk '{print $NF}')
  169. # TODO Expecting just one folder here. This method doesn't work with multiple dirs present
  170. if [[ $(echo ${dxvk_builddir_name} | wc -l) -gt 1 ]]; then
  171. echo -e "\e[1mERROR:\e[0m Multiple entries in dxvk build directory detected. Can't decide which one to use. Aborting\n"
  172. exit 1
  173. fi
  174. local dxvk_builddir_path="${DXVKROOT}/${pkg_name}/${dxvk_builddir_name}"
  175. cd "${dxvk_builddir_path}"
  176. for pfile in ../*.{patch,diff}; do
  177. if [[ -f ${pfile} ]]; then
  178. echo -e "Applying DXVK patch: ${pfile}\n"
  179. patch -Np1 < ${pfile}
  180. fi
  181. if [[ $? -ne 0 ]]; then
  182. echo -e "\e[1mERROR:\e[0m Error occured while applying DXVK patch '${pfile}'. Aborting\n"
  183. cd ${CURDIR}
  184. exit 1
  185. fi
  186. done
  187. cd "${CURDIR}"
  188. fi
  189. }
  190. ############################
  191. # DXVK - CUSTOM HOOKS EXECUTION
  192. dxvk_custompatches && \
  193. dxvk_posixpkgs && \
  194. dxvk_custom_deb_build
  195. }
  196. ########################################################
  197. # COMMON - COMPILE AND INSTALL DEB PACKAGE
  198. # Instructions to compile and install a deb package
  199. # on Debian system
  200. # Global variable to track buildtime dependencies
  201. z=0
  202. function compile_and_install_deb() {
  203. ############################
  204. # Set local variables
  205. local _pkg_name="${1}"
  206. local _pkg_license="${2}"
  207. local _pkg_giturl="${3}"
  208. local _pkg_gitbranch="${4}"
  209. local _git_commithash="${5}"
  210. local _pkg_gitver="${6}"
  211. local _pkg_debinstall="${7}"
  212. local _pkg_debcontrol="${8}"
  213. local _pkg_debrules="${9}"
  214. local _pkg_installfile="${10}"
  215. local _pkg_controlfile="${11}"
  216. local _pkg_rulesfile="${12}"
  217. local _pkg_deps_build="${13}"
  218. local _pkg_deps_runtime="${14}"
  219. local _pkg_debbuilder="${15}"
  220. ############################
  221. # COMMON - ARRAY PARAMETER FIX
  222. # Separate array indexes correctly
  223. # We have streamed all array indexes, separated
  224. # by | symbol. We reconstruct the arrays here.
  225. function arrayparser_reverse() {
  226. local arrays=(
  227. '_pkg_deps_build'
  228. '_pkg_deps_runtime'
  229. )
  230. for w in ${arrays[@]}; do
  231. local s=\${${w}}
  232. local IFS='|'
  233. local y=0
  234. for t in $(eval printf '%s\|' ${s}); do
  235. eval ${w}[$y]=\"${t}\"
  236. let y++
  237. done
  238. unset IFS
  239. done
  240. }
  241. arrayparser_reverse
  242. ############################
  243. echo -e "Starting compilation$(if [[ ! -v NO_INSTALL ]] || [[ ${_pkg_name} =~ ^meson|glslang$ ]]; then printf " & installation"; fi) of ${_pkg_name}\n"
  244. ############################
  245. # COMMON - PACKAGE DEPENDENCIES CHECK
  246. # Check and install package related dependencies if they are missing
  247. function pkg_dependencies() {
  248. local _pkg_list="${1}"
  249. local _pkg_type="${2}"
  250. local IFS=$'\n'
  251. case ${_pkg_type} in
  252. buildtime)
  253. local _pkg_type_str="build time"
  254. ;;
  255. runtime)
  256. local _pkg_type_str="runtime"
  257. ;;
  258. esac
  259. if [[ ${_pkg_list[0]} == "empty" ]]; then
  260. return 0
  261. fi
  262. # Generate a list of missing dependencies
  263. local a=0
  264. for p in ${_pkg_list[@]}; do
  265. local p=$(printf '%s' ${p} | awk '{print $1}')
  266. if [[ $(echo $(dpkg -s ${p} &>/dev/null)$?) -ne 0 ]]; then
  267. local _validlist[$a]=${p}
  268. let a++
  269. # Global array to track installed build dependencies
  270. if [[ ${_pkg_type} == "buildtime" ]]; then
  271. _buildpkglist[$z]=${p}
  272. let z++
  273. fi
  274. fi
  275. done
  276. # Install missing dependencies, be informative
  277. local b=0
  278. for _pkg_dep in ${_validlist[@]}; do
  279. echo -e "$(( $b + 1 ))/$(( ${#_validlist[*]} )) - Installing ${_pkg_name} ${_pkg_type_str} dependency ${_pkg_dep}"
  280. sudo apt install -y ${_pkg_dep} &> /dev/null
  281. if [[ $? -eq 0 ]]; then
  282. let b++
  283. else
  284. echo -e "\n\e[1mERROR:\e[0m Error occured while installing ${_pkg_dep}. Aborting.\n"
  285. exit 1
  286. fi
  287. done
  288. if [[ -n ${_validlist[*]} ]]; then
  289. # Add empty newline
  290. echo ""
  291. fi
  292. }
  293. ############################
  294. # COMMON - RETRIEVE PACKAGE
  295. # GIT VERSION TAG
  296. # Get git-based version in order to rename the package main folder
  297. # This is required by deb builder. It retrieves the version number
  298. # from that folder name
  299. function pkg_gitversion() {
  300. if [[ -n "${_pkg_gitver}" ]] && [[ "${_pkg_gitver}" =~ ^git ]]; then
  301. cd ${_pkg_name}
  302. git checkout ${_pkg_gitbranch}
  303. git reset --hard ${_git_commithash}
  304. if [[ $? -ne 0 ]]; then
  305. echo -e "\e[1mERROR:\e[0m Couldn't find commit ${_git_commithash} for ${_pkg_name}. Aborting\n"
  306. exit 1
  307. fi
  308. _pkg_gitver=$(eval "${_pkg_gitver}")
  309. cd ..
  310. fi
  311. }
  312. ############################
  313. # COMMON - OVERWRITE
  314. # DEBIAN BUILD ENV FILES
  315. # Overwrite a file which is given as user input
  316. # The contents are supplied as input, too.
  317. function pkg_override_debianfile() {
  318. local contents=${1}
  319. local targetfile=${2}
  320. if [[ ${contents} != "empty" ]]; then
  321. echo "${contents}" > "${targetfile}"
  322. if [[ $? -ne 0 ]]; then
  323. echo -e "\e[1mERROR:\e[0m Couldn't create Debian file '${targetfile}' for ${_pkg_name}. Aborting\n"
  324. exit 1
  325. fi
  326. fi
  327. }
  328. ############################
  329. # COMMON - GET SOURCE AND
  330. # PREPARE SOURCE FOLDER
  331. function pkg_folderprepare() {
  332. # Remove old build directory, if present
  333. rm -rf ${_pkg_name}
  334. # Create a new build directory, access it and download git sources there
  335. mkdir ${_pkg_name}
  336. cd ${_pkg_name}
  337. echo -e "Retrieving source code of ${_pkg_name} from $(printf ${_pkg_giturl} | sed 's/^.*\/\///; s/\/.*//')\n"
  338. git clone ${_pkg_giturl} ${_pkg_name}
  339. # If sources could be downloaded, rename the folder properly for deb builder
  340. # Access the folder after which package specific debianbuild function will be run
  341. # That function is defined inside package specific install_main function below
  342. if [[ $? -eq 0 ]]; then
  343. pkg_gitversion && \
  344. mv ${_pkg_name} ${_pkg_name}-${_pkg_gitver}
  345. cd ${_pkg_name}-${_pkg_gitver}
  346. dh_make --createorig -s -y -c ${_pkg_license} && \
  347. pkg_override_debianfile "${_pkg_debinstall}" "${_pkg_installfile}"
  348. pkg_override_debianfile "${_pkg_debcontrol}" "${_pkg_controlfile}"
  349. pkg_override_debianfile "${_pkg_debrules}" "${_pkg_rulesfile}"
  350. else
  351. echo -e "\e[1mERROR:\e[0m Error while downloading source of ${_pkg_name} package. Aborting\n"
  352. exit 1
  353. fi
  354. }
  355. ############################
  356. # COMMON - COMPILE, INSTALL
  357. # AND STORE DEB PACKAGE
  358. function pkg_debianbuild() {
  359. # Start deb builder
  360. bash -c "${_pkg_debbuilder}"
  361. # Once our deb package is compiled, install and store it
  362. # We do not make installation optional because this is a core dependency for DXVK
  363. if [[ $? -eq 0 ]]; then
  364. rm -rf ../*.{changes,buildinfo,tar.xz} && \
  365. sudo dpkg -i ../${_pkg_name}*.deb && \
  366. mv ../${_pkg_name}*.deb ../../../compiled_deb/"${datedir}" && \
  367. echo -e "Compiled ${_pkg_name} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  368. cd ../..
  369. rm -rf ${_pkg_name}
  370. else
  371. buildpkg_removal
  372. exit 1
  373. fi
  374. }
  375. ############################
  376. # COMMON - EXECUTION HOOKS
  377. pkg_dependencies "${_pkg_deps_build[*]}" buildtime && \
  378. if [[ ${_pkg_deps_runtime[0]} != "empty" ]] && [[ ! -v NO_INSTALL ]]; then
  379. pkg_dependencies "${_pkg_deps_runtime[*]}" runtime
  380. fi
  381. pkg_folderprepare
  382. # TODO use package name or separate override switch here?
  383. if [[ ${_pkg_name} == *"dxvk"* ]]; then
  384. dxvk_install_custom
  385. fi
  386. pkg_debianbuild
  387. unset _pkg_gitver
  388. }
  389. ########################################################
  390. # BUILD DEPENDENCIES REMOVAL
  391. function buildpkg_removal() {
  392. # Build time dependencies which were installed but no longer needed
  393. if [[ -v _buildpkglist ]]; then
  394. if [[ -v BUILDPKG_RM ]]; then
  395. sudo apt purge --remove -y ${_buildpkglist[*]}
  396. # In some cases, glslang or meson may still be present on the system. Remove them
  397. for _extrapkg in glslang meson; do
  398. if [[ $(echo $(dpkg -s ${_extrapkg} &>/dev/null)$?) -eq 0 ]]; then
  399. sudo apt purge --remove -y ${_extrapkg}
  400. fi
  401. done
  402. else
  403. echo -e "The following build time dependencies were installed and no longer needed:\n\n$(for l in ${_buildpkglist[*]}; do echo -e ${l}; done)\n"
  404. fi
  405. fi
  406. }
  407. ########################################################
  408. # Package installation instructions
  409. function pkg_install_main() {
  410. # Read necessary variables from debdata file
  411. local pkg_datafile=${1}
  412. if [[ -f ${pkg_datafile} ]]; then
  413. source ${pkg_datafile}
  414. else
  415. echo -e "\e[1mERROR:\e[0m Couldn't read datafile '${pkg_datafile}'. Check the file path and try again.\n"
  416. exit 1
  417. fi
  418. ############################
  419. # Prepare these arrays for 'compile_and_install_deb' input
  420. # Separate each array index with | in these arrays
  421. function pkg_arrayparser() {
  422. local pkg_arrays=(
  423. 'pkg_deps_build'
  424. 'pkg_deps_runtime'
  425. )
  426. local IFS=$'\n'
  427. for w in ${pkg_arrays[@]}; do
  428. local s=\${${w}[@]}
  429. local t=$(eval printf '%s\|' ${s})
  430. unset ${w}
  431. eval ${w}=\"${t}\"
  432. done
  433. }
  434. ############################
  435. # Execute package installation procedure
  436. pkg_arrayparser && \
  437. compile_and_install_deb \
  438. "${pkg_name}" \
  439. "${pkg_license}" \
  440. "${pkg_giturl}" \
  441. "${pkg_gitbranch}" \
  442. "${git_commithash}" \
  443. "${pkg_gitver}" \
  444. "${pkg_debinstall}" \
  445. "${pkg_debcontrol}" \
  446. "${pkg_debrules}" \
  447. "${pkg_installfile}" \
  448. "${pkg_controlfile}" \
  449. "${pkg_rulesfile}" \
  450. "${pkg_deps_build}" \
  451. "${pkg_deps_runtime}" \
  452. "${pkg_debbuilder}"
  453. }
  454. ########################################################
  455. # Check existence of known Wine packages
  456. runtimeCheck Wine "${known_wines[*]}"
  457. # Meson - compile (& install)
  458. pkgcompilecheck pkg_install_main meson "${DXVKROOT}/meson.debdata"
  459. # Glslang - compile (& install)
  460. pkgcompilecheck pkg_install_main glslang "${DXVKROOT}/glslang.debdata"
  461. # DXVK - compile (& install)
  462. pkg_install_main "${DXVKROOT}/dxvk.debdata"
  463. # Clean buildtime dependencies
  464. buildpkg_removal