wine_select.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/bin/sh
  2. # wine-select.sh - Selects the default wine version.
  3. # Copyright 2019 orbea
  4. # All rights reserved.
  5. #
  6. # Redistribution and use of this script, with or without modification, is
  7. # permitted provided that the following conditions are met:
  8. #
  9. # 1. Redistributions of this script must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
  13. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  15. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  16. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  18. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  19. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  20. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  21. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. IFS='
  23. '
  24. set -eu
  25. die () {
  26. ret="$1"; shift
  27. case "$ret" in
  28. : ) printf %s\\n "$@" >&2; return 0 ;;
  29. 0 ) printf %s\\n "$@" ;;
  30. * ) printf %s\\n "$@" >&2 ;;
  31. esac
  32. exit "$ret"
  33. }
  34. doinst () {
  35. if [ -x "$udd" ] && [ -f "$udd" ]; then
  36. "$udd" -q /usr/share/applications
  37. fi
  38. }
  39. default='/var/lib/wine/default'
  40. udd='/usr/bin/update-desktop-database'
  41. usage="wine-select.sh - Selects the default wine version.
  42. Usage: wine-select.sh [OPTIONS]
  43. -h, --help, Show this help message.
  44. -u, --uninstall, Remove existing symlinks.
  45. Files:
  46. $default : List of symlinks for the default wine version."
  47. list=
  48. files=
  49. choice=
  50. uninstall=
  51. while [ $# -gt 0 ]; do
  52. option="$1"
  53. shift
  54. case "$option" in
  55. -- ) break ;;
  56. -u|--uninstall ) uninstall=1 ;;
  57. -h|--help ) die 0 "$usage" ;;
  58. * ) die 1 "Unrecognized option '$option', use -h for help." ;;
  59. esac
  60. done
  61. [ "$(id -u)" != 0 ] && die 1 'ERROR: User is not root.'
  62. cd /opt
  63. if [ -z "${uninstall}" ]; then
  64. printf %s\\n '' 'Select the default wine install:' ''
  65. n=0
  66. for i in wine*/*; do
  67. [ -d "$i" ] || continue
  68. printf %s\\n " $n ) $i" | tr '/' '-'
  69. eval "wine$n=\"$i\""
  70. list="${list} $n"
  71. n=$((n+1))
  72. done
  73. printf %s\\n ''
  74. read -r selection
  75. eval "set -- $list"
  76. for i do
  77. case "$selection" in
  78. "$i" ) eval "choice=\"\${wine$selection}\""; break ;;
  79. * ) continue ;;
  80. esac
  81. done
  82. if [ -z "${choice}" ]; then
  83. die 1 'ERROR: Invalid wine version chosen.'
  84. fi
  85. fi
  86. mkdir -p /var/lib/wine
  87. if [ -f "$default" ] && [ -r "$default" ]; then
  88. while read -r line; do
  89. if [ -h "$line" ]; then
  90. rm -f -- "$line"
  91. fi
  92. done < "$default"
  93. fi
  94. if [ "${uninstall}" ]; then
  95. doinst
  96. rm -f "$default"
  97. exit 0
  98. fi
  99. ln='/usr/bin/ln'
  100. winedir="/opt/$choice"
  101. for bin in "$winedir"/bin/*; do
  102. if [ ! -e "/usr${bin#$winedir}" ]; then
  103. "$ln" -sf "$bin" /usr/bin
  104. files="${files} /usr${bin#$winedir}"
  105. else
  106. die : "WARNING: File '$bin' already exists."
  107. fi
  108. done
  109. for libpath in lib lib64; do
  110. [ -d "$winedir/$libpath" ] || continue
  111. mkdir -p "/usr/$libpath/wine/fakedlls"
  112. for lib in "$winedir/$libpath"/* "$winedir/$libpath"/wine/* \
  113. "$winedir/$libpath"/wine/fakedlls/*; do
  114. if [ -f "$lib" ]; then
  115. if [ ! -e "/usr/${lib#$winedir}/wine" ]; then
  116. libdir="${lib%/*}"
  117. "$ln" -sf "$lib" "/usr${libdir#$winedir}"
  118. files="${files} /usr${lib#$winedir}"
  119. else
  120. die : "WARNING: File '$lib' already exists."
  121. fi
  122. fi
  123. done
  124. done
  125. for man in "$winedir"/man/*/*.gz "$winedir"/man/*/*/*.gz; do
  126. if [ ! -e "/usr/${man#$winedir}" ]; then
  127. mandir="${man%/*}"
  128. mkdir -p "/usr/${mandir#$winedir}"
  129. "$ln" -sf "$man" "/usr${mandir#$winedir}"
  130. files="${files} /usr${man#$winedir}"
  131. else
  132. die : "WARNING: File '$man' already exists."
  133. fi
  134. done
  135. for misc in include/wine share/wine share/applications/wine.desktop; do
  136. if [ ! -e "/usr/$misc" ]; then
  137. "$ln" -sf "$winedir/$misc" "/usr/$misc"
  138. files="${files} /usr/$misc"
  139. else
  140. die : "WARNING: File '$winedir/$misc' already exists."
  141. fi
  142. done
  143. if [ "${files}" ]; then
  144. doinst
  145. printf %s\\n "${files# }" | tr ' ' '\n' | sort > "$default"
  146. printf %s\\n '' "Wine version '$choice' selected." '' | tr '/' '-'
  147. fi
  148. exit 0