Created
November 23, 2011 12:49
-
-
Save mcls/1388588 to your computer and use it in GitHub Desktop.
Expression Engine Configuratie (School)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import re | |
## | |
# Helper function for setting permissions | |
# | |
def chmod(permissions, path): | |
permissions = str(permissions) | |
path = str(path) | |
if (os.path.exists(path)): | |
os.chmod(path, int(permissions, 8)) | |
print(permissions + " " + path) | |
else: | |
print("Dit pad bestaat niet: " + path) | |
def mkdir(path, mode = 0777): | |
if (os.path.exists(path)): | |
print "De map '" + path + "' bestaat reeds." | |
else: | |
print "Map aanmaken: " + path | |
os.mkdir(path, mode) | |
def create_standard_htaccess(): | |
if ask_ok("Een standaard .htaccess file aanmaken?\nIndien er reeds een .htaccess bestaat zal deze overschreven worden.\n'y' of 'n': "): | |
print ".htaccess file aanmaken..." | |
content = "<IfModule mod_rewrite.c>\n" | |
content += "RewriteEngine On\n\n" | |
content += "RewriteBase /\n" | |
content += "RewriteCond %{REQUEST_FILENAME} !-f\n" | |
content += "RewriteCond %{REQUEST_FILENAME} !-d\n" | |
content += "RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]\n" | |
content += "RewriteRule ^(.*)$ /index.php?$1 [L]\n" | |
content += "</IfModule>\n" | |
htaccess = open(".htaccess", "w") | |
htaccess.write(content) | |
htaccess.close() | |
print ".htaccess aangemaakt" | |
print "Indien de installatie zich in een submap bevindt moet je nog wel de RewriteBase aanpassen in de .htaccess" | |
else: | |
print "Skipped." | |
def change_system_path(): | |
map_name = raw_input("Geef een nieuwe naam voor het system mapje (of drunk enter om de standaardnaam te behouden): ") | |
if map_name: | |
if not os.path.exists(map_name): | |
set_system_path_in_index(map_name) | |
# move map | |
os.rename("system", map_name) | |
return map_name | |
else: | |
print map_name + " already exists" | |
return "system" | |
else: | |
set_system_path_in_index("system") | |
return "system" | |
def set_system_path_in_index(path): | |
path = str(path) | |
index_content = open("index.php").read() | |
# overwrite old index.php (edit $system_path) | |
index_file = open("index.php", "w") | |
new_content = re.sub(r'\$system_path\s=\s[\'"].*[\'"]', '$system_path = \'./'+ path + '\'', index_content, 1) | |
index_file.write(new_content) | |
index_file.close() | |
def ask_ok(prompt, retries=10, complaint='Ja ("y") of nee ("n"), aub!'): | |
while True: | |
ok = raw_input(prompt) | |
if ok in ('y', 'ye', 'yes'): | |
return True | |
if ok in ('n', 'no', 'nop', 'nope'): | |
return False | |
retries = retries - 1 | |
if retries < 0: | |
raise IOError('refusenik user') | |
print complaint | |
# --------------------------------------------------------------------------------- | |
def main(): | |
print "*********************************" | |
print "* Configuring Expression Engine *" | |
print "*********************************" | |
print "Verander system path (optioneel)" | |
print "================================" | |
system_path = change_system_path() | |
print "Extra mappen voor school" | |
print "===========================" | |
mkdir("images/companies") | |
mkdir("images/ee-sites") | |
print "Setting permissions" | |
print "===================" | |
chmod("666", system_path + "/expressionengine/config/config.php") | |
chmod("666", system_path + "/expressionengine/config/database.php") | |
chmod("777", system_path + "/expressionengine/cache") | |
chmod("777", system_path + "/expressionengine/templates") | |
chmod("777", "images/uploads") | |
chmod("777", "images/avatars/uploads") | |
chmod("777", "images/captchas") | |
chmod("777", "images/member_photos") | |
chmod("777", "images/pm_attachments") | |
print ".htaccess" | |
print "=========" | |
create_standard_htaccess() | |
print "Done!" | |
print "=====" | |
print "De configuratie is klaar.\nSurf naar http://yourwebsite.com/" + system_path + "/index.php voor de installatie van Expression Engine" | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script voor Web CMS
Dit scriptje zorgt ervoor dat alle permissies voor Expression Engine ineens juist gezet worden.
Dat de extra mapjes voor companies en ee-sites aangemaakt worden.
En maakt een standaard .htaccess aan.
Indien de installatie in een submap staat moet de RewriteBase echter nog wel aangepast worden.
Getest op Ubuntu en MAMP.