Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-gnome
Path: blob/main/emulators/i386-wine/files/nvidia.sh
16146 views
1
#!/bin/sh
2
# Copyright 2010 to 2015 David Naylor <[email protected]>
3
# Copyright 2012 Jan Beich <[email protected]>
4
# Copyright 2020 Lorenzo Salvadore <[email protected]>
5
# All rights reserved.
6
#
7
# Redistribution and use in source and binary forms, with or without
8
# modification, are permitted provided that the following conditions are met:
9
#
10
# 1. Redistributions of source code must retain the above copyright notice,
11
# this list of conditions and the following disclaimer.
12
#
13
# 2. Redistributions in binary form must reproduce the above copyright notice,
14
# this list of conditions and the following disclaimer in the documentation
15
# and/or other materials provided with the distribution.
16
#
17
# THIS SOFTWARE IS PROVIDED BY David Naylor ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20
# EVENT SHALL David Naylor OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#
28
# The views and conclusions contained in the software and documentation are
29
# those of the authors and should not be interpreted as representing official
30
# policies, either expressed or implied, of David Naylor.
31
32
# Version 1.0 - 2010/05/28
33
# - initial release
34
# Version 1.1 - 2010/10/04
35
# - add support for 256 driver series
36
# - use passive connections for FTP
37
# - allow resuming of downloads if they were interrupted
38
# - add license and copyright notice
39
# Version 1.2 - 2010/10/17
40
# - try to save the NVIDIA tarball under $PORTSDIR/distfiles
41
# - obay $PREFIX
42
# - extract files directly to destination (avoids using /tmp)
43
# Version 1.3 - 2010/11/02
44
# - add support for future driver series
45
# Version 1.4 - 2011/05/23
46
# - add support for legacy drivers
47
# Version 1.5 - 2011/10/23
48
# - add support for no-fetch mode
49
# - backup the original openGL.so.1 library
50
# Version 1.6 - 2012/06/06
51
# - add support for pkgng
52
# Version 1.7 - 2012/06/23
53
# - make nVidia detection more robust
54
# - allow mixed pkg/pkgng operation
55
# Version 1.8 - 2012/07/02
56
# - fix mixed pkg/pkgng operation
57
# Version 1.9 - 2012/10/31
58
# - fix permission of extracts files
59
# Version 1.10 - 2013/05/06
60
# - s/wine-fbsd64/i386-wine/g
61
# - fix unwanted failures due to `set -e`
62
# Version 1.11 - 2013/05/26
63
# - install libGL.so.1 to ${PREFIX}/lib32/.nvidia and link to it
64
# - add deinstall option
65
# Version 1.12 - 2013/11/03
66
# - add detection for i386-wine-devel
67
# Version 1.13 - 2014/08/05
68
# - add detection for i386-wine-compholio
69
# Version 1.14 - 2014/12/26
70
# - gracefully handle a corrupt nVidia tarball
71
# - provide checksum and size information for nVidia tarball
72
# Version 1.15 - 2015/03/10
73
# - handle nvidia-driver with package name suffix
74
# - handle i386-wine with arbitary package name suffix
75
# - remove support for old pkg_ tools
76
# Version 1.16 - 2017/06/04
77
# - use https download site
78
# Version 1.17 - 2020/03/02
79
# - do not do anything if nvidia-driver version >= 440.59
80
81
set -e
82
83
PORTSDIR=${PORTSDIR:-/usr/ports}
84
PREFIX=${PREFIX:-/usr/local}
85
DISTDIR=${DISTDIR:-${PORTSDIR}/distfiles}
86
87
if [ -d $DISTDIR ]
88
then
89
cd $DISTDIR
90
NO_REMOVE_NVIDIA="yes"
91
else
92
cd /tmp/
93
fi
94
95
terminate() {
96
97
echo "!!! $2 !!!"
98
echo "Terminating..."
99
exit $1
100
101
}
102
103
args=`getopt dn $*`
104
if [ $? -ne 0 ]
105
then
106
echo "Usage: $0 [-n]"
107
exit 7
108
fi
109
set -- $args
110
while true
111
do
112
case $1 in
113
-d)
114
rm -f ${PREFIX}/lib32/libGL.so.1
115
rm -f ${PREFIX}/lib32/libGLcore.so.1 ${PREFIX}/lib32/libnvidia-tls.so.1
116
rm -f ${PREFIX}/lib32/libnvidia-glcore.so.1 ${PREFIX}/lib32/libnvidia-tls.so.1
117
rm -rf ${PREFIX}/lib32/.nvidia/
118
if [ -d ${PREFIX}/lib32/.libGL-new ]
119
then
120
ln -s .libGL-new/libGL.so.1 ${PREFIX}/lib32/libGL.so.1
121
else
122
ln -s .libGL/libGL.so.1 ${PREFIX}/lib32/libGL.so.1
123
fi
124
exit 0
125
;;
126
-n)
127
NO_FETCH=yes
128
;;
129
--)
130
shift
131
break
132
;;
133
esac
134
shift
135
done
136
137
version() {
138
local ret pkg="$1"
139
if [ -f "/usr/local/sbin/pkg" ]
140
then
141
ret=`pkg query -g '%v' "$pkg" || true`
142
fi
143
144
# installed manually or failed to register
145
if [ -z "$ret" ] && [ "$pkg" = "nvidia-driver*" ]
146
then
147
ret=`sed -n "s/.*Version: //p" 2> /dev/null \
148
$PREFIX/share/doc/NVIDIA_GLX-1.0/README || true`
149
fi
150
echo "$ret"
151
}
152
153
[ `whoami` = root ] \
154
|| terminate 254 "This script should be run as root"
155
156
echo "===> Patching i386-wine to work with x11/nvidia-driver:"
157
158
if [ -z "${WINE}" ]
159
then
160
WINE=`version 'i386-wine*'`
161
fi
162
[ -n "$WINE" ] \
163
|| terminate 255 "Unable to detect i386-wine, please install first"
164
echo "=> Detected i386-wine: ${WINE}"
165
166
NV=`version 'nvidia-driver*'`
167
[ -n "$NV" ] \
168
|| terminate 1 "Unable to detect nvidia-driver, please install first"
169
echo "=> Detected nvidia-driver: ${NV}"
170
171
NVIDIA=${NV}
172
NV=`echo ${NV} | cut -f 1 -d _ | cut -f 1 -d ,`
173
174
if [ ! "$(pkg version -t ${NV} 440.59)" == "<" ]
175
then
176
terminate 0 "nvidia-driver 440.59+ already includes 32-bit drivers: nothing to do"
177
fi
178
179
if [ ! -f NVIDIA-FreeBSD-x86-${NV}.tar.gz ] || !(tar -tf NVIDIA-FreeBSD-x86-${NV}.tar.gz > /dev/null 2>&1)
180
then
181
[ -n "$NO_FETCH" ] \
182
&& terminate 8 "NVIDIA-FreeBSD-x86-${NV}.tar.gz unavailable"
183
echo "=> Downloading NVIDIA-FreeBSD-x86-${NV}.tar.gz from https://download.nvidia.com..."
184
rm -f NVIDIA-FreeBSD-x86-${NV}.tar.gz
185
fetch -aRr https://download.nvidia.com/XFree86/FreeBSD-x86/${NV}/NVIDIA-FreeBSD-x86-${NV}.tar.gz \
186
|| terminate 2 "Failed to download NVIDIA-FreeBSD-x86-${NV}.tar.gz"
187
echo "=> Downloaded NVIDIA-FreeBSD-x86-${NV}.tar.gz"
188
echo "Please check the following information against /usr/ports/x11/nvidia-driver/distinfo"
189
sha256 NVIDIA-FreeBSD-x86-${NV}.tar.gz
190
echo "SIZE (NVIDIA-FreeBSD-x86-${NV}.tar.gz) = `stat -f "%z" NVIDIA-FreeBSD-x86-${NV}.tar.gz`"
191
fi
192
193
echo "=> Extracting NVIDIA-FreeBSD-x86-${NV}.tar.gz to $PREFIX/lib32..."
194
EXTRACT_LIST="libGL.so.1"
195
case $NV in
196
195*|173*|96*|71*)
197
EXTRACT_LIST="$EXTRACT_LIST libGLcore.so.1 libnvidia-tls.so.1"
198
;;
199
*)
200
EXTRACT_LIST="$EXTRACT_LIST libnvidia-glcore.so.1 libnvidia-tls.so.1"
201
;;
202
esac
203
204
EXTRACT_ARGS="--no-same-owner --no-same-permissions --strip-components 2 -C $PREFIX/lib32"
205
for i in $EXTRACT_LIST
206
do
207
EXTRACT_ARGS="$EXTRACT_ARGS --include NVIDIA-FreeBSD-x86-${NV}/obj/$i"
208
done
209
umask 0333
210
tar $EXTRACT_ARGS -xvf NVIDIA-FreeBSD-x86-${NV}.tar.gz \
211
|| terminate 3 "Failed to extract NVIDIA-FreeBSD-x86-${NV}.tar.gz"
212
mkdir -m 0755 -p ${PREFIX}/lib32/.nvidia \
213
|| terminate 9 "Failed to create .nvidia shadow directory"
214
mv ${PREFIX}/lib32/libGL.so.1 ${PREFIX}/lib32/.nvidia/ \
215
|| terminate 10 "Failed to move libGL.so.1 to .nvidia/ shadow directory"
216
ln -s .nvidia/libGL.so.1 ${PREFIX}/lib32/libGL.so.1 \
217
|| terminate 11 "Failed to link to .nvidia/libGL.so.1 in the shadow directory"
218
219
echo "=> Cleaning up..."
220
[ -n "$NO_REMOVE_NVIDIA" ] || rm -vf NVIDIA-FreeBSD-x86-${NV}.tar.gz \
221
|| terminate 6 "Failed to remove files"
222
223
echo "===> i386-wine-${WINE} successfully patched for nvidia-driver-${NVIDIA}"
224
225