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.

313 lines
7.9 KiB

  1. #!/bin/env bash
  2. # Winetricks package builder for Debian
  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
  29. SCRIPT_TITLE="\e[1mWinetricks package builder & installer\e[0m"
  30. SCRIPT_AUTHOR="Pekka Helenius (~Fincer), 2019"
  31. ########################################################
  32. pkgname="winetricks"
  33. pkgsrc="https://github.com/Winetricks/winetricks"
  34. pkgurl="https://winetricks.org"
  35. # TODO Do not require wine as a hard dependency since
  36. # it may break things. Wine is practically required, though.
  37. #
  38. pkgdeps_runtime=('cabextract' 'unzip' 'x11-utils') # 'wine'
  39. ########################################################
  40. WORKDIR="${PWD}"
  41. ###########################
  42. # DO NOT CHANGE THIS if you intend to use this shell
  43. # script as a part updatewine.sh shell script!
  44. BUILD_MAINDIR="${WORKDIR}/debian/winetricks-git"
  45. ########################################################
  46. echo -e "\n${SCRIPT_TITLE}\n"
  47. ########################################################
  48. # If the script is interrupted (Ctrl+C/SIGINT), do the following
  49. function Winetricks_intCleanup() {
  50. rm -rf ${BUILD_MAINDIR}
  51. exit 0
  52. }
  53. # Allow interruption of the script at any time (Ctrl + C)
  54. trap "Winetricks_intCleanup" INT
  55. ###########################################################
  56. COMMANDS=(
  57. apt
  58. dpkg
  59. git
  60. grep
  61. sudo
  62. wc
  63. )
  64. function checkCommands() {
  65. if [[ $(which --help 2>/dev/null) ]] && [[ $(echo --help 2>/dev/null) ]]; then
  66. local a=0
  67. for command in ${@}; do
  68. if [[ ! $(which $command 2>/dev/null) ]]; then
  69. local COMMANDS_NOTFOUND[$a]=${command}
  70. let a++
  71. fi
  72. done
  73. if [[ -n $COMMANDS_NOTFOUND ]]; then
  74. echo -e "\nError! The following commands could not be found: ${COMMANDS_NOTFOUND[*]}\nAborting\n"
  75. exit 1
  76. fi
  77. else
  78. exit 1
  79. fi
  80. }
  81. checkCommands "${COMMANDS[*]}"
  82. ########################################################
  83. function runtimeCheck() {
  84. # Runtime package names to check on Debian
  85. local known_pkgs=${1}
  86. ##########################
  87. # This array applies only if wine is defined
  88. # as a runtime dependency for Winetricks
  89. #
  90. # 'dpkg -s' check is quite primitive,
  91. # do this additional check for Wine
  92. local known_wines=(
  93. 'wine'
  94. 'wine-stable'
  95. 'wine32'
  96. 'wine64'
  97. 'libwine:amd64'
  98. 'libwine:i386'
  99. 'wine-git'
  100. 'wine-staging-git'
  101. )
  102. ##########################
  103. # Check if these packages are present on the system
  104. i=0
  105. for pkg in ${known_pkgs[@]}; do
  106. if [[ $(echo $(dpkg -s ${pkg} &>/dev/null)$?) -ne 0 ]]; then
  107. local pkglist[$i]=${pkg}
  108. let i++
  109. fi
  110. done
  111. # This loop applies only if wine is defined
  112. # as a runtime dependency for Winetricks
  113. #
  114. # If known wine is found, drop 'wine' from pkglist array
  115. for winepkg in ${known_wines[@]}; do
  116. if [[ $(echo $(dpkg -s ${winepkg} &>/dev/null)$?) -eq 0 ]]; then
  117. pkglist=( "${pkglist[@]/wine}" )
  118. fi
  119. done
  120. if [[ -n ${pkglist[*]} ]]; then
  121. echo -e "\e[1mWARNING:\e[0m Not installing Winetricks because the following runtime dependencies are missing:\n\n$(for l in ${pkglist[*]}; do echo ${l}; done)\n\n\
  122. These should be installed in order to use Winetricks. Just compiling Winetricks for later use.\n"
  123. # Force --no-install switch
  124. NO_INSTALL=
  125. fi
  126. }
  127. ########################################################
  128. function winetricks_prepare() {
  129. # Define package folder path and create it
  130. # Clone package source from 'pkgurl'
  131. pkgdir="${BUILD_MAINDIR}/${pkgname}"
  132. mkdir -p ${pkgdir} && \
  133. git clone ${pkgsrc} "${pkgdir}"
  134. if [[ $? -ne 0 ]]; then
  135. echo -e "Error while downloading source of ${pkgname} package. Aborting\n"
  136. exit 1
  137. fi
  138. # Parse package version field
  139. function pkgver() {
  140. cd "${pkgdir}"
  141. git describe --long | sed 's/\-[^0-9].*//; s/\-/\./g'
  142. if [[ $? -ne 0 ]]; then
  143. echo -e "Error while parsing ${pkgname} version field. Aborting\n"
  144. exit 1
  145. fi
  146. }
  147. # Define package version field variable 'pkgver'
  148. pkgver=$(pkgver)
  149. # Rename the source folder to meet the standards of Debian builder
  150. cd "${BUILD_MAINDIR}" && \
  151. mv "${pkgname}" "${pkgname}-${pkgver}"
  152. # Source folder which is used now, just added version string suffix
  153. pkgdir="${BUILD_MAINDIR}/${pkgname}-${pkgver}"
  154. }
  155. ########################################################
  156. function coredeps_check() {
  157. # Universal core build time dependencies for package compilation
  158. _coredeps=('dh-make' 'make' 'gcc' 'build-essential' 'fakeroot')
  159. local i=0
  160. for coredep in ${_coredeps[@]}; do
  161. if [[ $(echo $(dpkg -s ${coredep} &>/dev/null)$?) -ne 0 ]]; then
  162. echo -e "Installing core dependency ${coredep}.\n"
  163. buildpkglist[$i]=${coredep}
  164. sudo apt install -y ${coredep}
  165. if [[ $? -ne 0 ]]; then
  166. echo -e "Could not install ${coredep}. Aborting.\n"
  167. exit 1
  168. fi
  169. let i++
  170. fi
  171. done
  172. }
  173. ########################################################
  174. function feed_debiancontrol() {
  175. cat << CONTROLFILE > "${pkgdir}/debian/control"
  176. Source: ${pkgname}
  177. Section: unknown
  178. Priority: optional
  179. Maintainer: ${USER} <${USER}@unknown>
  180. Build-Depends: debhelper (>= 9)
  181. Standards-Version: 3.9.8
  182. Homepage: ${pkgurl}
  183. Package: ${pkgname}
  184. Architecture: all
  185. Depends: $(echo "${pkgdeps_runtime[*]}" | sed 's/\s/, /g')
  186. Suggests: wine
  187. Description: Script to install various redistributable runtime libraries in Wine.
  188. CONTROLFILE
  189. }
  190. ########################################################
  191. function winetricks_debianbuild() {
  192. cd "${pkgdir}"
  193. # Delete existing debian folder
  194. rm -rf debian
  195. # Create debian subdirectory
  196. dh_make --createorig -s -y -c lgpl
  197. # Update debian/control file
  198. feed_debiancontrol
  199. # Skip tests while executing deb builder
  200. printf 'override_dh_auto_test:' | tee -a debian/rules
  201. # Remove irrelevant sample files
  202. rm -rf debian/*.{ex,EX}
  203. # Start deb builder. Do not build either debug symbols or doc files
  204. DEB_BUILD_OPTIONS="strip nodocs noddebs" dpkg-buildpackage -rfakeroot -b -us -uc
  205. if [[ $? -ne 0 ]]; then
  206. echo -e "Error while compiling ${pkgname}. Check messages above. Aborting\n"
  207. exit 1
  208. fi
  209. # Once compiled, possibly install and store the compiled deb archive
  210. if [[ $? -eq 0 ]]; then
  211. if [[ ! -v NO_INSTALL ]]; then
  212. sudo dpkg -i ../${pkgname}*.deb
  213. fi
  214. mv ../${pkgname}*.deb "${WORKDIR}"/ && \
  215. cd "${WORKDIR}"
  216. rm -rf "${BUILD_MAINDIR}"
  217. else
  218. exit 1
  219. fi
  220. }
  221. ########################################################
  222. runtimeCheck "${pkgdeps_runtime[*]}"
  223. winetricks_prepare
  224. # If we run this script via debian/updatewine_debian.sh, this check is already done there
  225. coredeps_check
  226. winetricks_debianbuild
  227. ########################################################
  228. # Build time dependencies which were installed but no longer needed
  229. if [[ -v buildpkglist ]]; then
  230. echo -e "The following build time dependencies were installed and no longer needed:\n\n$(for l in ${buildpkglist[*]}; do echo ${l}; done)\n"
  231. fi