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.

386 lines
11 KiB

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