3
# Copyright (C) 2004 Federico Di Gregorio <fog@debian.org>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by the
7
# Free Software Foundation; either version 2, or (at your option) any later
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26
CG_LIBRARIES = ('libCg.so', 'libCgFX.so', 'libCgGL.so', 'libCgFXGL.so')
27
CG_PDFS = ('CgManualAddendum.pdf', 'CgReleaseNotes.pdf', 'Cg_Toolkit.pdf',
30
pipe = os.popen('dpkg --print-architecture', 'r')
31
arch = pipe.read().strip()
35
CG_URL = 'ftp://download.nvidia.com/developer/cg/Cg_1.3/Linux/'
36
CG_FILE = 'Cg-1.3.0501-0700.i386.tar.gz'
37
CG_MD5 = 'c122d853eca52e9863832480dc3ab843'
38
CG_USR_LIB = '/usr/lib'
40
CG_URL = 'ftp://download.nvidia.com/developer/cg/Cg_1.3/Linux64/'
41
CG_FILE = 'Cg-1.3.0501-0700.x86_64.tar.gz'
42
CG_MD5 = 'a9b4cb044e5975783e34edfcb82d5d71'
43
CG_USR_LIB = '/usr/lib64'
45
sys.stderr.write("Error: architecture %s is not supported\n" % arch)
49
"""Uninstall all components."""
50
print "Uninstalling NVIDIA Cg Toolkit components:"
52
print " Cg compiler,",
54
os.unlink('/usr/bin/cgc')
58
print "header files,",
59
shutil.rmtree('/usr/include/Cg', ignore_errors=True)
60
shutil.rmtree('/usr/include/CgFX', ignore_errors=True)
63
for l in CG_LIBRARIES:
65
os.unlink(os.path.join(CG_USR_LIB, l))
69
print "documentation,"
72
os.unlink(os.path.join('/usr/share/doc/nvidia-cg-toolkit', l))
76
shutil.rmtree('/usr/share/doc/nvidia-cg-toolkit/html', ignore_errors=True)
77
shutil.rmtree('/usr/share/doc/nvidia-cg-toolkit/txt', ignore_errors=True)
80
shutil.rmtree('/usr/share/doc/nvidia-cg-toolkit/examples',
83
print "manual pages,",
84
for f in glob.glob('/usr/share/man/man3/*.3nvidiacg.gz'):
92
def cg_install(filename):
93
"""Install from give file."""
94
print "Checking md5 checksum on " + filename
95
md5sum = md5.new(open(filename).read()).hexdigest()
97
e = "Error: md5sum mismatch: %s != %s"
98
sys.stderr.write(e % (CG_MD5, md5sum))
101
target = os.path.join('/tmp', 'cg.%f' % time.time())
105
e = "Error: can't create directory: %s."
106
sys.stderr.write(e % target)
111
print "Uncompressing NVIDIA Cg toolkit into " + target
112
os.system("/bin/tar xzf %s -C %s" % (filename, target))
114
print "Moving files to their final destinations:"
116
print " cg compiler,",
117
shutil.move(os.path.join(target, 'usr/bin/cgc'), '/usr/bin/cgc')
119
print "header files,",
120
shutil.move(os.path.join(target, 'usr/include/Cg'), '/usr/include/Cg')
121
shutil.move(os.path.join(target, 'usr/include/CgFX'), '/usr/include/CgFX')
124
for l in CG_LIBRARIES:
125
shutil.move(os.path.join(target, 'usr/lib', l),
126
os.path.join(CG_USR_LIB, l))
128
print "documentation,"
130
shutil.move(os.path.join(target, 'usr/local/Cg/docs', l),
131
os.path.join('/usr/share/doc/nvidia-cg-toolkit', l))
132
shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/html'),
133
'/usr/share/doc/nvidia-cg-toolkit/html')
134
shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/cgGL/html'),
135
'/usr/share/doc/nvidia-cg-toolkit/html/cgGL')
136
shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/txt'),
137
'/usr/share/doc/nvidia-cg-toolkit/txt')
138
shutil.move(os.path.join(target, 'usr/local/Cg/docs/runtime/cgGL/txt'),
139
'/usr/share/doc/nvidia-cg-toolkit/txt/cgGL')
142
shutil.move(os.path.join(target, 'usr/local/Cg/examples'),
143
'/usr/share/doc/nvidia-cg-toolkit/examples')
145
print "manual pages",
146
for f in os.listdir(os.path.join(target, 'usr/share/man/man3')):
147
src = os.path.join(target, 'usr/share/man/man3', f)
148
dst = os.path.join('/usr/share/man/man3', f+'nvidiacg')
149
shutil.move(src, dst)
151
print "(compressing),",
152
os.system('/bin/gzip -9 /usr/share/man/man3/*.3nvidiacg')
154
shutil.rmtree(target)
158
"""Get toolkit archive from the network."""
159
target = os.path.join('/tmp', 'cg.%f' % time.time())
163
e = "Error: can't create directory: %s."
164
sys.stderr.write(e % target)
166
dst = open(os.path.join(target, CG_FILE), 'w')
168
print "Downloading NVIDIA Cg Toolkit to " + dst.name
169
src = urllib2.urlopen(CG_URL+CG_FILE)
170
dst.write(src.read())
173
def cg_path(path, filename):
174
"""Return the path to an existing file or None."""
175
if filename and os.path.exists(filename):
178
filename = os.path.join(path, CG_FILE)
179
if filename and os.path.exists(filename):
183
parser = optparse.OptionParser(usage="%prog [options] <file or URL>")
184
parser.add_option('-i', '--install', action='store_true',
185
help="install the NVIDIA Cg Toolkit")
186
parser.add_option('-u', '--uninstall', action='store_true',
187
help="uninstall the NVIDIA Cg Toolkit")
188
parser.add_option('-l', '--local-file', action='store',
189
help="install from given file")
190
parser.add_option('-s', '--search-path', action='store',
191
help="search for files in given path")
192
parser.add_option('-d', '--delete-after', action='store_true',
193
help="remove toolkit archive after install")
194
opts, args = parser.parse_args()
198
local_file = cg_path(opts.search_path, opts.local_file)
199
if not local_file or not os.path.exists(local_file):
200
local_file = cg_wget()
201
cg_install(local_file)
202
if opts.delete_after:
203
os.unlink(local_file)
209
e = "Error: one action (--install or --uninstall) is required.\n"