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.

823 lines
23 KiB

6 years ago
6 years ago
  1. #!/bin/env bash
  2. # Compile DXVK git on Debian/Ubuntu/Mint and variants
  3. # Copyright (C) 2019 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[3]}
  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. --no-dxvk)
  68. NO_DXVK=
  69. ;;
  70. esac
  71. done
  72. ########################################################
  73. # Check presence of Wine. Some version of Wine should
  74. # be found in the system in order to install DXVK.
  75. known_wines=(
  76. 'wine'
  77. 'wine-stable'
  78. 'wine32'
  79. 'wine64'
  80. 'libwine:amd64'
  81. 'libwine:i386'
  82. 'wine-git'
  83. 'wine-staging-git'
  84. )
  85. # Alternative remote dependency packages for Debian distributions which offer too old packages for DXVK
  86. #
  87. # Left side: <package name in repositories>,<version_number>
  88. # Right side: package alternative source URL
  89. #
  90. # NOTE: Determine these packages in corresponding debdata files as runtime or buildtime dependencies
  91. #
  92. # As this seems to be a dependency for binutils-mingw packages
  93. function binutils_common_ver() {
  94. if [[ $(dpkg -s binutils-common &>/dev/null)$? -ne 0 ]]; then
  95. sudo apt -y install binutils-common
  96. fi
  97. if [[ $? -eq 0 ]]; then
  98. binutils_ver=$(dpkg -s binutils-common | sed -rn 's/^Version: ([0-9\.]+).*$/\1/p')
  99. fi
  100. }
  101. binutils_common_ver
  102. remotePackagesUrls=(
  103. "http://mirrors.edge.kernel.org/ubuntu/pool/universe/b/binutils-mingw-w64"
  104. "http://mirrors.edge.kernel.org/ubuntu/pool/universe/g/gcc-mingw-w64"
  105. "http://mirrors.edge.kernel.org/ubuntu/pool/universe/m/mingw-w64"
  106. )
  107. remotePackagesPool=(
  108. "gcc-mingw-w64-base"
  109. "mingw-w64-common"
  110. "binutils-mingw-w64-x86-64"
  111. "binutils-mingw-w64-i686"
  112. "mingw-w64-x86-64-dev"
  113. "gcc-mingw-w64-x86-64"
  114. "g++-mingw-w64-x86-64"
  115. "mingw-w64-i686-dev"
  116. "gcc-mingw-w64-i686"
  117. "g++-mingw-w64-i686"
  118. )
  119. typeset -A remotePackagesAlt
  120. for rpp in ${remotePackagesPool[@]}; do
  121. for URL in "${remotePackagesUrls[@]}"; do
  122. # Fetch exact package name and associated date
  123. pkg_data=$(curl -s "${URL}/" | sed -rn 's/.*href="(.*(amd64|all)\.deb)">.*([0-9]{2}\-[A-Za-z]{3}\-[0-9]{4}).*/\1 \3/p' | sed 's/%2B/+/g' | grep "${rpp}")
  124. if [[ ${pkg_data} = "" ]]; then
  125. continue
  126. fi
  127. # Associate Unix-formatted date with the exact package name
  128. IFS=$'\n'
  129. for ps in ${pkg_data[@]}; do
  130. ps_pkg=$(printf "%s" "${ps}" | awk '{print $1}')
  131. ps_date=$(date --date=$(printf "%s" "${ps}" | awk '{print $NF}') +%s)
  132. remotePackagesAltDate+=("${ps_date}|${ps_pkg}")
  133. done
  134. IFS=" "
  135. # Sort exact package names by date
  136. remotePackagesAltDateSorted=($(sort <<<"${remotePackagesAltDate[*]}"))
  137. # binutils packages depend on system binutils-common. Versions must match, even if not the newest package available.
  138. if [[ ${ps_pkg} =~ binutils ]] && [[ ${binutils_ver} != "" ]]; then
  139. for b in ${remotePackagesAltDateSorted[@]}; do
  140. if [[ ${b} =~ ${binutils_ver} ]]; then
  141. remotePackagesAltBinUtils+=(${b})
  142. fi
  143. done
  144. unset remotePackagesAltDateSorted
  145. remotePackagesAltDateSorted=(${remotePackagesAltBinUtils[@]})
  146. unset remotePackagesAltBinUtils
  147. fi
  148. # Get the newest exact package name
  149. pkg=$(printf "%s" ${remotePackagesAltDateSorted[-1]} | sed -r 's/^[0-9]+\|(.*)/\1/')
  150. unset remotePackagesAltDate
  151. unset remotePackagesAltDateSorted
  152. # Prepare and set a well-formatted value into remotePackagesAlt associative array
  153. if [ ! "${pkg}" == "" ]; then
  154. rpp_url=$(printf "%s/%s" "${URL}" "${pkg}")
  155. rpp_shortver=$(printf "%s" "${pkg}" | sed -r 's/.*_(.*[0-9]+)\-.*_(all|amd64).*/\1/g; s/[^0-9]//g')
  156. rpp_token=$(printf "%s,%d" "${rpp}" "${rpp_shortver}")
  157. remotePackagesAlt+=(["${rpp_token}"]="${rpp_url}")
  158. break 1
  159. fi
  160. done
  161. done
  162. # Posix-compliant MingW alternative executables
  163. #
  164. typeset -A alternatives
  165. alternatives=(
  166. [x86_64-w64-mingw32-gcc]="x86_64-w64-mingw32-gcc-posix"
  167. [x86_64-w64-mingw32-g++]="x86_64-w64-mingw32-g++-posix"
  168. [i686-w64-mingw32-gcc]="i686-w64-mingw32-gcc-posix"
  169. [i686-w64-mingw32-g++]="i686-w64-mingw32-g++-posix"
  170. )
  171. # Temporary symbolic links for DXVK compilation
  172. #
  173. typeset -A tempLinks
  174. tempLinks=(
  175. ['/usr/bin/i686-w64-mingw32-gcc']='/usr/bin/i686-w64-mingw32-gcc-posix'
  176. ['/usr/bin/i686-w64-mingw32-g++']='/usr/bin/i686-w64-mingw32-g++-posix'
  177. ['/usr/bin/x86_64-w64-mingw32-gcc']='x86_64-w64-mingw32-gcc-posix'
  178. ['/usr/bin/x86_64-w64-mingw32-g++']='x86_64-w64-mingw32-g++-posix'
  179. )
  180. ########################################################
  181. function runtimeCheck() {
  182. # Friendly name for this package
  183. local pkgreq_name=${1}
  184. # Known package names to check on Debian
  185. local known_pkgs=${2}
  186. # Check if any of these Wine packages are present on the system
  187. i=0
  188. for pkg in ${known_pkgs[@]}; do
  189. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -eq 0 ]]; then
  190. local pkglist[$i]=${pkg}
  191. let i++
  192. fi
  193. done
  194. if [[ -z ${pkglist[*]} ]]; then
  195. echo -e "\e[1mWARNING:\e[0m Not installing DXVK because \e[1m${pkgreq_name}\e[0m is missing on your system.\n\
  196. ${pkgreq_name} should be installed in order to use DXVK. Just compiling DXVK for later use.\n"
  197. # Do this check separately so we can warn about all missing runtime dependencies above
  198. if [[ ! -v NO_INSTALL ]]; then
  199. # Force --no-install switch
  200. NO_INSTALL=
  201. fi
  202. fi
  203. }
  204. ########################################################
  205. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  206. function DXVK_intCleanup() {
  207. rm -rf ${DXVKROOT}/{dxvk-git,meson,glslang,*.deb}
  208. rm -rf ${DXVKROOT}/../compiled_deb/"${datedir}"
  209. exit 0
  210. }
  211. # Allow interruption of the script at any time (Ctrl + C)
  212. trap "DXVK_intCleanup" INT
  213. # Error event
  214. #trap "DXVK_intCleanup" ERR
  215. ########################################################
  216. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  217. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  218. ########################################################
  219. # Update all packages if UPDATE_OVERRIDE given
  220. if [[ -v UPDATE_OVERRIDE ]]; then
  221. echo -en "Updating all packages" && \
  222. if [[ $(printf $(sudo -n uptime &>/dev/null)$?) -ne 0 ]]; then printf " Please provide your sudo password.\n"; else printf "\n\n"; fi
  223. sudo apt update && sudo apt upgrade -y
  224. fi
  225. ########################################################
  226. # Check do we need to compile the package
  227. # given as input for this function
  228. function pkgcompilecheck() {
  229. local install_function=${1}
  230. local pkg=${2}
  231. local pkg_data=${3}
  232. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -ne 0 ]] || [[ -v UPDATE_OVERRIDE ]]; then
  233. ${install_function} ${pkg_data}
  234. fi
  235. }
  236. ########################################################
  237. # DXVK CUSTOM INSTALLATION HOOKS
  238. # These are custom installation instructions for DXVK
  239. # They are not used independently.
  240. function dxvk_install_custom() {
  241. local PATCHDIR="${1}"
  242. # Use posix alternates for MinGW binaries
  243. function dxvk_posixpkgs() {
  244. for alt in ${!alternatives[@]}; do
  245. echo "Linking MingW executable ${alt} to ${alternatives[$alt]}"
  246. sudo rm -rf /etc/alternatives/"${alt}" 2>/dev/null
  247. sudo ln -sf /usr/bin/"${alternatives[$alt]}" /etc/alternatives/"${alt}"
  248. if [[ $? -ne 0 ]]; then
  249. echo -e "\e[1mERROR:\e[0m Error occured while linking executable ${alt} to ${alternatives[$alt]}. Aborting\n"
  250. exit 1
  251. fi
  252. done
  253. for link in ${!tempLinks[@]}; do
  254. if [[ ! -f ${link} ]]; then
  255. echo "Creating temporary links for MingW executable ${link}"
  256. sudo ln -sf ${tempLinks["${link}"]} "${link}"
  257. if [[ $? -ne 0 ]]; then
  258. echo -e "\e[1mERROR:\e[0m Error occured while linking executable ${link}. Aborting\n"
  259. exit 1
  260. fi
  261. fi
  262. done
  263. }
  264. ############################
  265. # DXVK - CUSTOM PATCHES
  266. # Add and apply custom DXVK patches
  267. function dxvk_custompatches() {
  268. # Get our current directory, since we will change it during patching process below
  269. # We want to go back here after having applied the patches
  270. local CURDIR="${PWD}"
  271. # Check if the following folder exists, and proceed.
  272. if [[ -d "${DXVKROOT}/../../${PATCHDIR}" ]]; then
  273. cp -r "${DXVKROOT}/../../${PATCHDIR}/"*.{patch,diff} "${DXVKROOT}/${pkg_name}/" 2>/dev/null
  274. local dxvk_builddir_name=$(ls -l "${DXVKROOT}/${pkg_name}" | grep ^d | awk '{print $NF}')
  275. # TODO Expecting just one folder here. This method doesn't work with multiple dirs present
  276. if [[ $(echo ${dxvk_builddir_name} | wc -l) -gt 1 ]]; then
  277. echo -e "\e[1mERROR:\e[0m Multiple entries in dxvk build directory detected. Can't decide which one to use. Aborting\n"
  278. exit 1
  279. fi
  280. local dxvk_builddir_path="${DXVKROOT}/${pkg_name}/${dxvk_builddir_name}"
  281. cd "${dxvk_builddir_path}"
  282. for pfile in ../*.{patch,diff}; do
  283. if [[ -f ${pfile} ]]; then
  284. echo -e "Applying DXVK patch: ${pfile}\n"
  285. patch -Np1 < ${pfile}
  286. fi
  287. if [[ $? -ne 0 ]]; then
  288. echo -e "\e[1mERROR:\e[0m Error occured while applying DXVK patch '${pfile}'. Aborting\n"
  289. cd ${CURDIR}
  290. exit 1
  291. fi
  292. done
  293. cd "${CURDIR}"
  294. fi
  295. }
  296. ############################
  297. # DXVK - CUSTOM HOOKS EXECUTION
  298. dxvk_custompatches && \
  299. dxvk_posixpkgs
  300. }
  301. ########################################################
  302. # COMMON - COMPILE AND INSTALL DEB PACKAGE
  303. # Instructions to compile and install a deb package
  304. # on Debian system
  305. # Global variable to track buildtime dependencies
  306. z=0
  307. function compile_and_install_deb() {
  308. ############################
  309. # Set local variables
  310. local _pkg_name="${1}"
  311. local _pkg_license="${2}"
  312. local _pkg_giturl="${3}"
  313. local _pkg_gitbranch="${4}"
  314. local _git_commithash="${5}"
  315. local _pkg_gitver="${6}"
  316. local _pkg_debinstall="${7}"
  317. local _pkg_debcontrol="${8}"
  318. local _pkg_debrules="${9}"
  319. local _pkg_installfile="${10}"
  320. local _pkg_controlfile="${11}"
  321. local _pkg_rulesfile="${12}"
  322. local _pkg_deps_build="${13}"
  323. local _pkg_deps_runtime="${14}"
  324. local _pkg_debbuilder="${15}"
  325. local _pkg_debcompat="${16}"
  326. local _pkg_compatfile="${17}"
  327. ############################
  328. # COMMON - ARRAY PARAMETER FIX
  329. # Separate array indexes correctly
  330. # We have streamed all array indexes, separated
  331. # by | symbol. We reconstruct the arrays here.
  332. function arrayparser_reverse() {
  333. local arrays=(
  334. '_pkg_deps_build'
  335. '_pkg_deps_runtime'
  336. )
  337. for w in ${arrays[@]}; do
  338. local s=\${${w}}
  339. local IFS='|'
  340. local y=0
  341. for t in $(eval printf '%s\|' ${s}); do
  342. eval ${w}[$y]=\"${t}\"
  343. let y++
  344. done
  345. unset IFS
  346. done
  347. }
  348. arrayparser_reverse
  349. ############################
  350. function pkg_installcheck() {
  351. return $(echo $(dpkg -s "${1}" &>/dev/null)$?)
  352. }
  353. ############################
  354. echo -e "Starting compilation$(if [[ ! -v NO_INSTALL ]] || [[ ${_pkg_name} =~ ^meson|glslang$ ]]; then printf " & installation"; fi) of ${_pkg_name}\n"
  355. ############################
  356. # COMMON - PACKAGE DEPENDENCIES CHECK
  357. # Check and install package related dependencies if they are missing
  358. function pkg_dependencies() {
  359. local _pkg_list="${1}"
  360. local _pkg_type="${2}"
  361. local IFS=$'\n'
  362. _pkg_list=$(echo "${_pkg_list}" | sed 's/([^)]*)//g')
  363. unset IFS
  364. case ${_pkg_type} in
  365. buildtime)
  366. local _pkg_type_str="build time"
  367. ;;
  368. runtime)
  369. local _pkg_type_str="runtime"
  370. ;;
  371. esac
  372. if [[ ${_pkg_list[0]} == "empty" ]]; then
  373. return 0
  374. fi
  375. # Generate a list of missing dependencies
  376. local a=0
  377. for p in ${_pkg_list[@]}; do
  378. if [[ $(pkg_installcheck ${p})$? -eq 0 ]]; then
  379. local _validlist[$a]=${p}
  380. let a++
  381. # Global array to track installed build dependencies
  382. if [[ ${_pkg_type} == "buildtime" ]]; then
  383. _buildpkglist[$z]="${p}"
  384. let z++
  385. fi
  386. fi
  387. done
  388. function pkg_remoteinstall() {
  389. sudo apt install -y ${1} &> /dev/null
  390. }
  391. function pkg_localinstall() {
  392. wget ${1} -O ${DXVKROOT}/"${2}".deb
  393. sudo dpkg -i --force-all ${DXVKROOT}/"${2}".deb
  394. }
  395. function pkg_configure() {
  396. if [[ $(sudo dpkg-reconfigure ${1} | grep "is broken or not fully installed") ]]; then
  397. if [[ -v ${2} ]]; then
  398. pkg_localinstall ${2} ${1}
  399. else
  400. pkg_remoteinstall ${1}
  401. fi
  402. fi
  403. }
  404. # Install missing dependencies, be informative
  405. local b=0
  406. for _pkg_dep in ${_validlist[@]}; do
  407. echo -e "$(( $b + 1 ))/$(( ${#_validlist[*]} )) - Installing ${_pkg_name} ${_pkg_type_str} dependency ${_pkg_dep}"
  408. if [[ ${#remotePackagesAlt[@]} -gt 0 ]]; then
  409. for altRemote in ${!remotePackagesAlt[@]}; do
  410. altRemotepkg=$(echo ${altRemote} | awk -F ',' '{print $1}')
  411. altRemotever=$(echo ${altRemote} | awk -F ',' '{print $2}')
  412. if [[ "${_pkg_dep}" == "${altRemotepkg}" ]]; then
  413. if [[ $(pkg_installcheck ${altRemotepkg})$? -ne 0 ]]; then
  414. # TODO remove duplicate functionality
  415. if [[ $(apt-cache show "${altRemotepkg}" | grep -m1 -oP "(?<=^Version: )[0-9|\.]*" | sed 's/\.//g') < ${altRemotever} ]]; then
  416. pkg_localinstall ${remotePackagesAlt["${altRemote}"]} "${altRemotepkg}"
  417. pkg_configure "${altRemotepkg}" ${remotePackagesAlt["${altRemote}"]}
  418. else
  419. pkg_remoteinstall "${altRemotepkg}"
  420. pkg_configure "${altRemotepkg}"
  421. fi
  422. else
  423. if [[ $(dpkg -s "${altRemotepkg}" | grep -m1 -oP "(?<=^Version: )[0-9|\.]*" | sed 's/\.//g') < ${altRemotever} ]]; then
  424. pkg_localinstall ${remotePackagesAlt["${altRemote}"]} "${altRemotepkg}"
  425. pkg_configure "${altRemotepkg}" ${remotePackagesAlt["${altRemote}"]}
  426. else
  427. pkg_remoteinstall "${altRemotepkg}"
  428. pkg_configure "${altRemotepkg}"
  429. fi
  430. fi
  431. fi
  432. done
  433. fi
  434. if [[ $(pkg_installcheck ${_pkg_dep})$? -ne 0 ]]; then
  435. pkg_remoteinstall "${_pkg_dep}"
  436. pkg_configure "${_pkg_dep}"
  437. fi
  438. if [[ $? -eq 0 ]]; then
  439. let b++
  440. else
  441. echo -e "\n\e[1mERROR:\e[0m Error occured while installing ${_pkg_dep}. Aborting.\n"
  442. exit 1
  443. fi
  444. done
  445. if [[ -n ${_validlist[*]} ]]; then
  446. # Add empty newline
  447. echo ""
  448. fi
  449. }
  450. ############################
  451. # COMMON - RETRIEVE PACKAGE
  452. # GIT VERSION TAG
  453. # Get git-based version in order to rename the package main folder
  454. # This is required by deb builder. It retrieves the version number
  455. # from that folder name
  456. function pkg_gitversion() {
  457. if [[ -n "${_pkg_gitver}" ]] && [[ "${_pkg_gitver}" =~ ^git ]]; then
  458. cd ${_pkg_name}
  459. git checkout ${_pkg_gitbranch}
  460. git reset --hard ${_git_commithash}
  461. if [[ $? -ne 0 ]]; then
  462. echo -e "\e[1mERROR:\e[0m Couldn't find commit ${_git_commithash} for ${_pkg_name}. Aborting\n"
  463. exit 1
  464. fi
  465. _pkg_gitver=$(eval "${_pkg_gitver}")
  466. cd ..
  467. fi
  468. }
  469. ############################
  470. # COMMON - OVERWRITE
  471. # DEBIAN BUILD ENV FILES
  472. # Overwrite a file which is given as user input
  473. # The contents are supplied as input, too.
  474. function pkg_override_debianfile() {
  475. local contents=${1}
  476. local targetfile=${2}
  477. if [[ ${contents} != "empty" ]]; then
  478. echo "${contents}" > "${targetfile}"
  479. if [[ $? -ne 0 ]]; then
  480. echo -e "\e[1mERROR:\e[0m Couldn't create Debian file '${targetfile}' for ${_pkg_name}. Aborting\n"
  481. exit 1
  482. fi
  483. fi
  484. }
  485. ############################
  486. # COMMON - GET SOURCE AND
  487. # PREPARE SOURCE FOLDER
  488. function pkg_folderprepare() {
  489. # Remove old build directory, if present
  490. rm -rf ${_pkg_name}
  491. # Create a new build directory, access it and download git sources there
  492. mkdir ${_pkg_name}
  493. cd ${_pkg_name}
  494. echo -e "Retrieving source code of ${_pkg_name} from $(printf ${_pkg_giturl} | sed 's/^.*\/\///; s/\/.*//')\n"
  495. git clone ${_pkg_giturl} ${_pkg_name}
  496. # If sources could be downloaded, rename the folder properly for deb builder
  497. # Access the folder after which package specific debianbuild function will be run
  498. # That function is defined inside package specific install_main function below
  499. if [[ $? -eq 0 ]]; then
  500. pkg_gitversion && \
  501. mv ${_pkg_name} ${_pkg_name}-${_pkg_gitver}
  502. cd ${_pkg_name}-${_pkg_gitver}
  503. dh_make --createorig -s -y -c ${_pkg_license} && \
  504. pkg_override_debianfile "${_pkg_debinstall}" "${_pkg_installfile}"
  505. pkg_override_debianfile "${_pkg_debcontrol}" "${_pkg_controlfile}"
  506. pkg_override_debianfile "${_pkg_debrules}" "${_pkg_rulesfile}"
  507. pkg_override_debianfile "${_pkg_debcompat}" "${_pkg_compatfile}"
  508. else
  509. echo -e "\e[1mERROR:\e[0m Error while downloading source of ${_pkg_name} package. Aborting\n"
  510. exit 1
  511. fi
  512. }
  513. ############################
  514. # COMMON - COMPILE, INSTALL
  515. # AND STORE DEB PACKAGE
  516. function pkg_debianbuild() {
  517. # Start deb builder
  518. bash -c "${_pkg_debbuilder}"
  519. # Once our deb package is compiled, install and store it
  520. # We do not make installation optional for deps because they are required by DXVK
  521. if [[ $? -eq 0 ]]; then
  522. rm -rf ../*.{changes,buildinfo,tar.xz}
  523. if [[ "${_pkg_name}" == *"dxvk"* ]] && [[ ! -v NO_INSTALL ]]; then
  524. sudo dpkg -i ../${_pkg_name}*.deb
  525. elif [[ "${_pkg_name}" != *"dxvk"* ]]; then
  526. sudo dpkg -i ../${_pkg_name}*.deb
  527. fi
  528. mv ../${_pkg_name}*.deb ../../../compiled_deb/"${datedir}" && \
  529. echo -e "Compiled ${_pkg_name} is stored at '$(readlink -f ../../../compiled_deb/"${datedir}")/'\n"
  530. cd ../..
  531. rm -rf {${_pkg_name},*.deb}
  532. else
  533. buildpkg_removal
  534. exit 1
  535. fi
  536. }
  537. ############################
  538. # COMMON - EXECUTION HOOKS
  539. pkg_dependencies "${_pkg_deps_build[*]}" buildtime
  540. if [[ ${_pkg_deps_runtime[0]} != "empty" ]] && [[ ! -v NO_INSTALL ]]; then
  541. pkg_dependencies "${_pkg_deps_runtime[*]}" runtime
  542. fi
  543. pkg_folderprepare
  544. # TODO use package name or separate override switch here?
  545. if [[ "${_pkg_name}" == *"dxvk"* ]]; then
  546. dxvk_install_custom "dxvk_custom_patches"
  547. fi
  548. pkg_debianbuild
  549. unset _pkg_gitver
  550. }
  551. ########################################################
  552. # BUILD DEPENDENCIES REMOVAL
  553. function buildpkg_removal() {
  554. _buildpkglist=($(echo ${_buildpkglist[@]} | tr ' ' '\n' |sort -u | tr '\n' ' '))
  555. for link in ${!tempLinks[@]}; do
  556. if [[ $(file ${link}) == *"symbolic link"* ]]; then
  557. sudo rm -f "${link}"
  558. fi
  559. done
  560. # Build time dependencies which were installed but no longer needed
  561. if [[ -v _buildpkglist ]]; then
  562. if [[ -v BUILDPKG_RM ]]; then
  563. sudo apt purge --remove -y ${_buildpkglist[*]}
  564. # In some cases, glslang or meson may still be present on the system. Remove them
  565. for _extrapkg in glslang meson; do
  566. if [[ $(echo $(dpkg -s ${_extrapkg} &>/dev/null)$?) -eq 0 ]]; then
  567. sudo dpkg --remove --force-remove-reinstreq ${_extrapkg}
  568. fi
  569. done
  570. # Manually obtained deb packages are expected to break system configuration, thus we need to fix it.
  571. sudo apt --fix-broken -y install
  572. else
  573. 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"
  574. fi
  575. fi
  576. }
  577. ########################################################
  578. # Package installation instructions
  579. function pkg_install_main() {
  580. # Read necessary variables from debdata file
  581. local pkg_datafile=${1}
  582. if [[ -f ${pkg_datafile} ]]; then
  583. source ${pkg_datafile}
  584. else
  585. echo -e "\e[1mERROR:\e[0m Couldn't read datafile '${pkg_datafile}'. Check the file path and try again.\n"
  586. exit 1
  587. fi
  588. ############################
  589. # Prepare these arrays for 'compile_and_install_deb' input
  590. # Separate each array index with | in these arrays
  591. function pkg_arrayparser() {
  592. local pkg_arrays=(
  593. 'pkg_deps_build'
  594. 'pkg_deps_runtime'
  595. )
  596. local IFS=$'\n'
  597. for w in ${pkg_arrays[@]}; do
  598. local s=\${${w}[@]}
  599. local t=$(eval printf '%s\|' ${s})
  600. unset ${w}
  601. eval ${w}=\"${t}\"
  602. done
  603. }
  604. ############################
  605. # Execute package installation procedure
  606. pkg_arrayparser && \
  607. compile_and_install_deb \
  608. "${pkg_name}" \
  609. "${pkg_license}" \
  610. "${pkg_giturl}" \
  611. "${pkg_gitbranch}" \
  612. "${git_commithash}" \
  613. "${pkg_gitver}" \
  614. "${pkg_debinstall}" \
  615. "${pkg_debcontrol}" \
  616. "${pkg_debrules}" \
  617. "${pkg_installfile}" \
  618. "${pkg_controlfile}" \
  619. "${pkg_rulesfile}" \
  620. "${pkg_deps_build}" \
  621. "${pkg_deps_runtime}" \
  622. "${pkg_debbuilder}" \
  623. "${pkg_debcompat}" \
  624. "${pkg_compatfile}"
  625. }
  626. ########################################################
  627. # Check existence of known Wine packages
  628. runtimeCheck Wine "${known_wines[*]}"
  629. # Meson - compile (& install)
  630. pkgcompilecheck pkg_install_main meson "${DXVKROOT}/meson.debdata"
  631. # Glslang - compile (& install)
  632. pkgcompilecheck pkg_install_main glslang "${DXVKROOT}/glslang.debdata"
  633. if [[ ! -v NO_DXVK ]]; then
  634. # DXVK - compile (& install)
  635. pkg_install_main "${DXVKROOT}/dxvk.debdata"
  636. fi
  637. # Clean buildtime dependencies
  638. buildpkg_removal