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.

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