Changeset 3413 for pykota/trunk/bin/pksetup
- Timestamp:
- 09/27/08 22:02:37 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/pksetup
r3411 r3413 9 9 # the Free Software Foundation, either version 3 of the License, or 10 10 # (at your option) any later version. 11 # 11 # 12 12 # This program is distributed in the hope that it will be useful, 13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 # GNU General Public License for more details. 16 # 16 # 17 17 # You should have received a copy of the GNU General Public License 18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 60 60 # IMPORTANT : many more directives can be used, and some of the directives 61 61 # below accept different and/or more complex parameters. Please read 62 # /usr/share/pykota/conf/pykota.conf.sample for more details about the 62 # /usr/share/pykota/conf/pykota.conf.sample for more details about the 63 63 # numerous possibilities allowed. 64 64 # … … 122 122 onaccountererror : stop 123 123 124 # Who will receive warning messages ? 124 # Who will receive warning messages ? 125 125 # both means admin and user. 126 126 mailto : both … … 136 136 poorman : 1.0 137 137 138 # Warning messages to use 139 poorwarn : Your Print Quota account balance is low. 138 # Warning messages to use 139 poorwarn : Your Print Quota account balance is low. 140 140 Soon you'll not be allowed to print anymore. 141 141 142 142 softwarn : Your Print Quota Soft Limit is reached. 143 143 This means that you may still be allowed to print for some 144 time, but you must contact your administrator to purchase 144 time, but you must contact your administrator to purchase 145 145 more print quota. 146 146 … … 150 150 as soon as possible to solve the problem. 151 151 152 # Number of banners allowed to be printed by users 152 # Number of banners allowed to be printed by users 153 153 # who are over quota 154 154 maxdenybanners : 0 … … 181 181 cupsrestart = "/etc/init.d/cupsys restart" # overload it if needed 182 182 adduser = "adduser --system --group --home /etc/pykota --gecos PyKota pykota" # overload it if needed 183 packages = [ "wget", 184 "bzip2", 185 "subversion", 186 "postgresql", 183 packages = [ "wget", 184 "bzip2", 185 "subversion", 186 "postgresql", 187 187 "postgresql-client", 188 188 "cupsys", … … 200 200 "python-pam", 201 201 "pkpgcounter" ] 202 202 203 203 otherpackages = [ 204 204 { "name" : "pkipplib", … … 219 219 ], 220 220 }, 221 ] 222 223 def __init__(self) : 221 ] 222 223 def __init__(self) : 224 224 """Initializes instance specific datas.""" 225 225 self.launched = [] 226 227 def yesno(self, message) : 226 227 def yesno(self, message) : 228 228 """Asks the end user some question and returns the answer.""" 229 229 try : 230 230 return raw_input("\n%s ? " % message).strip().upper()[0] == 'Y' 231 except IndexError : 231 except IndexError : 232 232 return False 233 234 def confirmCommand(self, message, command, record=True) : 233 234 def confirmCommand(self, message, command, record=True) : 235 235 """Asks for confirmation before a command is launched, and launches it if needed.""" 236 236 if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : … … 241 241 else : 242 242 return False 243 244 def confirmPipe(self, message, command) : 243 244 def confirmPipe(self, message, command) : 245 245 """Asks for confirmation before a command is launched in a pipe, launches it if needed, and returns the result.""" 246 246 if self.yesno("The following command will be launched %(message)s :\n%(command)s\nDo you agree" % locals()) : … … 251 251 else : 252 252 return False 253 253 254 254 def listPrinters(self) : 255 255 """Returns a list of tuples (queuename, deviceuri) for all existing print queues.""" … … 263 263 queuename = begin.split()[-1] 264 264 printers.append((queuename, deviceuri)) 265 return printers 266 267 def downloadOtherPackages(self) : 265 return printers 266 267 def downloadOtherPackages(self) : 268 268 """Downloads and install additional packages from http://www.pykota.com or other websites""" 269 269 olddirectory = os.getcwd() … … 278 278 if url.startswith("svn://") : 279 279 download = 'svn export "%(url)s" %(name)s' % locals() 280 else : 280 else : 281 281 download = 'wget --user-agent=pksetup "%(url)s"' % locals() 282 282 if self.confirmCommand("to download %(name)s" % locals(), download) : 283 283 self.confirmCommand("to install %(name)s" % locals(), commands) 284 self.confirmCommand("to remove the temporary directory %(directory)s" % locals(), 284 self.confirmCommand("to remove the temporary directory %(directory)s" % locals(), 285 285 "rm -fr %(directory)s" % locals(), 286 286 record=False) 287 os.chdir(olddirectory) 288 287 os.chdir(olddirectory) 288 289 289 def waitPrintersOnline(self) : 290 290 """Asks the admin to switch all printers ON.""" 291 291 while not self.yesno("First you MUST switch ALL your printers ON. Are ALL your printers ON") : 292 292 pass 293 293 294 294 def setupDatabase(self) : 295 295 """Creates the database.""" 296 296 pykotadirectory = self.pykotadirectory 297 297 self.confirmCommand("to create PyKota's database in PostgreSQL", 'su - postgres -c "psql -f %(pykotadirectory)s/postgresql/pykota-postgresql.sql template1"' % locals()) 298 298 299 299 def configurePostgreSQL(self) : 300 300 """Configures PostgreSQL for PyKota to work.""" … … 314 314 if tcpip is False : 315 315 tcpip = answer.startswith("listen_addresses") 316 else : 316 else : 317 317 tcpip = False 318 if tcpip : 318 if tcpip : 319 319 conflines.insert(2, "host\tpykota\tpykotaadmin,pykotauser\t127.0.0.1\t255.255.255.255\tmd5") 320 320 else : … … 333 333 return (tcpip, port) 334 334 return (None, None) 335 335 336 336 def genConfig(self, adminname, adminemail, dnsdomain, smtpserver, home, tcpip, port) : 337 337 """Generates minimal configuration files for PyKota.""" 338 338 if tcpip : 339 339 storageserver = "localhost:%i" % port 340 else : 340 else : 341 341 storageserver = "" 342 342 conf = pykotaconf % locals() … … 356 356 if begin is None : 357 357 begin = i 358 else : 358 else : 359 359 end = i 360 360 361 361 if (begin is not None) and (end is not None) : 362 362 suffix = "\n".join(lines[begin+1:end]) 363 363 self.confirmCommand("to improve PyKota's configuration wrt your existing printers", 'echo "%(suffix)s" >>%(home)s/pykota.conf' % locals()) 364 364 365 365 def addPyKotaUser(self) : 366 366 """Adds a system user named pykota, returns its home directory or None""" 367 367 try : 368 368 user = pwd.getpwnam("pykota") 369 except KeyError : 369 except KeyError : 370 370 if self.confirmCommand("to create a system user named 'pykota'", self.adduser) : 371 try : 371 try : 372 372 return pwd.getpwnam("pykota")[5] 373 except KeyError : 373 except KeyError : 374 374 return None 375 else : 375 else : 376 376 return None 377 else : 377 else : 378 378 return user[5] 379 379 380 380 def setupBackend(self) : 381 381 """Installs the cupspykota backend.""" … … 385 385 self.confirmCommand("to make PyKota known to CUPS", "ln -s %(realbackend)s %(backend)s" % locals()) 386 386 self.confirmCommand("to restart CUPS for the changes to take effect", self.cupsrestart) 387 388 def managePrinters(self, printers) : 387 388 def managePrinters(self, printers) : 389 389 """For each printer, asks if it should be managed with PyKota or not.""" 390 390 for (queuename, deviceuri) in printers : 391 391 command = 'pkprinters --add --cups --description "Printer created with pksetup" "%(queuename)s"' % locals() 392 392 self.confirmCommand("to import the %(queuename)s print queue into PyKota's database and reroute it through PyKota" % locals(), command) 393 393 394 394 def installPyKotaFiles(self) : 395 395 """Installs PyKota files through Python's Distutils mechanism.""" … … 399 399 if os.path.exists(setuppy) : 400 400 self.confirmCommand("to install PyKota files on your system", "python %(setuppy)s install" % locals()) 401 401 402 402 def setup(self) : 403 403 """Installation procedure.""" … … 411 411 if homedirectory is None : 412 412 logerr("Installation can't proceed. You MUST create a system user named 'pykota'.\n") 413 else : 413 else : 414 414 self.upgradeSystem() 415 415 self.setupPackages() … … 422 422 print nowready 423 423 print "The script %s can be used to reinstall in unattended mode.\n" % self.genInstaller() 424 425 def genInstaller(self) : 424 425 def genInstaller(self) : 426 426 """Generates an installer script.""" 427 427 scriptname = "/tmp/pykota-installer.sh" 428 commands = [ "#! /bin/sh", 428 commands = [ "#! /bin/sh", 429 429 "#", 430 "# PyKota installer script.", 431 "#", 430 "# PyKota installer script.", 431 "#", 432 432 "# This script was automatically generated.", 433 433 "#", 434 434 ] + self.launched 435 script = open(scriptname, "w") 435 script = open(scriptname, "w") 436 436 script.write("\n".join(commands)) 437 437 script.close() 438 438 os.chmod(scriptname, \ 439 439 stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) 440 return scriptname 441 442 443 class Debian(PyKotaSetup) : 440 return scriptname 441 442 443 class Debian(PyKotaSetup) : 444 444 """Class for Debian installer.""" 445 def setupPackages(self) : 445 def setupPackages(self) : 446 446 """Installs missing Debian packages.""" 447 447 self.confirmCommand("to install missing dependencies", "apt-get install %s" % " ".join(self.packages)) 448 448 449 449 def upgradeSystem(self) : 450 450 """Upgrades the Debian setup.""" 451 451 if self.confirmCommand("to grab an up-to-date list of available packages", "apt-get update") : 452 452 self.confirmCommand("to put your system up-to-date", "apt-get -y dist-upgrade") 453 454 class Ubuntu(Debian) : 453 454 class Ubuntu(Debian) : 455 455 """Class for Ubuntu installer.""" 456 456 pass 457 458 if __name__ == "__main__" : 457 458 if __name__ == "__main__" : 459 459 retcode = 0 460 460 if (len(sys.argv) != 2) or (sys.argv[1] == "-h") or (sys.argv[1] == "--help") : 461 461 print "pksetup v0.1 (c) 2003-2008 Jerome Alet - alet@librelogiciel.com\n\nusage : pksetup distribution\n\ne.g. : pksetup debian\n\nIMPORTANT : only Debian and Ubuntu are currently supported." 462 elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") : 462 elif (sys.argv[1] == "-v") or (sys.argv[1] == "--version") : 463 463 print "0.1" # pksetup's own version number 464 else : 464 else : 465 465 classname = sys.argv[1].strip().title() 466 466 try : 467 467 installer = globals()[classname]() 468 except KeyError : 468 except KeyError : 469 469 logerr("There's currently no support for the %s distribution, sorry.\n" % sys.argv[1]) 470 470 retcode = -1 471 else : 471 else : 472 472 try : 473 473 retcode = installer.setup() 474 except KeyboardInterrupt : 474 except KeyboardInterrupt : 475 475 logerr("\n\n\nWARNING : Setup was aborted at user's request !\n\n") 476 476 retcode = -1