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.

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