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.

323 lines
8.8 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) 2018 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), 2018"
  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=1af96347e1c6f1f2eb11aeb11009f380fd5761ec
  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. function checkCommands() {
  70. if [[ $(which --help 2>/dev/null) ]] && [[ $(echo --help 2>/dev/null) ]]; then
  71. local a=0
  72. for command in ${@}; do
  73. if [[ ! $(which $command 2>/dev/null) ]]; then
  74. local COMMANDS_NOTFOUND[$a]=${command}
  75. let a++
  76. fi
  77. done
  78. if [[ -n $COMMANDS_NOTFOUND ]]; then
  79. echo -e "\nError! The following commands could not be found: ${COMMANDS_NOTFOUND[*]}\nAborting\n"
  80. exit 1
  81. fi
  82. else
  83. exit 1
  84. fi
  85. }
  86. checkCommands "${COMMANDS[*]}"
  87. ###########################################################
  88. # http://wiki.bash-hackers.org/snipplets/print_horizontal_line#a_line_across_the_entire_width_of_the_terminal
  89. function INFO_SEP() { printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' - ; }
  90. ###########################################################
  91. if [[ $(uname -a | grep -c x86_64) -eq 0 ]]; then
  92. echo "This script supports 64-bit architectures only."
  93. exit 1
  94. fi
  95. if [[ $(groups | grep -c sudo) -eq 0 ]]; then
  96. echo "You must belong to sudo group."
  97. exit 1
  98. fi
  99. if [[ $UID -eq 0 ]]; then
  100. echo "Run as a regular user."
  101. exit 1
  102. fi
  103. ###########################################################
  104. # User-passed arguments for the script
  105. # We check the values of this array
  106. # and pass them to the subscripts if supported
  107. i=0
  108. for arg in ${@}; do
  109. case ${arg} in
  110. --no-staging)
  111. # Do not build Wine staging version, just Wine
  112. ;;
  113. --no-install)
  114. # Just build, do not install DXVK or Wine-Staging
  115. # Note that some version of Wine is required for DXVK compilation, though!
  116. ;;
  117. --no-wine)
  118. # Skip Wine build & installation process all together
  119. NO_WINE=
  120. ;;
  121. --no-dxvk)
  122. # Skip DXVK build & installation process all together
  123. NO_DXVK=
  124. ;;
  125. --no-pol)
  126. # Skip PlayOnLinux Wine prefixes update process
  127. ;;
  128. --no-winetricks)
  129. # Do not build Winetricks, do not install DXVK
  130. # Debian only
  131. ;;
  132. *)
  133. echo -e "\n\
  134. \
  135. ${SCRIPT_TITLE} by ${SCRIPT_AUTHOR}\n\n\
  136. Usage:\n\nbash updatewine.sh\n\nArguments:\n\n\
  137. --no-install\tDo not install Wine, Winetricks or DXVK, just compile them. Wine, meson & glslang must be installed for DXVK compilation.\n\
  138. --no-dxvk\tDo not compile or install DXVK\n\
  139. --no-pol\tDo not update PlayOnLinux Wine prefixes\n\n\
  140. --no-staging\tCompile Wine instead of Wine Staging\n\
  141. --no-wine\tDo not compile or install Wine/Wine Staging\n\
  142. --no-winetricks\t[Debian only] Do not compile or install Winetricks.\n\
  143. \t\tNo DXVK installation unless Winetricks already installed.\n\n\
  144. Compiled packages are installed by default, unless '--no-install' argument is given.\n\
  145. If '--no-install' argument is given, the script doesn't check or update your PlayOnLinux Wine prefixes.\n"
  146. exit 0
  147. ;;
  148. esac
  149. args[$i]="${arg}"
  150. let i++
  151. done
  152. ###########################################################
  153. # Date timestamp and random number identifier for compiled
  154. # DXVK & Wine Staging builds
  155. # This variable is known as 'datedir' in other script files
  156. datesuffix=$(echo $(date '+%Y-%m-%d-%H%M%S'))
  157. ###########################################################
  158. # Add git commit hash overrides to argument list
  159. # Pass them to subscripts, as well.
  160. githash_overrides=(
  161. "${git_commithash_dxvk}"
  162. "${git_commithash_glslang}"
  163. "${git_commithash_meson}"
  164. "${git_commithash_wine}"
  165. )
  166. # Add git branches to argument list
  167. # Pass them to subscripts, as well.
  168. gitbranch_overrides=(
  169. "${git_branch_dxvk}"
  170. "${git_branch_glslang}"
  171. "${git_branch_meson}"
  172. "${git_branch_wine}"
  173. )
  174. #############################
  175. # Commit syntax validity check
  176. for githash in ${githash_overrides[@]}; do
  177. if [[ ! $(printf ${githash} | wc -c) -eq 40 ]] && \
  178. [[ ! ${githash} == HEAD ]]; then
  179. echo -e "\nError: badly formatted commit hash '${githash}' in the script file 'updatewine.sh'. Aborting\n"
  180. exit 1
  181. fi
  182. done
  183. #############################
  184. params=(${datesuffix} ${githash_overrides[@]} ${gitbranch_overrides[@]} ${args[@]})
  185. ###########################################################
  186. function sudoQuestion() {
  187. sudo -k
  188. 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"
  189. sudo -v
  190. if [[ $? -ne 0 ]]; then
  191. echo -e "Invalid sudo password.\n"
  192. exit 1
  193. fi
  194. # PID of the current main process
  195. PIDOF=$$
  196. # Run sudo timestamp update on the background and continue the script execution
  197. # Refresh sudo timestamp while the main process is running
  198. function sudo_refresh() {
  199. while [[ $(printf $(ps ax -o pid --no-headers | grep -o ${PIDOF} &> /dev/null)$?) -eq 0 ]]; do
  200. sudo -nv && sleep 2
  201. done
  202. }
  203. sudo_refresh &
  204. }
  205. ###########################################################
  206. function checkInternet() {
  207. if [[ $(echo $(wget --delete-after -q -T 5 github.com -o -)$?) -ne 0 ]]; then
  208. echo -e "\nInternet connection failed (GitHub). Please check your connection and try again.\n"
  209. exit 1
  210. fi
  211. rm -f ./index.html.tmp
  212. }
  213. checkInternet
  214. ###########################################################
  215. # Only Debian & Arch based Linux distributions are currently supported
  216. function determineDistroFamily() {
  217. # These are default package managers used by the supported Linux distributions
  218. pkgmgrs=('dpkg' 'pacman')
  219. for pkgmgr in ${pkgmgrs[@]}; do
  220. if [[ $(printf $(which ${pkgmgr} &> /dev/null)$?) -eq 0 ]]; then
  221. pkgmgr_valid=${pkgmgr}
  222. fi
  223. done
  224. case ${pkgmgr_valid} in
  225. dpkg)
  226. distro="debian"
  227. ;;
  228. pacman)
  229. distro="arch"
  230. ;;
  231. default|*)
  232. echo -e "Your Linux distribution is not supported. Aborting.\n"
  233. exit 1
  234. ;;
  235. esac
  236. }
  237. if [[ ! -v NO_WINE ]] || [[ ! -v NO_DXVK ]]; then
  238. echo -e "\n${SCRIPT_TITLE}\n\nBuild identifier:\t${datesuffix}\n"
  239. else
  240. echo ""
  241. fi
  242. if [[ -n ${args[*]} ]]; then
  243. echo -e "Using arguments:\t${args[*]}\n"
  244. fi
  245. determineDistroFamily
  246. INFO_SEP
  247. 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\
  248. This script comes with GPU driver installation scripts for Debian-based Linux distributions.\n"
  249. INFO_SEP
  250. if [[ ! -v NO_WINE ]] || [[ ! -v NO_DXVK ]]; then
  251. sudoQuestion
  252. echo ""
  253. fi
  254. bash -c "cd ${distro} && bash ./updatewine_${distro}.sh ${params[*]}"