install-wine-SLVoice.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. #!/usr/bin/env bash
  2. # install-wine-SLVoice.sh v1.44 (c)2020-2024 Henri Beauchamp.
  3. # Released under the GPL license. https://www.gnu.org/licenses/gpl-3.0.txt
  4. WIN32_SLVOICE="http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/55968/524423/slvoice-4.10.0000.32327.5fc3fe7c.539691-windows-539691.tar.bz2"
  5. WIN64_SLVOICE="http://automated-builds-secondlife-com.s3.amazonaws.com/ct2/55967/524409/slvoice-4.10.0000.32327.5fc3fe7c.539691-windows64-539691.tar.bz2"
  6. # This is our custom Wine prefix for SLVoice
  7. export WINEPREFIX="$HOME/.wine-slvoice"
  8. # This is where the SLVoice client will be installed
  9. WINE_INSTALL_DIR="$WINEPREFIX/drive_c/Vivox"
  10. # Prevents Wine from asking to install Mono and Gecko...
  11. export WINEDLLOVERRIDES="mscoree,mshtml="
  12. # No verbose debugging, please !
  13. export WINEDEBUG="-all"
  14. # If the ~/.wine-slvoice prefix was already installed and this script is passed
  15. # an option, then run any corresponding Wine program on that prefix. We support
  16. # any option containing "-c" for winecfg or "-r" for regedit.
  17. if [ -f "$WINEPREFIX/system.reg" ] ; then
  18. if echo "$1" | grep "\-c" &>/dev/null ; then
  19. exec winecfg
  20. elif echo "$1" | grep "\-r" &>/dev/null ; then
  21. exec regedit
  22. fi
  23. fi
  24. # If we are not ran from a terminal, try and find a terminal on this system,
  25. # then launch it and restart ourselves within it.
  26. if ! [ -t 1 ] ; then
  27. cmd="-e"
  28. terminal=""
  29. if which xterm &>/dev/null ; then
  30. terminal="xterm"
  31. elif which rxvt &>/dev/null ; then
  32. terminal="rxvt"
  33. elif which mate-terminal &>/dev/null ; then
  34. terminal="mate-terminal"
  35. elif which gnome-terminal &>/dev/null ; then
  36. terminal="gnome-terminal"
  37. elif which kde-terminal &>/dev/null ; then
  38. terminal="kde-terminal"
  39. elif which xfce4-terminal &>/dev/null ; then
  40. terminal="xfce4-terminal"
  41. elif which qterminal &>/dev/null ; then
  42. terminal="qterminal"
  43. elif which Eterm &>/dev/null ; then
  44. terminal="Eterm"
  45. elif which x-terminal-emulator &>/dev/null ; then
  46. terminal="x-terminal-emulator"
  47. elif which terminator &>/dev/null ; then
  48. terminal="terminator"
  49. elif which xdg-terminal &>/dev/null ; then
  50. # NOTE: xdg-terminal may fail (due to a bug in failing to unquote
  51. # gsettings returned strings)...
  52. terminal="xdg-terminal"
  53. cmd=""
  54. else
  55. echo "This script must be ran from a terminal !"
  56. exit 1
  57. fi
  58. exec $terminal $cmd $0
  59. fi
  60. # Use colors, if stdout is emitted onto a terminal supporting them
  61. white_on_blue=""
  62. black_on_yellow=""
  63. black_on_green=""
  64. white_on_red=""
  65. white_on_black=""
  66. default_colors=""
  67. colors=`tput colors`
  68. if [ "$colors" != "" ] && (( $colors >= 8 )) ; then
  69. white_on_blue=$'\e[48;2;0;0;160m\e[38;2;255;255;255m'
  70. black_on_yellow=$'\e[48;2;255;255;0m\e[38;2;0;0;0m'
  71. black_on_green=$'\e[48;2;0;255;0m\e[38;2;0;0;0m'
  72. white_on_red=$'\e[48;2;255;0;0m\e[38;2;255;255;255m'
  73. white_on_black=$'\e[48;2;0;0;0m\e[38;2;255;255;255m'
  74. default_colors=$'\033[0m'
  75. fi
  76. function pause()
  77. {
  78. echo
  79. read -s -n 1 -p "${white_on_blue} $1 ${default_colors}"
  80. echo
  81. }
  82. function success()
  83. {
  84. echo "${black_on_green} ==> $1 ${default_colors}"
  85. }
  86. function warning()
  87. {
  88. echo "${black_on_yellow} WARNING: $1 ${default_colors}"
  89. }
  90. function error()
  91. {
  92. echo "${white_on_red} ERROR: $1 ${default_colors}"
  93. }
  94. echo
  95. echo "==============================================================================="
  96. echo " install-wine-SLVoice.sh "
  97. echo "==============================================================================="
  98. echo
  99. echo "This script will (try and) (re)install a \"Wine prefix\" for SLVoice.exe, i.e."
  100. echo "a specific Wine installation only for the purpose of running SLVoice.exe from"
  101. echo "the Linux version of the Cool VL Viewer. This is a per-account installation (in"
  102. echo "your home directory), not a system-wide one."
  103. echo "Any other Wine prefixes (such as the default one residing in ~/.wine) will be"
  104. echo "left untouched and have no impact whatsoever on ours."
  105. echo
  106. echo "Once installed, the SLVoice.exe client will be usable with any forthcoming"
  107. echo "version of the Cool VL Viewer and won't need to be reinstalled whenever you"
  108. echo "udpate the viewer."
  109. echo
  110. echo "SLVoice.exe will be installed in: ${white_on_black}$WINE_INSTALL_DIR${default_colors}"
  111. echo
  112. echo "The script will also verify that your system can run Windows binaries via"
  113. echo "Wine and the binfmt_misc mechanism of the Linux kernel or a wrapper script."
  114. echo
  115. echo "Finally, it will configure the Cool VL Viewer to run the installed Windows"
  116. echo "voice client (via appropriate variables in ~/.secondlife/cool_vl_viewer.conf)."
  117. pause "Press any key to continue (or CTRL C to abort)."
  118. scriptsrc=`readlink -f "$0" || echo "$0"`
  119. run_path=`dirname "$scriptsrc" || echo .`
  120. if [ ! -f "$run_path/app_settings/ca-bundle.crt" ] ; then
  121. echo
  122. error "could not find app_settings/ca-bundle.crt !"
  123. echo "This script must be placed in and ran from the viewer installation directory !"
  124. pause "Press any key to exit."
  125. exit 1
  126. fi
  127. echo
  128. echo "Checking for Wine availability..."
  129. if ! which winecfg &>/dev/null ; then
  130. echo
  131. error "No Wine installation found ('winecfg' not found) !"
  132. echo
  133. echo "Please make sure to install Wine (either 32 or 64 bits) on your system,"
  134. echo "after which step you can re-run this script..."
  135. pause "Press any key to exit."
  136. exit 1
  137. fi
  138. echo
  139. echo "Checking for Wine type (32 or 64 bits)..."
  140. wine_binary=""
  141. export WINEARCH="win32"
  142. wine_binary=`which wine64 2>/dev/null`
  143. if (( $? == 0 )) ; then
  144. export WINEARCH="win64"
  145. else
  146. wine_binary=`which wine 2>/dev/null`
  147. if (( $? == 0 )) ; then
  148. if file $wine_binary | grep "64-bit" &>/dev/null ; then
  149. export WINEARCH="win64"
  150. fi
  151. else
  152. wine_binary=`which wine32 2>/dev/null`
  153. fi
  154. fi
  155. if [ "$wine_binary" == "" ] ; then
  156. echo
  157. warning "no 'wine[32|64]' executable found; binfmt_misc will be required."
  158. else
  159. echo "Found wine binary: $wine_binary"
  160. fi
  161. echo
  162. echo "Will use the $WINEARCH architecture for our Wine prefix."
  163. # Allow forcing the use of a wrapper script to launch SLVoice.exe, when a "-w"
  164. # option is passed to this script. NOTE: the wrapper can only be created if
  165. # either of "wine64", "wine" or "wine32" Wine executables are present on the
  166. # system.
  167. needs_wrapper=0
  168. if echo "$1" | grep "\-w" &>/dev/null ; then
  169. needs_wrapper=1
  170. fi
  171. echo
  172. echo "Checking that binfmt_misc exists and is configured to allow the"
  173. echo "execution of Windows binaries..."
  174. has_binfmt_misc=0
  175. binfmt_misc_enabled=0
  176. if [ -d /proc/sys/fs/binfmt_misc ] ; then
  177. for i in /proc/sys/fs/binfmt_misc/* ; do
  178. if [ "$i" != "status" ] && [ "$i" != "register" ] && (( $binfmt_misc_enabled == 0 )) ; then
  179. if grep -m 1 "magic 4d5a" "$i" &>/dev/null ; then
  180. has_binfmt_misc=1
  181. temp=`head -1 "$i" 2>/dev/null`
  182. if [ "$temp" == "enabled" ] ; then
  183. binfmt_misc_enabled=1
  184. temp=`grep -m 1 interpreter "$i" 2>/dev/null | cut -d ' ' -f 2`
  185. if [ "$temp" == "" ] || [ ! -x "$temp" ] ; then
  186. binfmt_misc_enabled=0
  187. echo
  188. warning "found a Wine entry ($i) but not its '$temp' interpreter."
  189. echo "You might need to create (as root) a link to the actual Wine executable, e.g."
  190. echo "ln -s /usr/bin/wine64 $temp"
  191. fi
  192. else
  193. echo
  194. warning "found a Wine entry ($i) but it is disabled."
  195. fi
  196. fi
  197. fi
  198. done
  199. if (( $binfmt_misc_enabled == 1 )) ; then
  200. echo
  201. success "Good ! Wine is registered in binfmt_misc."
  202. elif [ "$wine_binary" == "" ] ; then
  203. warning "you will need to enable the existing Wine entry."
  204. else
  205. warning "no enabled entry found to launch Wine via binfmt_misc."
  206. echo "${white_on_black}A wrapper script will be created to call $wine_binary${default_colors}"
  207. echo "${white_on_black}and launch the voice client...${default_colors}"
  208. needs_wrapper=1
  209. fi
  210. elif [ "$wine_binary" == "" ] ; then
  211. echo
  212. error "binfmt_misc is not available on this system !"
  213. echo "The viewer would not be able to launch directly a Windows binary"
  214. echo "and no 'wine' executable was found on this system either..."
  215. echo
  216. echo "Please, enable binfmt_misc (review your Linux distribution FAQ) and"
  217. echo "once enabled, re-run this script."
  218. pause "Press any key to exit."
  219. exit 1
  220. else
  221. needs_wrapper=1
  222. echo
  223. warning "binfmt_misc is not available on this system."
  224. echo "${white_on_black}A wrapper script will be created to call $wine_binary${default_colors}"
  225. echo "${white_on_black}and launch the voice client...${default_colors}"
  226. fi
  227. if [ "$needs_wrapper" == "0" ]; then
  228. if [ "$has_binfmt_misc" == "0" ]; then
  229. echo
  230. error "binfmt_misc not configured to run Windows binaries on this system."
  231. echo "The viewer would not be able to launch the Windows voice client."
  232. echo
  233. echo "Please, enable binfmt_misc for Wine. Example of valid enabling (as root):"
  234. echo "echo \":windows:M::MZ::/usr/bin/wine:\" >/proc/sys/fs/binfmt_misc/register"
  235. echo "(supposing the Wine binary is indeed /usr/bin/wine)"
  236. echo "Once this is done, you can re-run this script."
  237. pause "Press any key to exit."
  238. exit 1
  239. elif [ "$binfmt_misc_enabled" == "1" ] ; then
  240. binfmt_misc_enabled=`cat /proc/sys/fs/binfmt_misc/status`
  241. if [ "$binfmt_misc_enabled" != "enabled" ] ; then
  242. echo
  243. warning "binfmt_misc is currently disabled, system wide."
  244. if [ "$wine_binary" == "" ] ; then
  245. echo "You will have to enable it so that the viewer can launch the Windows"
  246. echo "SLVoice client..."
  247. else
  248. needs_wrapper=1
  249. echo "${white_on_black}A wrapper script will be created to call $wine_binary${default_colors}"
  250. echo "${white_on_black}and launch the voice client...${default_colors}"
  251. fi
  252. fi
  253. fi
  254. fi
  255. if [ -d "$WINEPREFIX" ] ; then
  256. echo
  257. echo "Removing the old SLVoice Wine installation..."
  258. rm -rf "$WINEPREFIX"
  259. fi
  260. echo
  261. echo "We are now going to create a brand new Wine prefix... Launching winecfg."
  262. echo
  263. echo "${white_on_blue} Review the Audio settings and close the window with 'OK' when done... ${default_colors}"
  264. winecfg &>/dev/null
  265. # As long as Wine services are running, system.reg may appear missing while it
  266. # is there. Probably some weird file locking issue...
  267. if [ ! -f "$WINEPREFIX/system.reg" ] ; then
  268. echo
  269. echo "${white_on_black}Waiting for Wine to shut down...${default_colors}"
  270. let delay=20
  271. while [ ! -f "$WINEPREFIX/system.reg" ] && (( $delay > 0 )) ; do
  272. let delay=$delay-1
  273. sleep 1
  274. done
  275. fi
  276. if [ ! -f "$WINEPREFIX/system.reg" ] ; then
  277. echo
  278. error "Wine prefix creation failed ! Aborting."
  279. pause "Press any key to exit."
  280. exit 1
  281. fi
  282. echo
  283. slvoice_package=""
  284. wine_arch=`cat $WINEPREFIX/system.reg | grep -m 1 '#arch' | cut -d '=' -f2`
  285. if [ "$wine_arch" == "win32" ] ; then
  286. echo "Win32 prefix detected. Installing the 32 bits SLVoice version..."
  287. slvoice_package="$WIN32_SLVOICE"
  288. else
  289. echo "Win64 prefix detected. Installing the 64 bits SLVoice version..."
  290. slvoice_package="$WIN64_SLVOICE"
  291. fi
  292. mkdir -p "$WINE_INSTALL_DIR"
  293. pushd "$WINE_INSTALL_DIR" &>/dev/null
  294. echo
  295. echo "Downloading the corresponding package..."
  296. echo
  297. if which wget &>/dev/null ; then
  298. wget "$slvoice_package"
  299. elif which curl &>/dev/null ; then
  300. curl -O "$slvoice_package"
  301. else
  302. error "cannot download the file !"
  303. echo "Please install either wget or curl and re-run this script..."
  304. pause "Press any key to exit."
  305. exit 1
  306. fi
  307. echo
  308. echo "Extracting files..."
  309. tar xjf *.tar.bz2
  310. rm -f *.tar.bz2 *.xml
  311. mv -f bin/release/SLVoice.exe .
  312. chmod +x SLVoice.exe
  313. mv -f lib/release/*.dll .
  314. # Note: dbghelp.dll is already part of/adapted to Wine, so no need for the one
  315. # bundled with Vivox.
  316. rm -f DbgHelp.dll
  317. rm -rf bin/ lib/
  318. echo
  319. echo "Copying the certificates bundle..."
  320. cp -a $run_path/app_settings/ca-bundle.crt .
  321. exec="SLVoice.exe"
  322. if [ "$needs_wrapper" == "1" ]; then
  323. echo
  324. echo "Creating a wrapper script..."
  325. exec="slvoice-wine-wrapper.sh"
  326. echo "#!/usr/bin/env bash" >$exec
  327. echo "unset LD_PRELOAD" >>$exec
  328. echo "exec $wine_binary $WINE_INSTALL_DIR/SLVoice.exe \$*" >>$exec
  329. chmod +x $exec
  330. fi
  331. echo
  332. success "SLVoice installation done."
  333. popd &>/dev/null
  334. # Default path for SL viewers application directory:
  335. sl_app_dir="$HOME/.secondlife"
  336. if [ "$SECONDLIFE_USER_DIR" != "" ] ; then
  337. sl_app_dir="$SECONDLIFE_USER_DIR"
  338. echo
  339. echo "Adopting user-set SL viewers application directory: ${white_on_black}$sl_app_dir${default_colors}"
  340. fi
  341. echo
  342. mkdir -p "$sl_app_dir"
  343. conf_file="$sl_app_dir/cool_vl_viewer.conf"
  344. if [ -f "$conf_file" ] ; then
  345. echo "Updating your ${white_on_black}$conf_file${default_colors} file..."
  346. grep -v WINEPREFIX "$conf_file" >"$conf_file.$$"
  347. grep -v WINEDLLOVERRIDES "$conf_file.$$" >"$conf_file"
  348. grep -v WINEDEBUG "$conf_file" >"$conf_file.$$"
  349. grep -v LL_WINE_SLVOICE "$conf_file.$$" >"$conf_file"
  350. rm -f "$conf_file.$$"
  351. else
  352. echo "Creating a ${white_on_black}$conf_file${default_colors} file..."
  353. fi
  354. echo "export WINEPREFIX=\"$WINEPREFIX\"" >>"$conf_file"
  355. echo "export WINEDLLOVERRIDES=\"mscoree,mshtml=\"" >>"$conf_file"
  356. echo "export WINEDEBUG=\"-all\"" >>"$conf_file"
  357. echo "export LL_WINE_SLVOICE=\"$WINE_INSTALL_DIR/$exec\"" >>"$conf_file"
  358. echo
  359. success "Viewer configuration done."
  360. pause "All done ! Press any key to exit."