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.

650 lines
15 KiB

6 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. # Check and install package related dependencies if they are missing
  313. function pkgdependencies() {
  314. # Generate a list of missing dependencies
  315. local a=0
  316. for p in ${@}; do
  317. if [[ $(apt version ${p} | wc -w) -eq 0 ]]; then
  318. local list[$a]=${p}
  319. let a++
  320. fi
  321. done
  322. # Install missing dependencies, be informative
  323. local b=0
  324. for pkgdep in ${list[@]}; do
  325. echo -e "Installing ${_pkgname} dependency ${pkgdep} ($(( $b + 1 )) / $(( ${#list[*]} ))).\n"
  326. sudo apt install -y ${pkgdep} &> /dev/null
  327. if [[ $? -eq 0 ]]; then
  328. let b++
  329. else
  330. echo -e "\nError occured while installing ${pkgdep}. Aborting.\n"
  331. exit 1
  332. fi
  333. done
  334. }
  335. pkgdependencies ${deps[*]}
  336. }
  337. ########################################################
  338. # Wine staging override list
  339. # Wine Staging replaces and conflicts with these packages
  340. # Applies to debian/control file
  341. wine_over_pkgs=(
  342. 'wine'
  343. 'wine-development'
  344. 'wine64-development'
  345. 'wine1.6'
  346. 'wine1.6-i386'
  347. 'wine1.6-amd64'
  348. 'libwine:amd64'
  349. 'libwine:i386'
  350. 'wine-stable'
  351. 'wine32'
  352. 'wine64'
  353. )
  354. ############################
  355. # Suggest section in debian/control file
  356. wine_suggest_pkgs=(
  357. 'winbind'
  358. 'winetricks'
  359. 'fonts-wine'
  360. 'playonlinux'
  361. 'wine-binfmt'
  362. 'dosbox'
  363. )
  364. ########################################################
  365. # Feed the following data to Wine debian/control file
  366. function feedControlfile() {
  367. local MAINTAINER="$USER"
  368. sed -ie "s/^Build-Depends:.*$/Build-Depends: debhelper (>=11), $(echo ${wine_deps_build[*]} | sed 's/\s/, /g')/g" debian/control
  369. sed -ie "s/^Depends:.*$/Depends: $(echo ${wine_deps_runtime[*]} | sed 's/\s/, /g')/g" debian/control
  370. sed -ie "s/^Suggests:.*$/Suggests: $(echo ${wine_suggest_pkgs[*]} | sed 's/\s/, /g')/g" debian/control
  371. sed -ie "s/^Maintainer:.*$/Maintainer: ${MAINTAINER}/g" debian/control
  372. sed -ie "s/^Source:.*$/Source: ${PKGNAME}/g" debian/control
  373. sed -ie "s/^Package:.*$/Package: ${PKGNAME}/g" debian/control
  374. for ctrl_section in Conflicts Breaks Replaces Provides; do
  375. sed -ie "s/^${ctrl_section}:.*$/${ctrl_section}: $(echo ${wine_over_pkgs[*]} | sed 's/\s/, /g')/g" debian/control
  376. done
  377. }
  378. ########################################################
  379. # Refresh Wine GIT
  380. function refreshWineGIT() {
  381. # Restore the wine tree to its git origin state, without wine-staging patches
  382. # (necessary for reapllying wine-staging patches in succedent builds,
  383. # otherwise the patches will fail to be reapplied)
  384. cd "${WINEDIR}"
  385. git reset --hard HEAD # Restore tracked files
  386. git clean -d -x -f # Delete untracked files
  387. if [[ ! -v NO_STAGING ]]; then
  388. # Change back to the wine upstream commit that this version of wine-staging is based on
  389. git checkout $(bash "${WINEDIR_STAGING}"/patches/patchinstall.sh --upstream-commit)
  390. fi
  391. }
  392. ########################################################
  393. # Get Wine version tag
  394. function getWineVersion() {
  395. cd "${WINEDIR}"
  396. wine_version=$(git describe | sed 's/^[a-z]*-//; s/-[0-9]*-[a-z0-9]*$//')
  397. }
  398. ########################################################
  399. # Apply patches
  400. function patchWineSource() {
  401. if [[ ! -v NO_STAGING ]]; then
  402. cd "${WINEDIR_STAGING}/patches"
  403. bash ./patchinstall.sh DESTDIR="${WINEDIR}" ${staging_patchsets[*]}
  404. fi
  405. cp -r ${WINEROOT}/../../../wine_custom_patches/* "${WINEDIR_PATCHES}/"
  406. if [[ $(find "${WINEDIR_PATCHES}" -mindepth 1 -maxdepth 1 -regex ".*\.\(patch\|diff\)$") ]]; then
  407. cd "${WINEDIR}"
  408. for i in "${WINEDIR_PATCHES}"/*.patch; do
  409. patch -Np1 < $i
  410. done
  411. fi
  412. }
  413. ########################################################
  414. # 64-bit build
  415. function wine64Build() {
  416. cd "${WINEDIR_BUILD_64}"
  417. "${WINEDIR}"/configure \
  418. --with-x \
  419. --with-gstreamer \
  420. --enable-win64 \
  421. --with-xattr \
  422. --disable-mscoree \
  423. --with-vulkan \
  424. --prefix=/usr \
  425. --libdir=/usr/lib/x86_64-linux-gnu/
  426. make -j$(nproc --ignore 1)
  427. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_64}/usr" \
  428. libdir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/" \
  429. dlldir="${WINEDIR_INSTALL_64}/usr/lib/x86_64-linux-gnu/wine" install
  430. }
  431. # 32-bit build
  432. function wine32Build() {
  433. # Gstreamer amd64 & i386 dev packages conflict on Ubuntu
  434. cd "${WINEDIR_BUILD_32}"
  435. "${WINEDIR}"/configure \
  436. --with-x \
  437. --with-gstreamer \
  438. --with-xattr \
  439. --disable-mscoree \
  440. --with-vulkan \
  441. --without-gstreamer \
  442. --libdir=/usr/lib/i386-linux-gnu/ \
  443. --with-wine64="${WINEDIR_BUILD_64}" \
  444. --prefix=/usr
  445. make -j$(nproc --ignore 1)
  446. make -j$(nproc --ignore 1) prefix="${WINEDIR_INSTALL_32}/usr" \
  447. libdir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/" \
  448. dlldir="${WINEDIR_INSTALL_32}/usr/lib/i386-linux-gnu/wine" install
  449. }
  450. ########################################################
  451. function mergeWineBuilds() {
  452. cp -r "${WINEDIR_INSTALL_64}"/* "${WINEDIR_PACKAGE}"/
  453. cp -r "${WINEDIR_INSTALL_32}"/usr/bin/{wine,wine-preloader} "${WINEDIR_PACKAGE}"/usr/bin/
  454. cp -r "${WINEDIR_INSTALL_32}"/usr/lib/* "${WINEDIR_PACKAGE}"/usr/lib/
  455. }
  456. function buildDebianArchive() {
  457. cd "${WINEROOT}"
  458. mv "${WINEDIR_PACKAGE}" "${WINEROOT}/${PKGNAME}-${wine_version}"
  459. cd "${WINEROOT}/${PKGNAME}-${wine_version}"
  460. dh_make --createorig -s -y -c lgpl
  461. rm debian/*.{ex,EX}
  462. printf "usr/* /usr" > debian/install
  463. cat << 'DEBIANCONTROL' > debian/control
  464. Source:
  465. Section: otherosfs
  466. Priority: optional
  467. Maintainer:
  468. Build-Depends:
  469. Standards-Version: 4.1.2
  470. Homepage: https://www.winehq.org
  471. Package:
  472. Architecture: any
  473. Depends:
  474. Suggests:
  475. Conflicts:
  476. Breaks:
  477. Replaces:
  478. Provides:
  479. Description: A compatibility layer for running Windows programs.
  480. Wine is an open source Microsoft Windows API implementation for
  481. POSIX-compliant operating systems, including Linux.
  482. Git version includes the latest updates available for Wine.
  483. DEBIANCONTROL
  484. feedControlfile
  485. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -b -us -uc
  486. }
  487. function installDebianArchive() {
  488. cd "${WINEROOT}"
  489. # TODO Although the package name ends with 'amd64', this contains both 32 and 64 bit Wine versions
  490. echo -e "\nInstalling Wine.\n"
  491. sudo dpkg -i ${PKGNAME}_${wine_version}-1_amd64.deb
  492. }
  493. function storeDebianArchive() {
  494. cd "${WINEROOT}"
  495. mv ${PKGNAME}_${wine_version}-1_amd64.deb ../../compiled_deb/"${datedir}" && \
  496. echo -e "Compiled ${PKGNAME} is stored at '$(readlink -f ../../compiled_deb/"${datedir}")/'\n"
  497. rm -rf winebuild_${datedir}
  498. }
  499. function clearTree() {
  500. rm -rf "${WINEROOT}"
  501. }
  502. ########################################################
  503. # Get Wine (& Wine-Staging) sources
  504. getWine
  505. # Install Wine dependencies
  506. WineDeps "${wine_deps_build[*]}" "Wine build time"
  507. WineDeps "${wine_deps_runtime[*]}" "Wine runtime"
  508. # Refresh & sync Wine (+ Wine Staging) git sources
  509. refreshWineGIT
  510. # Update Wine source files
  511. patchWineSource
  512. # Get Wine/Wine Staging version
  513. getWineVersion
  514. # Compile 64 & 32 bit Wine/Wine Staging
  515. wine64Build
  516. wine32Build
  517. # Bundle compiled Wine/Wine-Staging files
  518. mergeWineBuilds
  519. # Bundle and install Debian deb archive
  520. buildDebianArchive
  521. if [[ ! -v NO_INSTALL ]]; then
  522. installDebianArchive
  523. fi
  524. storeDebianArchive
  525. # Clear all temporary files
  526. clearTree