Skip to content

Instantly share code, notes, and snippets.

@emanuele45
Last active December 17, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emanuele45/5630884 to your computer and use it in GitHub Desktop.
Save emanuele45/5630884 to your computer and use it in GitHub Desktop.
Testing script
import urllib2
import os
import os.path
import zipfile
from zipfile import ZipFile
import sys
import shutil
import re
import mechanize
server_path = '/whatever/your/path/is/'
install_dir = 'autotest'
extracted_name = "test.zip"
base_url = 'http://localhost/' + install_dir + '/'
download_url = 'https://github.com/emanuele45/Dialogo/archive/master.zip'
db_name = 'autotest'
db_user = 'root'
db_pwd = ''
full_path = os.path.join(server_path, install_dir)
#Get rid of the previous download
if os.path.exists('test.zip'): os.remove('test.zip')
if os.path.exists(full_path): shutil.rmtree(full_path)
# Download the new package
remotefile = urllib2.urlopen(download_url)
print remotefile.info()['Content-Disposition']
name_elem = remotefile.info()['Content-Disposition'].split('=')[-1].split('.')
del name_elem[-1]
final_name = '.'.join(name_elem)
data = remotefile.read()
with open(extracted_name, "wb") as code:
code.write(data)
# Extract
zipTest = ZipFile(extracted_name)
zipTest.extractall(server_path)
os.rename(os.path.join(server_path, final_name), os.path.join(server_path, install_dir))
# Move files to the appropriate position
shutil.copyfile(full_path + '/install/Settings.php', full_path + '/Settings.php')
shutil.copyfile(full_path + '/install/Settings_bak.php', full_path + '/Settings_bak.php')
shutil.copyfile(full_path + '/install/install.php', full_path + '/install.php')
shutil.copyfile(full_path + '/install/install_1-0_mysql.sql', full_path + '/install_1-0_mysql.sql')
shutil.copyfile(full_path + '/install/install_1-0_postgresql.sql', full_path + '/install_1-0_postgresql.sql')
shutil.copyfile(full_path + '/install/install_1-0_sqlite.sql', full_path + '/install_1-0_sqlite.sql')
# Let's create this one just in case
file = open(full_path + '/db_last_error.php', 'w+')
file.write('<?php')
file.close()
# And remove what is not necessary
shutil.rmtree(full_path + '/docs')
shutil.rmtree(full_path + '/install')
# And finally fix the permissions (since we cannot reliably change owner, we just set it world-writable
for dbase, dirs, files in os.walk(full_path):
for cdir in dirs:
os.chmod(os.path.join(dbase, cdir), 0o777)
for cfile in files:
os.chmod(os.path.join(dbase, cfile), 0o777)
# Start the install
br = mechanize.Browser()
br.open(base_url)
# First page is mostly only a welcome...I hope
br.select_form(nr=0)
request = br.submit()
print request.geturl()
# Second page: database details
br.select_form(nr=0)
# These are kept default for now
#br.form['db_type'] = 'mysql'
#br.form['db_server'] = 'localhost'
br.form['db_user'] = db_user
br.form['db_name'] = db_name
br.form['db_passwd'] = db_pwd
control = br.find_control('contbutt')
control.disabled = False
request = br.submit()
print request.geturl()
# Third page, nothing to change
br.select_form(nr=0)
control = br.find_control('contbutt')
control.disabled = False
request = br.submit()
print request.geturl()
# Fourth page, dummy
br.select_form(nr=0)
control = br.find_control('contbutt')
control.disabled = False
request = br.submit()
print request.geturl()
# Fifth page: admin accounts details
br.select_form(nr=0)
# These are kept default for now
br.form['username'] = 'admin'
br.form['password1'] = 'admin'
br.form['password2'] = 'admin'
br.form['email'] = 'admin@localhost.tld'
br.form['password3'] = db_pwd
control = br.find_control('contbutt')
control.disabled = False
request = br.submit()
print request.geturl()
# Fifth page: admin accounts details
br.open(base_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment