wine_select.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. test_null_file () {
  100. if [ -e "$1" ]; then
  101. die : "WARNING: File '$2' already exists."
  102. return 1
  103. fi
  104. return 0
  105. }
  106. ln='/usr/bin/ln'
  107. winedir="/opt/$choice"
  108. for bin in "$winedir"/bin/*; do
  109. if test_null_file "/usr${bin#$winedir}" "$bin"; then
  110. "$ln" -sf "$bin" /usr/bin
  111. files="${files} /usr${bin#$winedir}"
  112. fi
  113. done
  114. for libpath in lib lib64; do
  115. [ -d "$winedir/$libpath" ] || continue
  116. mkdir -p "/usr/$libpath/wine/fakedlls"
  117. for lib in "$winedir/$libpath"/* "$winedir/$libpath"/wine/* \
  118. "$winedir/$libpath"/wine/fakedlls/*; do
  119. if [ -f "$lib" ] && test_null_file "/usr/${lib#$winedir}/wine" "$lib"; then
  120. libdir="${lib%/*}"
  121. "$ln" -sf "$lib" "/usr${libdir#$winedir}"
  122. files="${files} /usr${lib#$winedir}"
  123. fi
  124. done
  125. done
  126. for man in "$winedir"/man/*/*.gz "$winedir"/man/*/*/*.gz; do
  127. if test_null_file "/usr/${man#$winedir}" "$man"; then
  128. mandir="${man%/*}"
  129. mkdir -p "/usr/${mandir#$winedir}"
  130. "$ln" -sf "$man" "/usr${mandir#$winedir}"
  131. files="${files} /usr${man#$winedir}"
  132. fi
  133. done
  134. for misc in include/wine share/wine share/applications/wine.desktop; do
  135. if test_null_file "/usr/$misc" "$winedir/$misc"; then
  136. "$ln" -sf "$winedir/$misc" "/usr/$misc"
  137. files="${files} /usr/$misc"
  138. fi
  139. done
  140. if [ "${files}" ]; then
  141. doinst
  142. printf %s\\n "${files# }" | tr ' ' '\n' | sort > "$default"
  143. printf %s\\n '' "Wine version '$choice' selected." '' | tr '/' '-'
  144. fi
  145. exit 0