Changeset 3494 for pykota/branches/1.26_fixes/bin
- Timestamp:
- 02/22/09 16:08:09 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/branches/1.26_fixes/bin/pksetup
r3412 r3494 16 16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 17 # GNU General Public License for more details. 18 # 18 # 19 19 # You should have received a copy of the GNU General Public License 20 20 # along with this program; if not, write to the Free Software … … 63 63 # IMPORTANT : many more directives can be used, and some of the directives 64 64 # below accept different and/or more complex parameters. Please read 65 # /usr/share/pykota/conf/pykota.conf.sample for more details about the 65 # /usr/share/pykota/conf/pykota.conf.sample for more details about the 66 66 # numerous possibilities allowed. 67 67 # … … 116 116 onaccountererror : stop 117 117 118 # Who will receive warning messages ? 118 # Who will receive warning messages ? 119 119 # both means admin and user. 120 120 mailto : both … … 130 130 poorman : 1.0 131 131 132 # Warning messages to use 133 poorwarn : Your Print Quota account balance is low. 132 # Warning messages to use 133 poorwarn : Your Print Quota account balance is low. 134 134 Soon you'll not be allowed to print anymore. 135 135 136 136 softwarn : Your Print Quota Soft Limit is reached. 137 137 This means that you may still be allowed to print for some 138 time, but you must contact your administrator to purchase 138 time, but you must contact your administrator to purchase 139 139 more print quota. 140 140 … … 144 144 as soon as possible to solve the problem. 145 145 146 # Number of banners allowed to be printed by users 146 # Number of banners allowed to be printed by users 147 147 # who are over quota 148 148 maxdenybanners : 0 … … 175 175 cupsrestart = "/etc/init.d/cupsys restart" # overload it if needed 176 176 adduser = "adduser --system --group --home /etc/pykota --gecos PyKota pykota" # overload it if needed 177 packages = [ "wget", 178 "bzip2", 179 "subversion", 180 "postgresql", 177 packages = [ "wget", 178 "bzip2", 179 "subversion", 180 "postgresql", 181 181 "postgresql-client", 182 182 "pkpgcounter", … … 195 195 "python-chardet", 196 196 "python-pam" ] 197 197 198 198 otherpackages = [ { "name" : "pkipplib", 199 199 "version" : "0.07", … … 204 204 ], 205 205 }, 206 { "name" : "ghostpcl", 207 "version" : "1.41p1", 208 "url" : "ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/GhostPCL/%(name)s_%(version)s.tar.bz2", 209 "commands" : [ "bunzip2 <%(name)s_%(version)s.tar.bz2 | tar -xf -", 210 "cd %(name)s_%(version)s", 206 { "name" : "ghostpdl", 207 "version" : "1.54", 208 "url" : "http://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/%(name)s/%(name)s-%(version)s.tar.bz2", 209 "commands" : [ "bunzip2 <%(name)s-%(version)s.tar.bz2 | tar -xf -", 210 "cd %(name)s-%(version)s", 211 "wget http://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/GhostPCL/urwfonts-1.41.tar.bz2", 212 "bunzip2 <urwfonts-1.41.tar.bz2 | tar -xf -", 213 "mv urwfonts-1.41 urwfonts", 211 214 "make fonts", 212 "make p roduct",215 "make pcl", 213 216 "make install", 214 217 ], 215 218 }, 216 ] 217 218 def __init__(self) : 219 ] 220 221 def __init__(self) : 219 222 """Initializes instance specific datas.""" 220 223 self.launched = [] 221 222 def yesno(self, message) : 224 225 def yesno(self, message) : 223 226 """Asks the end user some question and returns the answer.""" 224 227 try : 225 228 return raw_input("\n%s ? " % message).strip().upper()[0] == 'Y' 226 except IndexError : 229 except IndexError : 227 230 return False 228 229 def confirmCommand(self, message, command, record=True) : 231 232 def confirmCommand(self, message, command, record=True) : 230 233 """Asks for confirmation before a command is launched, and launches it if needed.""" 231 234 if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : … … 236 239 else : 237 240 return False 238 239 def confirmPipe(self, message, command) : 241 242 def confirmPipe(self, message, command) : 240 243 """Asks for confirmation before a command is launched in a pipe, launches it if needed, and returns the result.""" 241 244 if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : … … 246 249 else : 247 250 return False 248 251 249 252 def listPrinters(self) : 250 253 """Returns a list of tuples (queuename, deviceuri) for all existing print queues.""" … … 258 261 queuename = begin.split()[-1] 259 262 printers.append((queuename, deviceuri)) 260 return printers 261 262 def downloadOtherPackages(self) : 263 return printers 264 265 def downloadOtherPackages(self) : 263 266 """Downloads and install additional packages from http://www.pykota.com or other websites""" 264 267 olddirectory = os.getcwd() … … 273 276 if url.startswith("svn://") : 274 277 download = 'svn export "%(url)s" %(name)s' % locals() 275 else : 278 else : 276 279 download = 'wget "%(url)s"' % locals() 277 280 if self.confirmCommand("to download %(name)s" % locals(), download) : 278 281 self.confirmCommand("to install %(name)s" % locals(), commands) 279 self.confirmCommand("to remove the temporary directory %(directory)s" % locals(), 282 self.confirmCommand("to remove the temporary directory %(directory)s" % locals(), 280 283 "rm -fr %(directory)s" % locals(), 281 284 record=False) 282 os.chdir(olddirectory) 283 285 os.chdir(olddirectory) 286 284 287 def waitPrintersOnline(self) : 285 288 """Asks the admin to switch all printers ON.""" 286 289 while not self.yesno("First you MUST switch ALL your printers ON. Are ALL your printers ON") : 287 290 pass 288 291 289 292 def setupDatabase(self) : 290 293 """Creates the database.""" 291 294 pykotadirectory = self.pykotadirectory 292 295 self.confirmCommand("to create PyKota's database in PostgreSQL", 'su - postgres -c "psql -f %(pykotadirectory)s/postgresql/pykota-postgresql.sql template1"' % locals()) 293 296 294 297 def configurePostgreSQL(self) : 295 298 """Configures PostgreSQL for PyKota to work.""" … … 306 309 if answer is not False : 307 310 tcpip = answer.strip().lower().endswith("true") 308 else : 311 else : 309 312 tcpip = False 310 if tcpip : 313 if tcpip : 311 314 conflines.insert(2, "host\tpykota\tpykotaadmin,pykotauser\t127.0.0.1\t255.255.255.255\tmd5") 312 315 else : … … 316 319 self.confirmCommand("to make PostgreSQL take the changes into account", self.pgrestart) 317 320 return tcpip 318 return None 319 320 def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip) : 321 return None 322 323 def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip) : 321 324 """Generates minimal configuration files for PyKota.""" 322 325 if tcpip : 323 326 storageserver = "localhost" 324 else : 327 else : 325 328 storageserver = "" 326 329 conf = pykotaconf % locals() … … 340 343 if begin is None : 341 344 begin = i 342 else : 345 else : 343 346 end = i 344 347 345 348 if (begin is not None) and (end is not None) : 346 349 suffix = "\n".join(lines[begin+1:end]) 347 350 self.confirmCommand("to improve PyKota's configuration wrt your existing printers", 'echo "%(suffix)s" >>%(home)s/pykota.conf' % locals()) 348 351 349 352 def addPyKotaUser(self) : 350 353 """Adds a system user named pykota, returns its home directory or None""" 351 354 try : 352 355 user = pwd.getpwnam("pykota") 353 except KeyError : 356 except KeyError : 354 357 if self.confirmCommand("to create a system user named 'pykota'", self.adduser) : 355 try : 358 try : 356 359 return pwd.getpwnam("pykota")[5] 357 except KeyError : 360 except KeyError : 358 361 return None 359 else : 362 else : 360 363 return None 361 else : 364 else : 362 365 return user[5] 363 366 364 367 def setupBackend(self) : 365 368 """Installs the cupspykota backend.""" … … 369 372 self.confirmCommand("to make PyKota known to CUPS", "ln -s %(realbackend)s %(backend)s" % locals()) 370 373 self.confirmCommand("to restart CUPS for the changes to take effect", self.cupsrestart) 371 372 def managePrinters(self, printers) : 374 375 def managePrinters(self, printers) : 373 376 """For each printer, asks if it should be managed with PyKota or not.""" 374 377 for (queuename, deviceuri) in printers : 375 378 command = 'pkprinters --add --cups --description "Printer created with pksetup" "%(queuename)s"' % locals() 376 379 self.confirmCommand("to import the %(queuename)s print queue into PyKota's database and reroute it through PyKota" % locals(), command) 377 380 378 381 def installPyKotaFiles(self) : 379 382 """Installs PyKota files through Python's Distutils mechanism.""" … … 383 386 if os.path.exists(setuppy) : 384 387 self.confirmCommand("to install PyKota files on your system", "python %(setuppy)s install" % locals()) 385 388 386 389 def setup(self) : 387 390 """Installation procedure.""" … … 395 398 if homedirectory is None : 396 399 sys.stderr.write("Installation can't proceed. You MUST create a system user named 'pykota'.\n") 397 else : 400 else : 398 401 self.upgradeSystem() 399 402 self.setupPackages() … … 406 409 print nowready 407 410 print "The script %s can be used to reinstall in unattended mode.\n" % self.genInstaller() 408 409 def genInstaller(self) : 411 412 def genInstaller(self) : 410 413 """Generates an installer script.""" 411 414 scriptname = "/tmp/pykota-installer.sh" 412 commands = [ "#! /bin/sh", 415 commands = [ "#! /bin/sh", 413 416 "#", 414 "# PyKota installer script.", 415 "#", 417 "# PyKota installer script.", 418 "#", 416 419 "# This script was automatically generated.", 417 420 "#", 418 421 ] + self.launched 419 script = open(scriptname, "w") 422 script = open(scriptname, "w") 420 423 script.write("\n".join(commands)) 421 424 script.close() 422 425 os.chmod(scriptname, \ 423 426 stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) 424 return scriptname 425 426 427 class Debian(PyKotaSetup) : 427 return scriptname 428 429 430 class Debian(PyKotaSetup) : 428 431 """Class for Debian installer.""" 429 def setupPackages(self) : 432 def setupPackages(self) : 430 433 """Installs missing Debian packages.""" 431 434 self.confirmCommand("to install missing dependencies", "apt-get install %s" % " ".join(self.packages)) 432 435 433 436 def upgradeSystem(self) : 434 437 """Upgrades the Debian setup.""" 435 438 if self.confirmCommand("to grab an up-to-date list of available packages", "apt-get update") : 436 439 self.confirmCommand("to put your system up-to-date", "apt-get -y dist-upgrade") 437 438 class Ubuntu(Debian) : 440 441 class Ubuntu(Debian) : 439 442 """Class for Ubuntu installer.""" 440 443 pass 441 442 if __name__ == "__main__" : 444 445 if __name__ == "__main__" : 443 446 retcode = 0 444 447 if (len(sys.argv) != 2) or (sys.argv[1] == "-h") or (sys.argv[1] == "--help") : 445 448 print "pksetup v0.1 (c) 2003-2007 Jerome Alet - alet@librelogiciel.com\n\nusage : pksetup distribution\n\ne.g. : pksetup debian\n\nIMPORTANT : only Debian and Ubuntu are currently supported." 446 elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") : 449 elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") : 447 450 print "0.1" # pksetup's own version number 448 else : 451 else : 449 452 classname = sys.argv[1].strip().title() 450 453 try : 451 454 installer = globals()[classname]() 452 except KeyError : 455 except KeyError : 453 456 sys.stderr.write("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1]) 454 457 retcode = -1 455 else : 458 else : 456 459 try : 457 460 retcode = installer.setup() 458 except KeyboardInterrupt : 461 except KeyboardInterrupt : 459 462 sys.stderr.write("\n\n\nWARNING : Setup was aborted at user's request !\n\n") 460 463 retcode = -1