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.

555 lines
16 KiB

6 years ago
  1. #!/bin/env bash
  2. # Set up Wine Staging + DXVK on Arch Linux & 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. ARCH_BUILDROOT="${PWD}"
  22. # datedir variable supplied by ../updatewine.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_wine=${params[3]}
  40. git_branch_dxvk=${params[4]}
  41. git_branch_wine=${params[7]}
  42. git_source_dxvk=${params[8]}
  43. git_source_wine=${params[11]}
  44. git_source_winestaging=${params[12]}
  45. ########################################################
  46. # Parse input arguments, filter user parameters
  47. # The range is defined in ../updatewine.sh
  48. # All input arguments are:
  49. # <datedir> 4*<githash_override> <args>
  50. # 0 1 2 3 4 5 ...
  51. # Filter all but <args>, i.e. the first 0-4 arguments
  52. i=0
  53. for arg in ${params[@]:8}; do
  54. args[$i]="${arg}"
  55. let i++
  56. done
  57. for check in ${args[@]}; do
  58. case ${check} in
  59. --no-staging)
  60. NO_STAGING=
  61. ;;
  62. --no-install)
  63. NO_INSTALL=
  64. # Do not check for PlayOnLinux wine prefixes
  65. NO_POL=
  66. ;;
  67. --no-wine)
  68. NO_WINE=
  69. ;;
  70. --no-dxvk)
  71. NO_DXVK=
  72. ;;
  73. --no-pol)
  74. NO_POL=
  75. ;;
  76. esac
  77. done
  78. ########################################################
  79. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  80. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  81. ###########################################################
  82. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  83. function Arch_intCleanup() {
  84. rm -rf ${ARCH_BUILDROOT}/{0-wine-staging-git/{wine-patches,*.tar.xz,*.sig},0-dxvk-git/{dxvk-git,*.tar.xz,*.sig}}
  85. exit 0
  86. }
  87. # Allow interruption of the script at any time (Ctrl + C)
  88. trap "Arch_intCleanup" INT
  89. # Error event
  90. #trap "Arch_intCleanup" ERR
  91. ###########################################################
  92. # Check existence of ccache package
  93. function ccacheCheck() {
  94. if [[ $(pacman -Q | awk '{print $1}' | grep -wE "ccache" | wc -l) -eq 0 ]]; then
  95. echo -e "\e[1mNOTE:\e[0m Please consider using 'ccache' for faster compilation times.\nInstall it by typing 'sudo pacman -S ccache'\n"
  96. fi
  97. }
  98. ###########################################################
  99. # Validate all core build files for Wine and/or DXVK exist
  100. function checkFiles() {
  101. local wine_files=('30-win32-aliases.conf' 'PKGBUILD')
  102. local dxvk_files=('PKGBUILD')
  103. function validatefiles() {
  104. local list=${1}
  105. local name=${2}
  106. local path=${3}
  107. for file in ${list[@]}; do
  108. if [[ ! -f "${path}/${file}" ]]; then
  109. echo -e "\e[1mERROR:\e[0m Could not locate file ${} for ${name}. Aborting\n"
  110. exit 1
  111. fi
  112. done
  113. }
  114. if [[ ! -v NO_WINE ]]; then
  115. validatefiles "${wine_files[*]}" Wine "${ARCH_BUILDROOT}/0-wine-staging-git"
  116. fi
  117. if [[ ! -v NO_DXVK ]]; then
  118. validatefiles "${dxvk_files[*]}" DXVK "${ARCH_BUILDROOT}/0-dxvk-git"
  119. fi
  120. }
  121. ###########################################################
  122. # Disable or enable Wine Staging, depending on user's
  123. # choice
  124. function checkStaging() {
  125. # Enable Wine Staging
  126. if [[ ! -v NO_STAGING ]]; then
  127. sed -i 's/enable_staging=[0-9]/enable_staging=1/' "${ARCH_BUILDROOT}/0-wine-staging-git/PKGBUILD"
  128. wine_name="wine-staging-git"
  129. # Enable Wine, disable Staging
  130. else
  131. sed -i 's/enable_staging=[0-9]/enable_staging=0/' "${ARCH_BUILDROOT}/0-wine-staging-git/PKGBUILD"
  132. wine_name="wine"
  133. fi
  134. }
  135. ###########################################################
  136. # Check package dependencies beforehand, just to avoid
  137. # annoying situations which could occur later while the script
  138. # is already running.
  139. # Just for "packages which are not found" array <=> ERRPKGS
  140. # We need to set it outside of checkDepends function
  141. # because it is a global variable for all checked packages
  142. l=0
  143. function checkDepends() {
  144. # The first and the second argument
  145. local packagedir=${1}
  146. local package=${2}
  147. # We get necessary variables to check from this file
  148. local file="./${packagedir}/PKGBUILD"
  149. # All but the (zero), the first and the second argument
  150. # We check the value of these file variables
  151. local file_vars=${@:3}
  152. for var in ${file_vars[*]}; do
  153. # Get the variable and set it as a new variable in the current shell
  154. # This is applicable only to variable arrays! Do not use if the variable is not an array.
  155. local field=$(awk "/^${var}/,/)/" ${file} | sed -r "s/^${var}=|[)|(|']//g")
  156. local i=0
  157. for parse in ${field[*]}; do
  158. if [[ ! $parse =~ ^# ]]; then
  159. local PKGS[$i]=$(printf '%s' $parse | sed 's/[=|>|<].*$//')
  160. let i++
  161. fi
  162. done
  163. # Sort list and delete duplicate index values
  164. local PKGS=($(sort -u <<< "${PKGS[*]}"))
  165. for pkg in ${PKGS[*]}; do
  166. if [[ $(printf $(pacman -Q ${pkg} &>/dev/null)$?) -ne 0 ]]; then
  167. ERRPKGS[$l]=${pkg}
  168. echo -e "\e[91mERROR:\e[0m Dependency '${pkg}' not found, required by '${package}' (${file} => ${var})"
  169. let l++
  170. fi
  171. done
  172. done
  173. echo -e "\e[92m==>\e[0m\e[1m Dependency check for ${package} done.\e[0m\n"
  174. }
  175. function check_alldeps() {
  176. if [[ -v ERRPKGS ]]; then
  177. echo -e "\e[1mERROR:\e[0m The following dependencies are missing:\n\e[91m\
  178. $(for o in ${ERRPKGS[@]}; do printf '%s\n' ${o}; done)\
  179. \e[0m\n"
  180. echo -e "Please install them and try again.\n"
  181. exit 1
  182. fi
  183. }
  184. ###########################################################
  185. # Prepare building environment for the current runtime
  186. function prepare_env() {
  187. # Copy Wine & DXVK patch files
  188. cp -rf ${ARCH_BUILDROOT}/../wine_custom_patches ${ARCH_BUILDROOT}/0-wine-staging-git/wine-patches
  189. cp -rf ${ARCH_BUILDROOT}/../dxvk_custom_patches ${ARCH_BUILDROOT}/0-dxvk-git/dxvk-patches
  190. # Create identifiable directory for this build
  191. mkdir -p ${ARCH_BUILDROOT}/compiled_pkg/"${datedir}"
  192. }
  193. ########################################################
  194. # Parse Wine hash override if Staging is set to be installed
  195. function check_gitOverride_wine() {
  196. # If staging is to be installed and Wine git is frozen to a specific commit
  197. # We need to determine exact commit to use for Wine Staging
  198. # to avoid any mismatches
  199. #
  200. # Basically, when user has defined 'git_commithash_wine' variable (commit), we
  201. # iterate through Wine commits and try to determine previously set
  202. # Wine Staging commit. We use that Wine Staging commit instead of
  203. # the one user has defined in 'git_commithash_wine' variable
  204. #
  205. if [[ ! -v NO_STAGING ]] && [[ "${git_commithash_wine}" != HEAD ]]; then
  206. function form_commit_array() {
  207. cd "${commit_dir}"
  208. if [[ $? -ne 0 ]]; then
  209. echo -e "\e[1mERROR:\e[0m Couldn't access Wine folder ${commit_dir} to check commits. Aborting\n"
  210. exit 1
  211. fi
  212. local array_name=${1}
  213. local commits_raw=$(eval ${2})
  214. local i=0
  215. for commit in ${commits_raw[*]}; do
  216. eval ${array_name}[$i]="${commit}"
  217. let i++
  218. done
  219. if [[ $? -ne 0 ]]; then
  220. echo -e "\e[1mERROR:\e[0m Couldn't parse Wine commits in ${commit_dir}. Aborting\n"
  221. exit 1
  222. fi
  223. cd "${ARCH_BUILDROOT}/0-wine-staging-git/"
  224. }
  225. function staging_change_freeze_commit() {
  226. local wine_commits_raw="git log --pretty=oneline | awk '{print \$1}' | tr '\n' ' '"
  227. # TODO this check may break quite easily
  228. # It depends on the exact comment syntax Wine Staging developers are using (Rebase against ...)
  229. # Length and order of these two "array" variables MUST MATCH!
  230. local staging_refcommits_raw="git log --pretty=oneline | awk '{ if ((length(\$NF)==40 || length(\$NF)==41) && \$(NF-1)==\"against\") print \$1; }'"
  231. local staging_rebasecommits_raw="git log --pretty=oneline | awk '{ if ((length(\$NF)==40 || length(\$NF)==41) && \$(NF-1)==\"against\") print substr(\$NF,1,40); }' | tr '\n' ' '"
  232. # Syntax: <function> <array_name> <raw_commit_list>
  233. commit_dir="${ARCH_BUILDROOT}/0-wine-staging-git/wine-git"
  234. form_commit_array wine_commits "${wine_commits_raw}"
  235. commit_dir="${ARCH_BUILDROOT}/0-wine-staging-git/wine-staging-git"
  236. form_commit_array staging_refcommits "${staging_refcommits_raw}"
  237. form_commit_array staging_rebasecommits "${staging_rebasecommits_raw}"
  238. # User has selected vanilla Wine commit to freeze to
  239. # We must get the previous Staging commit from rebase_commits array, and
  240. # change git_commithash_wine value to that
  241. # Get all vanilla Wine commits
  242. # Filter all newer than defined in 'git_commithash_wine'
  243. #
  244. echo -e "Determining valid Wine Staging git commit. This takes a while.\n"
  245. local i=0
  246. for dropcommit in ${wine_commits[@]}; do
  247. if [[ "${dropcommit}" == "${git_commithash_wine}" ]]; then
  248. break
  249. else
  250. local wine_dropcommits[$i]="${dropcommit}"
  251. let i++
  252. fi
  253. done
  254. wine_commits=("${wine_commits[@]:${#wine_dropcommits[*]}}")
  255. # For the filtered array list, iterate through 'staging_rebasecommits' array list until
  256. # we get a match
  257. for vanilla_commit in ${wine_commits[@]}; do
  258. local k=0
  259. for rebase_commit in ${staging_rebasecommits[@]}; do
  260. if [[ "${vanilla_commit}" == "${rebase_commit}" ]]; then
  261. # This is the commit we use for vanilla Wine
  262. git_commithash_wine="${vanilla_commit}"
  263. # This is equal commit we use for Wine Staging
  264. git_commithash_winestaging="${staging_refcommits[$k]}"
  265. break 2
  266. fi
  267. let k++
  268. done
  269. done
  270. }
  271. git_branch_wine=master
  272. staging_change_freeze_commit
  273. elif [[ ! -v NO_STAGING ]] && [[ "${git_commithash_wine}" == HEAD ]]; then
  274. git_branch_wine=master
  275. git_commithash_winestaging=HEAD
  276. fi
  277. }
  278. ###########################################################
  279. # Remove any existing pkg,src or tar.xz packages left by previous pacman commands
  280. function cleanUp() {
  281. rm -rf ${ARCH_BUILDROOT}/*/{pkg,src,*.tar.xz,*.patch,*.diff,*.sig}
  282. }
  283. ###########################################################
  284. # Build & install package
  285. function build_pkg() {
  286. local pkgname=${1}
  287. local pkgname_friendly=${2}
  288. local pkgdir=${3}
  289. local cleanlist=${4}
  290. # Create package and install it to the system
  291. # We need to download git sources beforehand in order
  292. # to determine git commit hashes
  293. cd "${ARCH_BUILDROOT}"/${pkgdir}
  294. bash -c "updpkgsums && makepkg -o"
  295. local pkgbuild_file="${ARCH_BUILDROOT}/${pkgdir}/PKGBUILD"
  296. # Check git commit hashes
  297. if [[ $? -eq 0 ]] && \
  298. [[ ${5} == gitcheck ]]; then
  299. if [[ ${pkgname} == wine ]]; then
  300. check_gitOverride_wine
  301. git_source_wine=$(echo ${git_source_wine} | sed 's/\//\\\//g; s/\./\\\./g')
  302. sed -i "s/\(^_wine_gitsrc=\).*/\1\"${git_source_wine}\"/" ${pkgbuild_file}
  303. sed -i "s/\(^_wine_commit=\).*/\1${git_commithash_wine}/" ${pkgbuild_file}
  304. sed -i "s/\(^_git_branch_wine=\).*/\1${git_branch_wine}/" ${pkgbuild_file}
  305. if [[ ! -v NO_STAGING ]]; then
  306. git_source_winestaging=$(echo ${git_source_winestaging} | sed 's/\//\\\//g; s/\./\\\./g')
  307. sed -i "s/\(^_staging_gitsrc=\).*/\1\"${git_source_winestaging}\"/" ${pkgbuild_file}
  308. sed -i "s/\(^_staging_commit=\).*/\1${git_commithash_winestaging}/" ${pkgbuild_file}
  309. fi
  310. elif [[ ${pkgname} == dxvk ]]; then
  311. git_source_dxvk=$(echo ${git_source_dxvk} | sed 's/\//\\\//g; s/\./\\\./g')
  312. sed -i "s/\(^_dxvk_gitsrc=\).*/\1\"${git_source_dxvk}\"/" ${pkgbuild_file}
  313. sed -i "s/\(^_git_branch_dxvk=\).*/\1${git_branch_dxvk}/" ${pkgbuild_file}
  314. sed -i "s/\(^_dxvk_commit=\).*/\1${git_commithash_dxvk}/" ${pkgbuild_file}
  315. fi
  316. fi
  317. if [[ $? -eq 0 ]]; then bash -c "updpkgsums && makepkg -Cf"; else exit 1; fi
  318. # After successful compilation...
  319. if [[ $(ls ./${pkgname}-*tar.xz 2>/dev/null | wc -l) -ne 0 ]]; then
  320. if [[ ! -v NO_INSTALL ]]; then
  321. yes | sudo pacman -U ${pkgname}-*.tar.xz
  322. fi
  323. mv ${pkgname}-*.tar.xz ${ARCH_BUILDROOT}/compiled_pkg/${datedir}/ && \
  324. echo -e "\nCompiled ${pkgname_friendly} is stored at '$(readlink -f ${ARCH_BUILDROOT}/compiled_pkg/${datedir}/)/'\n"
  325. for rml in ${cleanlist[*]}; do
  326. rm -rf "${ARCH_BUILDROOT}/${pkgdir}/${rml}"
  327. done
  328. else
  329. echo -e "\e[1mERROR:\e[0m Error occured during ${pkgname} compilation.\n"
  330. for rml in ${cleanlist[*]}; do
  331. rm -rf "${ARCH_BUILDROOT}/${pkgdir}/${rml}"
  332. done
  333. exit 1
  334. fi
  335. cd "${ARCH_BUILDROOT}"
  336. }
  337. ##########################################################
  338. # Update user's PlayOnLinux Wine prefixes if present
  339. function updatePOL() {
  340. # Check whether we will update user's PoL wine prefixes
  341. if [[ ! -v NO_POL ]]; then
  342. # Check existence of PoL default folder in user's homedir
  343. if [[ ! -d "$HOME/.PlayOnLinux" ]]; then
  344. echo -e "\e[1mWARNING:\e[0m Couldn't find PoL directories in $USER's homedir.\n"
  345. return 0
  346. fi
  347. fi
  348. if [[ ! -v NO_WINE ]]; then
  349. # If a new Wine Staging version was installed and 'System' version of Wine has been used in
  350. # PoL wineprefix configurations, update those existing PoL wineprefixes
  351. for wineprefix in $(find $HOME/.PlayOnLinux/wineprefix -mindepth 1 -maxdepth 1 -type d); do
  352. if [[ -d ${wineprefix}/dosdevices ]]; then
  353. # If VERSION string exists, skip updating that prefix.
  354. if [[ $(printf $(grep -ril "VERSION" ${wineprefix}/playonlinux.cfg &> /dev/null)$?) -ne 0 ]]; then
  355. WINEPREFIX=${wineprefix} wineboot -u
  356. fi
  357. fi
  358. done
  359. fi
  360. # TODO remove duplicate functionality
  361. if [[ ! -v NO_DXVK ]]; then
  362. for wineprefix in $(find $HOME/.PlayOnLinux/wineprefix -mindepth 1 -maxdepth 1 -type d); do
  363. if [[ -d ${wineprefix}/dosdevices ]]; then
  364. WINEPREFIX=${wineprefix} setup_dxvk
  365. fi
  366. done
  367. fi
  368. }
  369. ##########################################################
  370. # Clean these temporary folders & files
  371. # TODO Shall we remove git folders or keep them?
  372. dxvk_wine_cleanlist=('*.patch' '*.diff' 'pkg' 'src' '*-patches' '*.tar.xz' '*.sig')
  373. ##########################################################
  374. # Validate all buildtime files
  375. checkFiles
  376. # Check whether we build Wine or Wine Staging
  377. checkStaging
  378. # Check whether we have ccache installed
  379. ccacheCheck
  380. # Clean all previous trash we may have
  381. cleanUp
  382. # Prepare building environment: copy patches and create timestamped folder for compiled packages
  383. prepare_env
  384. #########################
  385. # Check Wine & DXVK dependencies, depending on whether these packages
  386. # are to be built
  387. echo -e "\e[1mINFO:\e[0m Checking dependencies for packages.\n"
  388. if [[ ! -v NO_WINE ]]; then
  389. checkDepends "0-wine-staging-git" "${wine_name}" _depends makedepends
  390. fi
  391. if [[ ! -v NO_DXVK ]]; then
  392. checkDepends "0-dxvk-git" "dxvk-git" depends makedepends
  393. fi
  394. check_alldeps
  395. #########################
  396. # Compile Wine & DXVK, depending on whether these packages
  397. # are to be built
  398. # Although the folder name is '0-wine-staging-git', we can still build vanilla Wine
  399. if [[ ! -v NO_WINE ]]; then
  400. build_pkg wine "${wine_name}" "0-wine-staging-git" "${dxvk_wine_cleanlist[*]}" gitcheck
  401. fi
  402. if [[ ! -v NO_DXVK ]]; then
  403. build_pkg dxvk DXVK "0-dxvk-git" "${dxvk_wine_cleanlist[*]}" gitcheck
  404. fi
  405. #########################
  406. # Update user's PlayonLinux wine prefixes if needed
  407. if [[ ! -v NO_POL ]]; then
  408. echo -e "\e[1mINFO:\e[0m Updating your PlayOnLinux Wine prefixes.\n"
  409. updatePOL
  410. fi