Skip to content

Instantly share code, notes, and snippets.

@esfand
Forked from ajumell/install.py
Created May 28, 2018 22:04
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 esfand/f9ef87c834a74392c404e859d788d858 to your computer and use it in GitHub Desktop.
Save esfand/f9ef87c834a74392c404e859d788d858 to your computer and use it in GitHub Desktop.
Webfaction Magento Insatll script.
-----BEGIN WEBFACTION INSTALL SCRIPT-----
#!/bin/env python2.4
"""
Magento 1.7.0.2
"autostart": not applicable
"extra info": Do you agree to Magento's license?
http://www.opensource.org/licenses/osl-3.0.php
If so, enter the URL that Magento will be available at. For example,
http://www.example.com/ or https://www.example.com/.
"""
import random
import string
import sys
import urllib2
import xmlrpclib
def create(server, session_id, app_name, db_name, db_pass, db_user,
secure_base_url, url, use_secure, use_secure_admin):
# Create app and database.
server.create_db(session_id, db_name, 'mysql', db_pass)
app = server.create_app(session_id, app_name, 'static_php53')
# Download Magento and setup the app's ~/webapps directory.
cmd = """\
wget -q --referer=http://www.magentocommerce.com/download http://www.magentocommerce.com/getmagento/1.7.0.2/magento-1.7.0.2.tar.bz2
tar xjf magento-1.7.0.2.tar.bz2 --strip 1
wget -q --referer=http://www.magentocommerce.com/download http://www.magentocommerce.com/getmagento/1.6.1.0/magento-sample-data-1.6.1.0.tar.bz2
tar xjf magento-sample-data-1.6.1.0.tar.bz2 --strip 1
rm index.html
rm magento*.bz2
"""
server.system(session_id, cmd)
# Install Magento
server.write_file(session_id, 'my.cnf', '[client]\npassword=' + db_pass, 'wb')
cmd = """\
mysql --defaults-extra-file=my.cnf -u %(db_user)s %(db_name)s < magento_sample_data_for_1.6.1.0.sql
rm my.cnf
""" % locals()
server.system(session_id, cmd)
_file = """\
<?php
$_SERVER['argv']['admin_email'] = 'ajumell@gmail.com';
$_SERVER['argv']['admin_firstname'] = 'Muhammed';
$_SERVER['argv']['admin_lastname'] = 'K K';
$_SERVER['argv']['admin_password'] = '12345';
$_SERVER['argv']['admin_username'] = 'ajumell';
$_SERVER['argv']['db_host'] = 'localhost';
$_SERVER['argv']['db_name'] = '%(db_name)s';
$_SERVER['argv']['db_pass'] = '%(db_pass)s';
$_SERVER['argv']['db_user'] = '%(db_user)s';
$_SERVER['argv']['default_currency'] = 'INR';
$_SERVER['argv']['license_agreement_accepted'] = 'yes';
$_SERVER['argv']['locale'] = 'en_US';
$_SERVER['argv']['secure_base_url'] = '%(secure_base_url)s';
$_SERVER['argv']['skip_url_validation'] = 'yes';
$_SERVER['argv']['timezone'] = 'America/Los_Angeles';
$_SERVER['argv']['url'] = '%(url)s';
$_SERVER['argv']['use_rewrites'] = 'no';
$_SERVER['argv']['use_secure'] = '%(use_secure)s';
$_SERVER['argv']['use_secure_admin'] = '%(use_secure_admin)s';
""" % locals()
server.write_file(session_id, 'temp', _file, 'wb')
cmd = """\
mv install.php install.php.mv
mv temp install.php
sed '1d' install.php.mv >> install.php
php -f install.php
rm install.php
mv install.php.mv install.php
"""
stdout = server.system(session_id, cmd)
if 'SUCCESS' not in stdout:
print stdout
sys.exit()
print app['id']
def delete(server, session_id, app_name, db_name, *args):
server.delete_app(session_id, app_name)
try:
server.delete_db(session_id, db_name, 'mysql')
except:
pass
try:
server.delete_db_user(session_id, db_name, 'mysql')
except:
pass
if __name__ == '__main__':
action, username, password, machine, app_name, autostart, extra_info = \
sys.argv[1:]
server = xmlrpclib.ServerProxy('https://api.webfaction.com/')
session_id, account = server.login(username, password, machine)
db_name = db_user = ('%s_%s' % (username, app_name))[:16]
db_pass = ''.join(
random.choice(string.digits + string.letters) for i in range(8))
# Validate extra info.
url = extra_info.strip()
# remove this because a Site Not Configured page returns 503 response codes.
# try:
# urllib2.urlopen(url)
# except:
# print 'Extra info is invalid.'
# sys.exit()
if url.startswith('http://'):
secure_base_url = 'https://' + url[7:]
use_secure = use_secure_admin = 'no'
elif url.startswith('https://'):
secure_base_url = url
use_secure = use_secure_admin = 'yes'
else:
print 'Extra info is invalid.'
sys.exit()
locals()[action](server, session_id, app_name, db_name, db_pass,
db_user, secure_base_url, url, use_secure,
use_secure_admin)
-----END WEBFACTION INSTALL SCRIPT-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment