def configure_pg_hba(): if os.getuid() != 0: raise DistutilsSetupError('You must run this script as root') print "WARNING! This will override your pg_hba.conf - press return only if" print "you want to continue, else press Ctrl+C to exit." raw_input() print print "Configuring Postgres...", sys.stdout.flush() pg_hba = open(PG_HBA_PATH, 'w') pg_hba.write(""" # This file was written by the Molly installer local molly molly md5 host molly molly 127.0.0.1/32 md5 host molly molly ::1/128 md5 # "local" is for Unix domain socket connections only local all all ident # IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 ident """) pg_hba.close() quiet_exec(['/etc/init.d/%s' % POSTGRES_SERVICE, 'restart']) print "DONE!" print print "This has configured Postgres to allow the user 'molly' to connect to" print "the database called 'molly' from localhost only. Please call your" print "database and user molly in the dbcreate function."
def _exec(command, logprefix, wait=True, quiet=True): if wait: if os.name == 'nt': sh_command = ['cmd','/C',command] else: sh_command = ['bash','-c',command] if quiet: quiet_exec(sh_command, logprefix) else: process = Popen(sh_command) process.wait() if process.returncode != 0: raise CommandFailed(command, process.returncode, None, None) else: if quiet: sh_command = ['bash', '-c', '%s >/dev/null' % command] else: sh_command = ['bash', '-c', command] Popen(sh_command)
def create(path, force=False, python=sys.executable): """ Create a virtualenv at the path pointed at by path. If force is True, then anything that's already there will be deleted """ if os.path.exists(path) and force: shutil.rmtree(path) elif os.path.exists(path): raise NotAVirtualenvError() if 'VIRTUALENVWRAPPER_HOOK_DIR' in os.environ: # Use virtualenvwrapper logger.debug('Using virtualenvwrapper to create') command = ['mkvirtualenv','--python=%s' % python,'--distribute','--no-site-packages',path] else: # Use plain old virtualenv logger.debug('Using virtualenv to create') command = ['virtualenv','--python=%s' % python,'--distribute','--no-site-packages',path] quiet_exec(command, 'Create') return Virtualenv(path)
def sysprep(self): # Install EPEL quiet_exec( ["rpm", "-Uvh", "http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm"], "EPEL install", ) # Install RPM Forge rpmforge = tempfile.NamedTemporaryFile() rpm = urllib2.urlopen( "http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm", "RPM Forge install" ) print >> rpmforge, rpm.read() rpm.close() rpmforge.flush() quiet_exec(["rpm", "-Uvh", rpmforge.name]) rpmforge.close() # Now actually install packages super(SysPreparer, self).sysprep()
def postgres_setup(): if os.getuid() != 0: print "Can't start postgres - not root, skipping..." else: print "Starting Postgres...", sys.stdout.flush() quiet_exec(['chkconfig', 'postgresql', 'on'], 'dbprep') quiet_exec(['service', 'postgresql', 'initdb'], 'dbprep') quiet_exec(['service', 'postgresql', 'start'], 'dbprep') print "DONE!"
def postgres_setup(): if os.getuid() != 0: print "Can't start postgres - not root, skipping..." else: print "Starting Postgres...", sys.stdout.flush() quiet_exec(["chkconfig", "postgresql", "on"], "dbprep") quiet_exec(["service", "postgresql", "initdb"], "dbprep") quiet_exec(["service", "postgresql", "start"], "dbprep") print "DONE!"
def _install(self): quiet_exec(['yum', '-y', 'install'] + self.PACKAGES, 'Yum')
def create_postgis_template(username, password): # Setup PostGIS print "Configuring PostGIS...", sys.stdout.flush() creds = [] if username: creds += ['-U', username] if password: os.environ['PGPASSWORD'] = password # Create the template spatial database. quiet_exec(['createdb', '-E', 'UTF8'] + creds + ['template_postgis']) # Adding PLPGSQL language support. quiet_exec(['createlang'] + creds + ['-d', 'template_postgis', 'plpgsql']) # Loading the PostGIS SQL routines quiet_exec(['psql'] + creds + ['-d', 'template_postgis', '-f', POSTGIS_PATH]) quiet_exec(['psql'] + creds + ['-d', 'template_postgis', '-f', SPATIAL_REF_SYS_PATH]) quiet_exec(['psql'] + creds + ['-d', 'postgres', '-c', "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"]) # Enabling users to alter spatial tables. quiet_exec(['psql'] + creds + ['-d', 'template_postgis', '-c', 'GRANT ALL ON geometry_columns TO PUBLIC;']) quiet_exec(['psql'] + creds + ['-d', 'template_postgis', '-c', 'GRANT ALL ON spatial_ref_sys TO PUBLIC;']) if password: del os.environ['PGPASSWORD'] print "DONE!"
def create_postgis_template(username, password): # Setup PostGIS print "Configuring PostGIS...", sys.stdout.flush() creds = [] if username: creds += ["-U", username] if password: os.environ["PGPASSWORD"] = password # Create the template spatial database. quiet_exec(["createdb", "-E", "UTF8"] + creds + ["template_postgis"]) # Adding PLPGSQL language support. quiet_exec(["createlang"] + creds + ["-d", "template_postgis", "plpgsql"]) # Loading the PostGIS SQL routines quiet_exec(["psql"] + creds + ["-d", "template_postgis", "-f", POSTGIS_PATH]) quiet_exec(["psql"] + creds + ["-d", "template_postgis", "-f", SPATIAL_REF_SYS_PATH]) quiet_exec( ["psql"] + creds + ["-d", "postgres", "-c", "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"] ) # Enabling users to alter spatial tables. quiet_exec(["psql"] + creds + ["-d", "template_postgis", "-c", "GRANT ALL ON geometry_columns TO PUBLIC;"]) quiet_exec(["psql"] + creds + ["-d", "template_postgis", "-c", "GRANT ALL ON spatial_ref_sys TO PUBLIC;"]) if password: del os.environ["PGPASSWORD"] print "DONE!"
def _install(self): quiet_exec(["yum", "-y", "install"] + self.PACKAGES, "Yum")
def create(dba_user, dba_pass, username, password, database): creds = [] if dba_user: creds += ['-U', dba_user] if dba_pass: os.environ['PGPASSWORD'] = dba_pass try: quiet_exec(['psql'] + creds + ['-c', "CREATE USER %s WITH PASSWORD '%s';" % (username, password)], 'dbcreate') except CommandFailed: pass quiet_exec(['psql'] + creds + ['-c', "ALTER ROLE %s WITH PASSWORD '%s';" % (username, password)], 'dbcreate') try: quiet_exec(['createdb'] + creds + ['-T', 'template_postgis', database], 'dbcreate') except CommandFailed: quiet_exec(['dropdb'] + creds + [database], 'dbcreate') quiet_exec(['createdb'] + creds + ['-T', 'template_postgis', database], 'dbcreate') quiet_exec(['psql'] + creds + ['-c', "GRANT ALL ON DATABASE %s TO %s;" % (database, username)], 'dbcreate') if dba_pass: del os.environ['PGPASSWORD']
def _install(self): quiet_exec(['apt-get', '-y', 'update'], 'Apt') quiet_exec(['apt-get', '-y', 'install'] + self.PACKAGES, 'Apt')
def sysprep(self): self._install() quiet_exec(['easy_install', '-U', 'virtualenv'], 'Apt')