Path: blob/main/emulators/i386-wine/files/nvidia.sh
16146 views
#!/bin/sh1# Copyright 2010 to 2015 David Naylor <[email protected]>2# Copyright 2012 Jan Beich <[email protected]>3# Copyright 2020 Lorenzo Salvadore <[email protected]>4# All rights reserved.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions are met:8#9# 1. Redistributions of source code must retain the above copyright notice,10# this list of conditions and the following disclaimer.11#12# 2. Redistributions in binary form must reproduce the above copyright notice,13# this list of conditions and the following disclaimer in the documentation14# and/or other materials provided with the distribution.15#16# THIS SOFTWARE IS PROVIDED BY David Naylor ``AS IS'' AND ANY EXPRESS OR IMPLIED17# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF18# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO19# EVENT SHALL David Naylor OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,20# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,22# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF23# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING24# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,25# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26#27# The views and conclusions contained in the software and documentation are28# those of the authors and should not be interpreted as representing official29# policies, either expressed or implied, of David Naylor.3031# Version 1.0 - 2010/05/2832# - initial release33# Version 1.1 - 2010/10/0434# - add support for 256 driver series35# - use passive connections for FTP36# - allow resuming of downloads if they were interrupted37# - add license and copyright notice38# Version 1.2 - 2010/10/1739# - try to save the NVIDIA tarball under $PORTSDIR/distfiles40# - obay $PREFIX41# - extract files directly to destination (avoids using /tmp)42# Version 1.3 - 2010/11/0243# - add support for future driver series44# Version 1.4 - 2011/05/2345# - add support for legacy drivers46# Version 1.5 - 2011/10/2347# - add support for no-fetch mode48# - backup the original openGL.so.1 library49# Version 1.6 - 2012/06/0650# - add support for pkgng51# Version 1.7 - 2012/06/2352# - make nVidia detection more robust53# - allow mixed pkg/pkgng operation54# Version 1.8 - 2012/07/0255# - fix mixed pkg/pkgng operation56# Version 1.9 - 2012/10/3157# - fix permission of extracts files58# Version 1.10 - 2013/05/0659# - s/wine-fbsd64/i386-wine/g60# - fix unwanted failures due to `set -e`61# Version 1.11 - 2013/05/2662# - install libGL.so.1 to ${PREFIX}/lib32/.nvidia and link to it63# - add deinstall option64# Version 1.12 - 2013/11/0365# - add detection for i386-wine-devel66# Version 1.13 - 2014/08/0567# - add detection for i386-wine-compholio68# Version 1.14 - 2014/12/2669# - gracefully handle a corrupt nVidia tarball70# - provide checksum and size information for nVidia tarball71# Version 1.15 - 2015/03/1072# - handle nvidia-driver with package name suffix73# - handle i386-wine with arbitary package name suffix74# - remove support for old pkg_ tools75# Version 1.16 - 2017/06/0476# - use https download site77# Version 1.17 - 2020/03/0278# - do not do anything if nvidia-driver version >= 440.597980set -e8182PORTSDIR=${PORTSDIR:-/usr/ports}83PREFIX=${PREFIX:-/usr/local}84DISTDIR=${DISTDIR:-${PORTSDIR}/distfiles}8586if [ -d $DISTDIR ]87then88cd $DISTDIR89NO_REMOVE_NVIDIA="yes"90else91cd /tmp/92fi9394terminate() {9596echo "!!! $2 !!!"97echo "Terminating..."98exit $199100}101102args=`getopt dn $*`103if [ $? -ne 0 ]104then105echo "Usage: $0 [-n]"106exit 7107fi108set -- $args109while true110do111case $1 in112-d)113rm -f ${PREFIX}/lib32/libGL.so.1114rm -f ${PREFIX}/lib32/libGLcore.so.1 ${PREFIX}/lib32/libnvidia-tls.so.1115rm -f ${PREFIX}/lib32/libnvidia-glcore.so.1 ${PREFIX}/lib32/libnvidia-tls.so.1116rm -rf ${PREFIX}/lib32/.nvidia/117if [ -d ${PREFIX}/lib32/.libGL-new ]118then119ln -s .libGL-new/libGL.so.1 ${PREFIX}/lib32/libGL.so.1120else121ln -s .libGL/libGL.so.1 ${PREFIX}/lib32/libGL.so.1122fi123exit 0124;;125-n)126NO_FETCH=yes127;;128--)129shift130break131;;132esac133shift134done135136version() {137local ret pkg="$1"138if [ -f "/usr/local/sbin/pkg" ]139then140ret=`pkg query -g '%v' "$pkg" || true`141fi142143# installed manually or failed to register144if [ -z "$ret" ] && [ "$pkg" = "nvidia-driver*" ]145then146ret=`sed -n "s/.*Version: //p" 2> /dev/null \147$PREFIX/share/doc/NVIDIA_GLX-1.0/README || true`148fi149echo "$ret"150}151152[ `whoami` = root ] \153|| terminate 254 "This script should be run as root"154155echo "===> Patching i386-wine to work with x11/nvidia-driver:"156157if [ -z "${WINE}" ]158then159WINE=`version 'i386-wine*'`160fi161[ -n "$WINE" ] \162|| terminate 255 "Unable to detect i386-wine, please install first"163echo "=> Detected i386-wine: ${WINE}"164165NV=`version 'nvidia-driver*'`166[ -n "$NV" ] \167|| terminate 1 "Unable to detect nvidia-driver, please install first"168echo "=> Detected nvidia-driver: ${NV}"169170NVIDIA=${NV}171NV=`echo ${NV} | cut -f 1 -d _ | cut -f 1 -d ,`172173if [ ! "$(pkg version -t ${NV} 440.59)" == "<" ]174then175terminate 0 "nvidia-driver 440.59+ already includes 32-bit drivers: nothing to do"176fi177178if [ ! -f NVIDIA-FreeBSD-x86-${NV}.tar.gz ] || !(tar -tf NVIDIA-FreeBSD-x86-${NV}.tar.gz > /dev/null 2>&1)179then180[ -n "$NO_FETCH" ] \181&& terminate 8 "NVIDIA-FreeBSD-x86-${NV}.tar.gz unavailable"182echo "=> Downloading NVIDIA-FreeBSD-x86-${NV}.tar.gz from https://download.nvidia.com..."183rm -f NVIDIA-FreeBSD-x86-${NV}.tar.gz184fetch -aRr https://download.nvidia.com/XFree86/FreeBSD-x86/${NV}/NVIDIA-FreeBSD-x86-${NV}.tar.gz \185|| terminate 2 "Failed to download NVIDIA-FreeBSD-x86-${NV}.tar.gz"186echo "=> Downloaded NVIDIA-FreeBSD-x86-${NV}.tar.gz"187echo "Please check the following information against /usr/ports/x11/nvidia-driver/distinfo"188sha256 NVIDIA-FreeBSD-x86-${NV}.tar.gz189echo "SIZE (NVIDIA-FreeBSD-x86-${NV}.tar.gz) = `stat -f "%z" NVIDIA-FreeBSD-x86-${NV}.tar.gz`"190fi191192echo "=> Extracting NVIDIA-FreeBSD-x86-${NV}.tar.gz to $PREFIX/lib32..."193EXTRACT_LIST="libGL.so.1"194case $NV in195195*|173*|96*|71*)196EXTRACT_LIST="$EXTRACT_LIST libGLcore.so.1 libnvidia-tls.so.1"197;;198*)199EXTRACT_LIST="$EXTRACT_LIST libnvidia-glcore.so.1 libnvidia-tls.so.1"200;;201esac202203EXTRACT_ARGS="--no-same-owner --no-same-permissions --strip-components 2 -C $PREFIX/lib32"204for i in $EXTRACT_LIST205do206EXTRACT_ARGS="$EXTRACT_ARGS --include NVIDIA-FreeBSD-x86-${NV}/obj/$i"207done208umask 0333209tar $EXTRACT_ARGS -xvf NVIDIA-FreeBSD-x86-${NV}.tar.gz \210|| terminate 3 "Failed to extract NVIDIA-FreeBSD-x86-${NV}.tar.gz"211mkdir -m 0755 -p ${PREFIX}/lib32/.nvidia \212|| terminate 9 "Failed to create .nvidia shadow directory"213mv ${PREFIX}/lib32/libGL.so.1 ${PREFIX}/lib32/.nvidia/ \214|| terminate 10 "Failed to move libGL.so.1 to .nvidia/ shadow directory"215ln -s .nvidia/libGL.so.1 ${PREFIX}/lib32/libGL.so.1 \216|| terminate 11 "Failed to link to .nvidia/libGL.so.1 in the shadow directory"217218echo "=> Cleaning up..."219[ -n "$NO_REMOVE_NVIDIA" ] || rm -vf NVIDIA-FreeBSD-x86-${NV}.tar.gz \220|| terminate 6 "Failed to remove files"221222echo "===> i386-wine-${WINE} successfully patched for nvidia-driver-${NVIDIA}"223224225