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.

643 lines
15 KiB

5 years ago
  1. #!/bin/env bash
  2. # Wine/Wine Staging build script for Ubuntu & variants (amd64)
  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 variable supplied by ../updatewine_debian.sh script file
  21. datedir="${1}"
  22. ########################################################
  23. # Staging patchsets. Default: all patchsets.
  24. # Applies only if Wine Staging is set to be compiled
  25. # Please see Wine Staging patchinstall.sh file for individual patchset names.
  26. staging_patchsets=(--all)
  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. ;;
  44. esac
  45. done
  46. ########################################################
  47. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  48. function Wine_intCleanup() {
  49. cd ..
  50. rm -rf winebuild_${datedir}
  51. exit 0
  52. }
  53. # Allow interruption of the script at any time (Ctrl + C)
  54. trap "Wine_intCleanup" INT
  55. ########################################################
  56. # This is specifically for Debian
  57. # Must be done to install Wine buildtime dependencies on amd64 environment
  58. #
  59. if [[ $(dpkg --print-foreign-architectures | grep i386 | wc -l) -eq 0 ]]; then
  60. sudo dpkg --add-architecture i386
  61. sudo apt update
  62. fi
  63. ########################################################
  64. function getWine() {
  65. local wine_url="git://source.winehq.org/git/wine.git"
  66. local winestaging_url="git://github.com/wine-staging/wine-staging.git"
  67. function cleanOldBuilds() {
  68. if [[ $(find . -type d -name "winebuild_*" | wc -l) -ne 0 ]]; then
  69. echo -e "Removing old Wine build folders. This can take a while.\n"
  70. rm -rf ./winebuild_*
  71. fi
  72. }
  73. cleanOldBuilds
  74. mkdir winebuild_${datedir}
  75. cd winebuild_${datedir}
  76. WINEROOT="${PWD}"
  77. echo -e "Retrieving source code of Wine$(if [[ ! -v NO_STAGING ]]; then echo ' & Wine Staging' ; fi)\n"
  78. git clone ${wine_url}
  79. if [[ ! -v NO_STAGING ]]; then
  80. git clone ${winestaging_url}
  81. WINEDIR_STAGING="${WINEROOT}/wine-staging"
  82. PKGNAME="wine-staging-git"
  83. else
  84. PKGNAME="wine-git"
  85. fi
  86. mkdir wine-{patches,32-build,32-install,64-build,64-install,package}
  87. cp -r ../../../wine_custom_patches/*.{patch,diff} wine-patches/ 2>/dev/null
  88. WINEDIR="${WINEROOT}/wine"
  89. WINEDIR_PATCHES="${WINEROOT}/wine-patches"
  90. WINEDIR_BUILD_32="${WINEROOT}/wine-32-build"
  91. WINEDIR_BUILD_64="${WINEROOT}/wine-64-build"
  92. WINEDIR_INSTALL_32="${WINEROOT}/wine-32-install"
  93. WINEDIR_INSTALL_64="${WINEROOT}/wine-64-install"
  94. WINEDIR_PACKAGE="${WINEROOT}/wine-package"
  95. }
  96. function getDebianFiles() {
  97. local debian_archive=wine_3.0-1ubuntu1.debian.tar.xz
  98. cd "${WINEDIR}"
  99. wget http://archive.ubuntu.com/ubuntu/pool/universe/w/wine/${debian_archive}
  100. tar xvf ${debian_archive}
  101. rm ${debian_archive}
  102. }
  103. ########################################################
  104. # Wine build dependency list on Debian
  105. wine_deps_build=(
  106. 'make'
  107. 'gcc-multilib'
  108. 'g++-multilib'
  109. 'libxml-simple-perl'
  110. 'libxml-parser-perl'
  111. 'libxml-libxml-perl'
  112. 'lzma'
  113. 'flex'
  114. 'bison'
  115. 'quilt'
  116. 'gettext'
  117. 'oss4-dev'
  118. 'sharutils'
  119. 'pkg-config'
  120. 'dctrl-tools'
  121. 'khronos-api'
  122. 'unicode-data'
  123. 'freebsd-glue'
  124. 'icoutils'
  125. 'librsvg2-bin'
  126. 'imagemagick'
  127. 'fontforge'
  128. 'libxi-dev:amd64'
  129. 'libxt-dev:amd64'
  130. 'libxmu-dev:amd64'
  131. 'libx11-dev:amd64'
  132. 'libxext-dev:amd64'
  133. 'libxfixes-dev:amd64'
  134. 'libxrandr-dev:amd64'
  135. 'libxcursor-dev:amd64'
  136. 'libxrender-dev:amd64'
  137. 'libxkbfile-dev:amd64'
  138. 'libxxf86vm-dev:amd64'
  139. 'libxxf86dga-dev:amd64'
  140. 'libxinerama-dev:amd64'
  141. 'libgl1-mesa-dev:amd64'
  142. 'libglu1-mesa-dev:amd64'
  143. 'libxcomposite-dev:amd64'
  144. 'libpng-dev:amd64'
  145. 'libssl-dev:amd64'
  146. 'libv4l-dev:amd64'
  147. 'libxml2-dev:amd64'
  148. 'libgsm1-dev:amd64'
  149. 'libjpeg-dev:amd64'
  150. 'libkrb5-dev:amd64'
  151. 'libtiff-dev:amd64'
  152. 'libsane-dev:amd64'
  153. 'libudev-dev:amd64'
  154. 'libpulse-dev:amd64'
  155. 'liblcms2-dev:amd64'
  156. 'libldap2-dev:amd64'
  157. 'libxslt1-dev:amd64'
  158. 'unixodbc-dev:amd64'
  159. 'libcups2-dev:amd64'
  160. 'libcapi20-dev:amd64'
  161. 'libopenal-dev:amd64'
  162. 'libdbus-1-dev:amd64'
  163. 'freeglut3-dev:amd64'
  164. 'libmpg123-dev:amd64'
  165. 'libasound2-dev:amd64'
  166. 'libgphoto2-dev:amd64'
  167. 'libosmesa6-dev:amd64'
  168. 'libpcap0.8-dev:amd64'
  169. 'libgnutls28-dev:amd64'
  170. 'libncurses5-dev:amd64'
  171. 'libgettextpo-dev:amd64'
  172. 'libfreetype6-dev:amd64'
  173. 'libfontconfig1-dev:amd64'
  174. 'libgstreamer-plugins-base1.0-dev:amd64'
  175. 'ocl-icd-opencl-dev:amd64'
  176. 'libvulkan-dev:amd64'
  177. 'libxi-dev:i386'
  178. 'libxt-dev:i386'
  179. 'libxmu-dev:i386'
  180. 'libx11-dev:i386'
  181. 'libxext-dev:i386'
  182. 'libxfixes-dev:i386'
  183. 'libxrandr-dev:i386'
  184. 'libxcursor-dev:i386'
  185. 'libxrender-dev:i386'
  186. 'libxkbfile-dev:i386'
  187. 'libxxf86vm-dev:i386'
  188. 'libxxf86dga-dev:i386'
  189. 'libxinerama-dev:i386'
  190. 'libgl1-mesa-dev:i386'
  191. 'libglu1-mesa-dev:i386'
  192. 'libxcomposite-dev:i386'
  193. 'libpng-dev:i386'
  194. 'libssl-dev:i386'
  195. 'libv4l-dev:i386'
  196. 'libgsm1-dev:i386'
  197. 'libjpeg-dev:i386'
  198. 'libkrb5-dev:i386'
  199. 'libsane-dev:i386'
  200. 'libudev-dev:i386'
  201. 'libpulse-dev:i386'
  202. 'liblcms2-dev:i386'
  203. 'libldap2-dev:i386'
  204. 'unixodbc-dev:i386'
  205. 'libcapi20-dev:i386'
  206. 'libopenal-dev:i386'
  207. 'libdbus-1-dev:i386'
  208. 'freeglut3-dev:i386'
  209. 'libmpg123-dev:i386'
  210. 'libasound2-dev:i386'
  211. 'libgphoto2-dev:i386'
  212. 'libosmesa6-dev:i386'
  213. 'libpcap0.8-dev:i386'
  214. 'libncurses5-dev:i386'
  215. 'libgettextpo-dev:i386'
  216. 'libfreetype6-dev:i386'
  217. 'libfontconfig1-dev:i386'
  218. 'ocl-icd-opencl-dev:i386'
  219. 'libvulkan-dev:i386'
  220. )
  221. # Excluded x86 packages since they conflict with their amd64 counterparts:
  222. #
  223. # libxslt1-dev:i386
  224. # libxml2-dev:i386
  225. # libicu-dev:i386
  226. # libtiff-dev:i386
  227. # libcups2-dev:i386
  228. # libgnutls28-dev:i386
  229. # libgstreamer1.0-dev:i386
  230. # libgstreamer-plugins-base1.0-dev:i386
  231. ########################################################
  232. # Wine runtime dependency list on Debian
  233. wine_deps_runtime=(
  234. 'libxcursor1:i386'
  235. 'libxrandr2:i386'
  236. 'libxi6:i386'
  237. 'libsm6:i386'
  238. 'libvulkan1:i386'
  239. 'libasound2:i386'
  240. 'libc6:i386'
  241. 'libfontconfig1:i386'
  242. 'libfreetype6:i386'
  243. 'libgcc1:i386'
  244. 'libglib2.0-0:i386'
  245. 'libgphoto2-6:i386'
  246. 'libgphoto2-port12:i386'
  247. 'liblcms2-2:i386'
  248. 'libldap-2.4-2:i386'
  249. 'libmpg123-0:i386'
  250. 'libncurses5:i386'
  251. 'libopenal1:i386'
  252. 'libpcap0.8:i386'
  253. 'libpulse0:i386'
  254. 'libtinfo5:i386'
  255. 'libudev1:i386'
  256. 'libx11-6:i386'
  257. 'libxext6:i386'
  258. 'libxml2:i386'
  259. 'ocl-icd-libopencl1:i386'
  260. 'zlib1g:i386'
  261. 'fontconfig:amd64'
  262. 'libxcursor1:amd64'
  263. 'libxrandr2:amd64'
  264. 'libxi6:amd64'
  265. 'gettext:amd64'
  266. 'libsm6:amd64'
  267. 'libvulkan1:amd64'
  268. 'libasound2:amd64'
  269. 'libc6:amd64'
  270. 'libfontconfig1:amd64'
  271. 'libfreetype6:amd64'
  272. 'libgcc1:amd64'
  273. 'libglib2.0-0:amd64'
  274. 'libgphoto2-6:amd64'
  275. 'libgphoto2-port12:amd64'
  276. 'liblcms2-2:amd64'
  277. 'libldap-2.4-2:amd64'
  278. 'libmpg123-0:amd64'
  279. 'libncurses5:amd64'
  280. 'libopenal1:amd64'
  281. 'libpcap0.8:amd64'
  282. 'libpulse0:amd64'
  283. 'libtinfo5:amd64'
  284. 'libudev1:amd64'
  285. 'libx11-6:amd64'
  286. 'libxext6:amd64'
  287. 'libxml2:amd64'
  288. 'ocl-icd-libopencl1:amd64'
  289. 'zlib1g:amd64'
  290. 'desktop-file-utils'
  291. 'libgstreamer-plugins-base1.0-0:amd64'
  292. 'libgstreamer1.0-0:amd64'
  293. )
  294. # Exclude the following i386 runtime dependencies
  295. # because they conflict with their amd64 counterparts:
  296. # gettext:i386
  297. ########################################################
  298. # Wine dependencies:
  299. function WineDeps() {
  300. local a=0
  301. local deps="${1}"
  302. local depsname=${2}
  303. echo -e "Installing Wine dependencies.\n" # Sudo password may be required.\n"
  304. # TODO should we install all at once, or go iterating the list,
  305. # giving better output for user. Iterative method is slower, though.
  306. #
  307. # sudo apt install -y ${deps[*]}
  308. # if [[ $? -ne 0 ]]; then
  309. # echo -e "Error while installing Wine dependencies. Aborting\n"
  310. # exit 1
  311. # fi
  312. function pkgdependencies() {
  313. for pkgdep in ${@}; do
  314. if [[ $(apt version ${pkgdep} | wc -w) -eq 0 ]]; then
  315. echo -e "Installing ${depsname} dependency ${pkgdep} ($(($a + 1 )) / $((${#*} + 1)))\n."
  316. sudo apt install -y ${pkgdep} &> /dev/null
  317. if [[ $? -eq 0 ]]; then
  318. let a++
  319. else
  320. echo -e "\nError occured while installing ${pkgdep}. Aborting.\n"
  321. exit 1
  322. fi
  323. fi
  324. done
  325. }
  326. pkgdependencies ${deps[*]}
  327. }
  328. ########################################################
  329. # Wine staging override list
  330. # Wine Staging replaces and conflicts with these packages
  331. # Applies to debian/control file
  332. wine_over_pkgs=(
  333. 'wine'
  334. 'wine-development'
  335. 'wine64-development'
  336. 'wine1.6'
  337. 'wine1.6-i386'
  338. 'wine1.6-amd64'
  339. 'libwine:amd64'
  340. 'libwine:i386'
  341. 'wine-stable'
  342. 'wine32'
  343. 'wine64'
  344. )
  345. ############################
  346. # Suggest section in debian/control file
  347. wine_suggest_pkgs=(
  348. 'winbind'
  349. 'winetricks'
  350. 'fonts-wine'
  351. 'playonlinux'
  352. 'wine-binfmt'
  353. 'dosbox'
  354. )
  355. ########################################################
  356. # Feed the following data to Wine debian/control file
  357. function feedControlfile() {
  358. local MAINTAINER="$USER"
  359. sed -ie "s/^Build-Depends:.*$/Build-Depends: debhelper (>=11), $(echo ${wine_deps_build[*]} | sed 's/\s/, /g')/g" debian/control
  360. sed -ie "s/^Depends:.*$/Depends: $(echo ${wine_deps_runtime[*]} | sed 's/\s/, /g')/g" debian/control
  361. sed -ie "s/^Suggests:.*$/Suggests: $(echo ${wine_suggest_pkgs[*]} | sed 's/\s/, /g')/g" debian/control
  362. sed -ie "s/^Maintainer:.*$/Maintainer: ${MAINTAINER}/g" debian/control
  363. sed -ie "s/^Source:.*$/Source: ${PKGNAME}/g" debian/control
  364. sed -ie "s/^Package:.*$/Package: ${PKGNAME}/g" debian/control
  365. for ctrl_section in Conflicts Breaks Replaces Provides; do
  366. sed -ie "s/^${ctrl_section}:.*$/${ctrl_section}: $(echo ${wine_over_pkgs[*]} | sed 's/\s/, /g')/g" debian/control
  367. done
  368. }
  369. ########################################################
  370. # Refresh Wine GIT
  371. function refreshWineGIT() {
  372. # Restore the wine tree to its git origin state, without wine-staging patches
  373. # (necessary for reapllying wine-staging patches in succedent builds,
  374. # otherwise the patches will fail to be reapplied)
  375. cd "${WINEDIR}"
  376. git reset --hard HEAD # Restore tracked files
  377. git clean -d -x -f # Delete untracked files
  378. if [[ ! -v NO_STAGING ]]; then
  379. # Change back to the wine upstream commit that this version of wine-staging is based on
  380. git checkout $(bash "${WINEDIR_STAGING}"/patches/patchinstall.sh --upstream-commit)
  381. fi
  382. }
  383. ########################################################
  384. # Get Wine version tag
  385. function getWineVersion() {
  386. cd "${WINEDIR}"
  387. wine_version=$(git describe | sed 's/^[a-z]*-//; s/-[0-9]*-[a-z0-9]*$//')
  388. }
  389. ########################################################
  390. # Apply patches
  391. function patchWineSource() {
  392. if [[ ! -v NO_STAGING ]]; then
  393. cd "${WINEDIR_STAGING}/patches"
  394. bash ./patchinstall.sh DESTDIR="${WINEDIR}" ${staging_patchsets[*]}
  395. fi
  396. cp -r ${WINEROOT}/../../../wine_custom_patches/* "${WINEDIR_PATCHES}/"
  397. if [[ $(find "${WINEDIR_PATCHES}" -mindepth 1 -maxdepth 1 -regex ".*\.\(patch\|diff\)$") ]]; then
  398. cd "${WINEDIR}"
  399. for i in "${WINEDIR_PATCHES}"/*.patch; do
  400. patch -Np1 < $i
  401. done
  402. fi
  403. }
  404. ########################################################
  405. # 64-bit build
  406. function wine64Build() {
  407. cd "${WINEDIR_BUILD_64}"
  408. "${WINEDIR}"/configure \
  409. --with-x \
  410. --with-gstreamer \
  411. --enable-win64 \
  412. --with-xattr \
  413. --disable-mscoree \
  414. --with-vulkan \
  415. --prefix=/usr \
  416. --libdir=/usr/lib/x86_64-linux-gnu/
  417. make -j$(nproc --ignore 1)
  418. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_64}/usr" \
  419. libdir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/" \
  420. dlldir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/wine" install
  421. }
  422. # 32-bit build
  423. function wine32Build() {
  424. # Gstreamer amd64 & i386 dev packages conflict on Ubuntu
  425. cd "${WINEDIR_BUILD_32}"
  426. "${WINEDIR}"/configure \
  427. --with-x \
  428. --with-gstreamer \
  429. --with-xattr \
  430. --disable-mscoree \
  431. --with-vulkan \
  432. --without-gstreamer \
  433. --libdir=/usr/lib/i386-linux-gnu/ \
  434. --with-wine64="${WINEDIR_BUILD_64}" \
  435. --prefix=/usr
  436. make -j$(nproc --ignore 1)
  437. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_32}/usr" \
  438. libdir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/" \
  439. dlldir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/wine" install
  440. }
  441. ########################################################
  442. function mergeWineBuilds() {
  443. cp -r "${WINEDIR_INSTALL_64}"/* "${WINEDIR_PACKAGE}"/
  444. cp -r "${WINEDIR_INSTALL_32}"/usr/bin/{wine,wine-preloader} "${WINEDIR_PACKAGE}"/usr/bin/
  445. cp -r "${WINEDIR_INSTALL_32}"/usr/lib/* "${WINEDIR_PACKAGE}"/usr/lib/
  446. }
  447. function buildDebianArchive() {
  448. cd "${WINEROOT}"
  449. mv "${WINEDIR_PACKAGE}" "${WINEROOT}/${PKGNAME}-${wine_version}"
  450. cd "${WINEROOT}/${PKGNAME}-${wine_version}"
  451. dh_make --createorig -s -y
  452. rm debian/*.{ex,EX}
  453. printf "usr/* /usr" > debian/install
  454. cat << 'DEBIANCONTROL' > debian/control
  455. Source:
  456. Section: otherosfs
  457. Priority: optional
  458. Maintainer:
  459. Build-Depends:
  460. Standards-Version: 4.1.2
  461. Homepage: https://www.winehq.org
  462. Package:
  463. Architecture: any
  464. Depends:
  465. Suggests:
  466. Conflicts:
  467. Breaks:
  468. Replaces:
  469. Provides:
  470. Description: A compatibility layer for running Windows programs.
  471. Wine is an open source Microsoft Windows API implementation for
  472. POSIX-compliant operating systems, including Linux.
  473. Git version includes the latest updates available for Wine.
  474. DEBIANCONTROL
  475. feedControlfile
  476. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -b -us -uc
  477. }
  478. function installDebianArchive() {
  479. cd "${WINEROOT}"
  480. # TODO Although the package name ends with 'amd64', this contains both 32 and 64 bit Wine versions
  481. echo -e "\nInstalling Wine.\n"
  482. sudo dpkg -i ${PKGNAME}_${wine_version}-1_amd64.deb
  483. }
  484. function storeDebianArchive() {
  485. cd "${WINEROOT}"
  486. mv ${PKGNAME}_${wine_version}-1_amd64.deb ../../compiled_deb/"${datedir}" && \
  487. echo -e "Compiled ${PKGNAME} is stored at '$(readlink -f ../../compiled_deb/"${datedir}")/'\n"
  488. rm -rf winebuild_${datedir}
  489. }
  490. function clearTree() {
  491. rm -rf "${WINEROOT}"
  492. }
  493. ########################################################
  494. # Get Wine (& Wine-Staging) sources
  495. getWine
  496. # Install Wine dependencies
  497. WineDeps "${wine_deps_build[*]}" "Wine build time"
  498. WineDeps "${wine_deps_runtime[*]}" "Wine runtime"
  499. # Refresh & sync Wine (+ Wine Staging) git sources
  500. refreshWineGIT
  501. # Update Wine source files
  502. patchWineSource
  503. # Get Wine/Wine Staging version
  504. getWineVersion
  505. # Compile 64 & 32 bit Wine/Wine Staging
  506. wine64Build
  507. wine32Build
  508. # Bundle compiled Wine/Wine-Staging files
  509. mergeWineBuilds
  510. # Bundle and install Debian deb archive
  511. buildDebianArchive
  512. if [[ ! -v NO_INSTALL ]]; then
  513. installDebianArchive
  514. fi
  515. storeDebianArchive
  516. # Clear all temporary files
  517. clearTree