
| Current Path : /home/ift/51_iftlib/drupal/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //home/ift/51_iftlib/drupal/create_drupal_site.py |
# coding: utf8
import os,sys,re
class Create_drupal_site (object):
def __init__ (self):
self.hint = '''
=================================================================
Be aware to have enabled in `/etc/apache2/apache2.conf`:
Include sites-enabled/*
Set the variables in `etc/php/x.y/apache2/php.ini` so that:
memory_limit = 512M
max_execution_time = 600
max_input_time = 600
'''
#***********************************************************
def run (self,pars):
varwww = re.sub(r"\/$","",os.path.abspath(".")) + "/"
try:
m = re.search(r"(.*?)@(.*)\:(\d+)$",pars[1])
except:
m = None
error = None
if m:
www_user = m.group(1)
new_site = m.group(2)
new_port = m.group(3)
else:
error = '\nParameter format: (www-user)@(site_name):(port)\n\n'
if not error and os.path.isdir(varwww+new_site):
error = '\nSite ' + new_site + ' exists already\n\n' + self.hint
if error:
print("\nERROR:\n" + error)
return()
print ("User " + www_user)
print ("Site " + new_site)
print ("Port " + new_port)
varwww = re.sub(r"\/$","",os.path.abspath(".")) + "/"
os.system('''
# apt-get install -y mysql5 mysql-common
# apt-get install -y mysql-server mysql-client
apt-get install -y apache2 php php-gd php-xml
apt-get install -y sqlite3 php-sqlite
apt-get install -y libapache2-mod-php php-mysqlnd
apt-get install -y php-gd php-intl php-pear
apt-get install -y php-imap php-mcrypt php-memcache
apt-get install -y php-ming php-curl php-imagick
apt-get install -y php-ps php-pspell php-recode
apt-get install -y php-snmp php-sqlite php-tidy
apt-get install -y php-xmlrpc php-xsl php-apcu
a2enmod rewrite ssl
/etc/init.d/apache2 restart
cp drush813.phar /usr/local/bin
cp drush813 /usr/local/bin
chmod 775 /usr/local/bin/drush813*
drush813 dl drupal-8
mv drupal-8.* '''+new_site+'''
cp '''+new_site+'''/sites/default/default.settings.php '''+new_site+'''/sites/default/settings.php
''')
open("/etc/apache2/sites-available/"+new_site,"w").write(
'<VirtualHost *:'+new_port+'''>
DocumentRoot '''+varwww+new_site+'''
ServerName '''+new_site+'''
ServerAlias www.'''+new_site+'''
<Directory '''+varwww+new_site+'''>
# Options -FollowSymLinks -SymLinksIfOwnerMatch
AllowOverride All
# Order allow,deny
# allow from all
</Directory>
</VirtualHost>
''')
open(varwww+new_site+"/"+new_site,"w").write(
'<VirtualHost *:80'+'''>
RewriteEngine On
RewriteRule "^/(.+)" "http://'''+new_site+'''"
ServerName '''+new_site+'''
ServerAlias www.'''+new_site+'''
</VirtualHost>
# eval redir --lport ''' + new_port + ''' --cport ''' + new_port + ''' --caddr REMOTEHOST &
''')
open(varwww+new_site+"/postinstall.sh","w").write('''
chmod a-w '''+varwww+new_site+'''/sites/default/settings.php
drush813 en --yes whitejazz
drush813 en --yes bootstrap
drush813 dl --yes adaptivetheme
drush813 en --yes at_tools
drush813 en --yes at_core
drush813 en --yes at_theme_generator
sudo chown -R '''+www_user+''':www-data '''+varwww+new_site+'''
sudo chmod -R g+rwx '''+varwww+new_site+'''/sites/default
mv '''+varwww+new_site+'''/postinstall.sh '''+varwww+new_site+'''/postinstall.done
''')
os.system('''
sudo chown -R '''+www_user+''':www-data '''+varwww+new_site+'''
sudo chmod -R g+rwx '''+varwww+new_site+'''/sites/default
''')
os.system("chdir /etc/apache2/sites-enabled; ln -s ../sites-available/"+new_site)
open("/etc/apache2/ports.conf","a").write("Listen " + new_port + "\n")
os.system("/etc/init.d/apache2 restart")
print (self.hint + '''
Now run:
1. http://localhost:'''+new_port+''' (in Browser)
2. In '''+ varwww + new_site + ''': postinstall.sh
'''
)
#****************************************************
if __name__ == "__main__":
if len(sys.argv) > 1 and sys.argv[1] in Create_drupal_site.__dict__:
Create_drupal_site.__dict__[sys.argv[1]](Create_drupal_site(),sys.argv[2:])
else:
Create_drupal_site.__dict__['run'](Create_drupal_site(),sys.argv)