#!/usr/bin/env python # # Makes a kforged installation from Apache, mod_python, and KForge sources. import os, os.path httpName = 'httpd-2.0.55' modPythonName = 'mod_python-3.1.4' kforgeName = 'kforge-0.91' kforgedProgramName = 'kforged' kforgedPort = '80' if os.environ['USER'] == 'root': raise "Running as 'root' is not allowed." kforgeUserName = os.environ['USER'] targetPath = '/home/%s/kforged' % kforgeUserName #targatPath ='/usr/share/kforge' os.environ['KFORGEHOME'] = targetPath os.environ['PYTHONPATH'] = targetPath + '/lib/python' if os.system('python -c "import django"'): raise "KForged dependency error: Django web framework not found. KForge web user interface is implemented with Djano. Djano is required to make a KForged installation." def makeKforgedInstallation(): assertTargetEmpty() enterSdkSource() makeApacheModPythonInstallation() makeKforgeInstallation() leaveDir() configureKforgedInstallation() print "OK" def makeApacheModPythonInstallation(): extractHttpdSource() enterHttpdSource() configureHttpdSource() make() makeInstall() leaveDir() removeHttpdSource() extractModPythonSource() enterModPythonSource() configureModPythonSource() make() makeInstallDso() leaveDir() removeModPythonSource() def makeKforgeInstallation(): extractKforgeSource() enterKforgeSource() installKforge() leaveDir() removeKforgeSource() def assertTargetEmpty(): print "Checking target path '%s' does not exist" % targetPath if os.path.exists(targetPath): raise Exception("Target exists: %s" % targetPath) def enterSdkSource(): print "Entering src..." if os.chdir('src'): raise Exception("") def extractHttpdSource(): print "Extracting httpd '%s' src..." % httpName if os.system('tar zxvf %s.tar.gz' % httpName): raise Exception("") def enterHttpdSource(): print "Entering httpd src dirs..." if os.chdir(httpName): raise Exception("") def configureHttpdSource(): print "Configuring httpd src..." if os.system('./configure --prefix=%s/apache --enable-dav --enable-dav-fs --enable-ssl --with-program-name=%s --with-port=%s' % (targetPath, kforgedProgramName, kforgedPort)): raise Exception("") def removeHttpdSource(): print "Removing httpd src dirs..." if os.system('rm -rf %s' % httpName): raise Exception("") def extractModPythonSource(): print "Extracting modPython '%s' src..." % modPythonName if os.system('tar zxvf %s.tgz' % modPythonName): raise Exception("") def enterModPythonSource(): print "Entering modPython src dirs..." if os.chdir(modPythonName): raise Exception("") def configureModPythonSource(): print "Configuring modPython src..." if os.system('./configure --with-apxs=%s/apache/bin/apxs' % targetPath): raise Exception("") def removeModPythonSource(): print "Removing modPython src dirs..." if os.system('rm -rf %s' % modPythonName): raise Exception("") def extractKforgeSource(): print "Extracting kforge '%s' src..." % kforgeName if os.system('tar zxvf %s.tar.gz' % kforgeName): raise Exception("") def enterKforgeSource(): print "Entering kforge src dirs..." if os.chdir(kforgeName): raise Exception("") def installKforge(): print "Configuring kforge src..." if os.system('python setup.py install --home=%s' % targetPath): raise Exception("") def removeKforgeSource(): print "Removing kforge src dirs..." if os.system('rm -rf %s' % kforgeName): raise Exception("") def make(): print "Running make..." if os.system('make'): raise Exception("") def makeInstall(): print "Running make install..." if os.system('make install'): raise Exception("") def makeInstallDso(): print "Running make install_dso..." if os.system('make install_dso'): raise Exception("") def leaveDir(): print "Leaving dir..." if os.chdir('..'): raise Exception("") def configureKforgedInstallation(): #print "Creating kforge log dir..." #os.system('mkdir %s/var/log' % targetPath) #print "Creating kforge apache log dir..." #os.system('mkdir %s/apache/logs' % targetPath) #print "Creating kforge var/www/media dir..." #os.system('mkdir %s/var/www/media' % targetPath) print "Creating database..." cmd = '%s/bin/kforge-db create' % targetPath print cmd if os.system(cmd): raise Exception("") print "Rebuilding included KForge Apache configuration ..." cmd = '%s/bin/kforge-config-rebuild' % targetPath print cmd if os.system(cmd): raise Exception("") print "Appending Include directive to 'apache' conf..." apacheConfigFilePath = '%s/apache/conf/%s.conf' % (targetPath, kforgedProgramName) cmd = 'cat kforged-httpd.conf >> %s' % apacheConfigFilePath print cmd if os.system(cmd): raise Exception("") userName = kforgeUserName varPath = '%s/var' % targetPath print "Changing file ownership to '%s'..." % userName cmd = 'chown -R %s:%s %s' % (userName, userName, varPath) print cmd if os.system(cmd): raise Exception("") varPath = '%s/apache/log' % targetPath print "Changing file ownership to '%s'..." % userName cmd = 'chown -R %s:%s %s' % (userName, userName, varPath) print cmd print "...skipped!" # os.system(cmd) print "Starting kforged..." apachectlPath = '%s/apache/bin/apachectl' % targetPath cmd = 'su -c "%s start"' % apachectlPath print cmd if os.system(cmd): raise Exception("") if __name__ == '__main__': makeKforgedInstallation() print "" # todo: ... print "Unimplemented concerns:" print "" print " The following concerns are not supported in this version." print "" print " - Check the Apache User and Group" print " It is important to make sure that Apache has write access" print " to log files, and read access to other things. The easiest" print " way to do this is to set the permissions for these files." print " But you may wish to create a kforge user and run with that." print "" print " - Check the Apache Port" print " It is important to make sure that Apache listens to a free" print " port. It is also possible to run a reverse-proxy kforged." print " To create a reverse-proxy kforged, run kforged on a higher" print " port than normal, and configure the front server to proxy" print " requests to kforged." print "" print " - Check the Apache certificate (value set in etc/kforge.conf)" print " Apache is build with ssl enabled. A certificate is required." print " You can build a certificate with apache2-ssl-certificate." print "" print " - Check the service_name (value set in etc/kforge.conf)" print " You will want to provide a name for your new service." print "" print " - Check the domain_name (value set in etc/kforge.conf)" print " You will want to serve your service within your own domain." print "" print " - Check admin.domain_name and project.domain_name are domain names resolve" print " We need to resolve a domain_name to a host IP address." print " Add a line in /etc/hosts for a local setup, otherwise in your DNS." print "" print " - Check the database user authorisation configuration" print " E.g. For Postgres you will want to add:" print "" print " host DB_NAME DB_USER 127.0.0.1 255.255.255.255 password" print " host template1 DB_USER 127.0.0.1 255.255.255.255 password" print "" print " to the top of:" print "" print " /etc/postgresql/pg_hba.conf" print "" print " Afterwards, you may need to run:" print "" print " $ $KFORGEHOME/bin/kforge-db rebuild" print "" print " - Check the database user account exists" print " E.g. For postgres, you will want to run:" print "" print " $ $KFORGEHOME/bin/kforge-dbuser-create DB_USER" print "" print " - Command line utilities require these shell commands:" print " export KFORGEHOME=~/kforged" print " export PATH=$PATH:$KFORGEHOME/bin" print " export PYTHONPATH=$KFORGEHOME/lib/python" print " export DJANGO_SETTINGS_MODULE=kforge.django.settings.main" print "" print " You can write them into your ~/.bashrc file." print "" print " - You need a copy of mod_dav_svn.so:" print " cp /usr/lib/apache2/modules/mod_dav_svn.so $KFORGEHOME/apache/modules/" print "" print " The location of 'mod_dav_svn.so' may vary. However," print " the package name on Debian Sarge is 'libapache2-svn'." print "" print "" print " - (Developers only:) Symlink to development dirs" print " Link to kforge lib, and kui templates." print "" print " NB: PLEASE SCROLL BACK UP AND CHECK THE LIST OF UNIMPLEMENTED ISSUES" print ""