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.

394 lines
11 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/bin/env bash
  2. # DXVK/Wine-Staging scripts dispatcher for various Linux distributions
  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. # Check if we're using bash or sh to run the script. If bash, OK.
  19. # If another one, ask user to run the script with bash.
  20. BASH_CHECK=$(ps | grep `echo $$` | awk '{ print $4 }')
  21. if [ $BASH_CHECK != "bash" ]; then
  22. echo "
  23. Please run this script using bash (/usr/bin/bash).
  24. "
  25. exit 1
  26. fi
  27. ###########################################################
  28. # Just a title & author for this script, used in initialization and help page
  29. SCRIPT_TITLE="\e[1mWine/Wine Staging & DXVK package builder & auto-installer\e[0m"
  30. SCRIPT_AUTHOR="Pekka Helenius (~Fincer), 2019"
  31. ########################################################
  32. # Should we freeze Git versions of these packages?
  33. # This is handy in some cases, if breakages occur
  34. # (although we actually compile an older version of a package)
  35. #
  36. # Define a commit hash to freeze to
  37. # Use keyword 'HEAD' if you want to use the latest git
  38. # version available
  39. # Do NOT leave these variable empty!
  40. git_commithash_dxvk=HEAD
  41. git_branch_dxvk=master
  42. git_commithash_wine=HEAD
  43. git_branch_wine=master
  44. # These apply only on Debian/Ubuntu/Mint
  45. git_commithash_meson=5d6dcf8850fcc5d552f55943b6aa3582754dedf8
  46. git_branch_meson=master
  47. git_commithash_glslang=HEAD
  48. git_branch_glslang=master
  49. ###########################################################
  50. # Allow interruption of the script at any time (Ctrl + C)
  51. trap "exit" INT
  52. ###########################################################
  53. COMMANDS=(
  54. date
  55. df
  56. find
  57. git
  58. grep
  59. groups
  60. nproc
  61. patch
  62. readlink
  63. sudo
  64. tar
  65. uname
  66. wc
  67. wget
  68. )
  69. SUDO_GROUPS=(
  70. sudo
  71. wheel
  72. )
  73. function checkCommands() {
  74. if [[ $(which --help 2>/dev/null) ]] && [[ $(echo --help 2>/dev/null) ]]; then
  75. local a=0
  76. for command in ${@}; do
  77. if [[ ! $(which $command 2>/dev/null) ]]; then
  78. local COMMANDS_NOTFOUND[$a]=${command}
  79. let a++
  80. fi
  81. done
  82. if [[ -n $COMMANDS_NOTFOUND ]]; then
  83. echo -e "\nError! The following commands could not be found: ${COMMANDS_NOTFOUND[*]}\nAborting\n"
  84. exit 1
  85. fi
  86. else
  87. exit 1
  88. fi
  89. }
  90. checkCommands "${COMMANDS[*]}"
  91. ###########################################################
  92. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  93. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  94. ###########################################################
  95. if [[ $(uname -a | grep -c x86_64) -eq 0 ]]; then
  96. echo "This script supports 64-bit architectures only."
  97. exit 1
  98. fi
  99. if [[ $(groups | grep -cE $(echo ${SUDO_GROUPS[*]} | sed 's/ /|/g')) -eq 0 ]]; then
  100. echo "You must belong to a sudo group (checked groups: ${SUDO_GROUPS[*]})."
  101. exit 1
  102. fi
  103. unset sudogrp
  104. if [[ $UID -eq 0 ]]; then
  105. echo "Run as a regular user."
  106. exit 1
  107. fi
  108. ###########################################################
  109. # User-passed arguments for the script
  110. # We check the values of this array
  111. # and pass them to the subscripts if supported
  112. i=0
  113. for arg in ${@}; do
  114. case ${arg} in
  115. --no-staging)
  116. # Do not build Wine staging version, just Wine
  117. ;;
  118. --no-install)
  119. # Just build, do not install DXVK or Wine-Staging
  120. # Note that some version of Wine is required for DXVK compilation, though!
  121. ;;
  122. --no-wine)
  123. # Skip Wine build & installation process all together
  124. NO_WINE=
  125. ;;
  126. --no-dxvk)
  127. # Skip DXVK build & installation process all together
  128. NO_DXVK=
  129. ;;
  130. --no-pol)
  131. # Skip PlayOnLinux Wine prefixes update process
  132. ;;
  133. *)
  134. echo -e "\n\
  135. \
  136. ${SCRIPT_TITLE} by ${SCRIPT_AUTHOR}\n\n\
  137. Usage:\n\nbash updatewine.sh\n\nArguments:\n\n\
  138. --no-install\tDo not install Wine or DXVK. Just compile them. Wine, meson & glslang must be installed for DXVK compilation.\n\
  139. --no-dxvk\tDo not compile or install DXVK\n\
  140. --no-pol\tDo not update PlayOnLinux Wine prefixes\n\n\
  141. --no-staging\tCompile Wine instead of Wine Staging\n\
  142. --no-wine\tDo not compile or install Wine/Wine Staging\n\n\
  143. Compiled packages are installed by default, unless '--no-install' argument is given.\n\
  144. If '--no-install' argument is given, the script doesn't check or update your PlayOnLinux Wine prefixes.\n"
  145. exit 0
  146. ;;
  147. esac
  148. args[$i]="${arg}"
  149. let i++
  150. done
  151. ###########################################################
  152. # Date timestamp and random number identifier for compiled
  153. # DXVK & Wine Staging builds
  154. # This variable is known as 'datedir' in other script files
  155. datesuffix=$(echo $(date '+%Y-%m-%d-%H%M%S'))
  156. ###########################################################
  157. # Add git commit hash overrides to argument list
  158. # Pass them to subscripts, as well.
  159. githash_overrides=(
  160. "${git_commithash_dxvk}"
  161. "${git_commithash_glslang}"
  162. "${git_commithash_meson}"
  163. "${git_commithash_wine}"
  164. )
  165. # Add git branches to argument list
  166. # Pass them to subscripts, as well.
  167. gitbranch_overrides=(
  168. "${git_branch_dxvk}"
  169. "${git_branch_glslang}"
  170. "${git_branch_meson}"
  171. "${git_branch_wine}"
  172. )
  173. #############################
  174. # Commit syntax validity check
  175. for githash in ${githash_overrides[@]}; do
  176. if [[ ! $(printf ${githash} | wc -c) -eq 40 ]] && \
  177. [[ ! ${githash} == HEAD ]]; then
  178. echo -e "\nError: badly formatted commit hash '${githash}' in the script file 'updatewine.sh'. Aborting\n"
  179. exit 1
  180. fi
  181. done
  182. ###########################################################
  183. params=(${datesuffix} ${githash_overrides[@]} ${gitbranch_overrides[@]} ${args[@]})
  184. ###########################################################
  185. # General function for question responses
  186. function questionresponse() {
  187. local response=${1}
  188. read -r -p "" response
  189. if [[ $(echo $response | sed 's/ //g') =~ ^([yY][eE][sS]|[yY])$ ]]; then
  190. echo ""
  191. return 0
  192. else
  193. return 1
  194. fi
  195. }
  196. ###########################################################
  197. function reqsCheck() {
  198. local AVAIL_SPACE=$(df -h -B MB --output=avail . | sed '1d; s/[A-Z]*//g')
  199. local REC_SPACE=8000
  200. local MSG_SPACE="\e[1mWARNING:\e[0m Not sufficient storage space\n\nYou will possibly run out of space while compiling software.\n\
  201. The script strongly recommends ~\e[1m$((${REC_SPACE} / 1000)) GB\e[0m at least to compile software successfully but you have only\n\
  202. \e[1m${AVAIL_SPACE} MB\e[0m left on the filesystem the script is currently placed at.\n\n\
  203. Be aware that the script process may fail because of this, especially while compiling Wine Staging.\n\n\
  204. Do you really want to continue? [Y/n]"
  205. local AVAIL_RAM=$(( $(grep -oP "(?<=^MemFree:).*[0-9]" /proc/meminfo | sed 's/ //g') / 1024 ))
  206. local REC_RAM=4096
  207. local MSG_RAM="\e[1mWARNING:\e[0m Not sufficient RAM available\n\nCompilation processes will likely fail.\n\
  208. The script strongly recommends ~\e[1m${REC_RAM} MB\e[0m at least to compile software successfully but you have only\n\
  209. \e[1m${AVAIL_RAM} MB\e[0m left on the computer the script is currently placed at.\n\n\
  210. Be aware that the script process may fail because of this, especially while compiling DXVK.\n\n\
  211. Do you really want to continue? [Y/n]"
  212. function reqs_property() {
  213. local avail_prop="${1}"
  214. local req_prop="${2}"
  215. local req_message="${3}"
  216. local req_installtargets="${4}"
  217. local i=0
  218. for req_installtarget in ${req_installtargets}; do
  219. req_targetconditions[$i]=$(echo "[[ ! -v ${req_installtarget} ]] ||")
  220. let i++
  221. done
  222. local req_targetconditions=($(echo ${req_targetconditions[@]} | sed 's/\(.*\) ||/\1 /'))
  223. local fullcondition="[[ "${avail_prop}" -lt "${req_prop}" ]] && ($(echo ${req_targetconditions[@]}))"
  224. if $(eval ${fullcondition}); then
  225. INFO_SEP
  226. echo -e "${req_message}"
  227. questionresponse
  228. if [[ $? -ne 0 ]]; then
  229. echo -e "Cancelling.\n"
  230. exit 1
  231. fi
  232. unset avail_prop req_prop req_installtarget req_targetconditions fullcondition
  233. fi
  234. }
  235. reqs_property "${AVAIL_SPACE}" "${REC_SPACE}" "${MSG_SPACE}" "NO_WINE"
  236. reqs_property "${AVAIL_RAM}" "${REC_RAM}" "${MSG_RAM}" "NO_DXVK"
  237. }
  238. ###########################################################
  239. function sudoQuestion() {
  240. sudo -k
  241. echo -e "\e[1mINFO:\e[0m sudo password required\n\nThis script requires elevated permissions for package updates & installations. Please provide your sudo password for these script commands. Sudo permissions are not used for any other purposes.\n"
  242. sudo -v
  243. if [[ $? -ne 0 ]]; then
  244. echo -e "Invalid sudo password.\n"
  245. exit 1
  246. fi
  247. # PID of the current main process
  248. PIDOF=$$
  249. # Run sudo timestamp update on the background and continue the script execution
  250. # Refresh sudo timestamp while the main process is running
  251. function sudo_refresh() {
  252. while [[ $(printf $(ps ax -o pid --no-headers | grep -o ${PIDOF} &> /dev/null)$?) -eq 0 ]]; do
  253. sudo -nv && sleep 2
  254. done
  255. }
  256. sudo_refresh &
  257. }
  258. ###########################################################
  259. function checkInternet() {
  260. if [[ $(echo $(wget --delete-after -q -T 5 github.com -o -)$?) -ne 0 ]]; then
  261. echo -e "\nDNS name resolution failed (GitHub). Please check your network connection settings and try again.\n"
  262. exit 1
  263. fi
  264. rm -f ./index.html.tmp
  265. }
  266. checkInternet
  267. ###########################################################
  268. # Only Debian & Arch based Linux distributions are currently supported
  269. function determineDistroFamily() {
  270. # These are default package managers used by the supported Linux distributions
  271. pkgmgrs=('dpkg' 'pacman')
  272. for pkgmgr in ${pkgmgrs[@]}; do
  273. if [[ $(printf $(which ${pkgmgr} &> /dev/null)$?) -eq 0 ]]; then
  274. pkgmgr_valid=${pkgmgr}
  275. fi
  276. done
  277. case ${pkgmgr_valid} in
  278. dpkg)
  279. distro="debian"
  280. ;;
  281. pacman)
  282. distro="arch"
  283. ;;
  284. default|*)
  285. echo -e "Your Linux distribution is not supported. Aborting.\n"
  286. exit 1
  287. ;;
  288. esac
  289. }
  290. if [[ ! -v NO_WINE ]] || [[ ! -v NO_DXVK ]]; then
  291. echo -e "\n${SCRIPT_TITLE}\n\nBuild identifier:\t${datesuffix}\n"
  292. else
  293. echo ""
  294. fi
  295. if [[ -n ${args[*]} ]]; then
  296. echo -e "Using arguments:\t${args[*]}\n"
  297. fi
  298. determineDistroFamily
  299. INFO_SEP
  300. echo -e "\e[1mNOTE: \e[0mDXVK requires very latest Nvidia/AMD drivers to work.\nMake sure these drivers are available on your Linux distribution.\n\
  301. This script comes with GPU driver installation scripts for Debian-based Linux distributions.\n"
  302. INFO_SEP
  303. if [[ ! -v NO_WINE ]] || [[ ! -v NO_DXVK ]]; then
  304. reqsCheck
  305. sudoQuestion
  306. echo ""
  307. fi
  308. bash -c "cd ${distro} && bash ./updatewine_${distro}.sh ${params[*]}"