Skip to content

Instantly share code, notes, and snippets.

@garretfick
Created April 18, 2017 00:50
Show Gist options
  • Save garretfick/d6e3f0531b1ef86c8b05f3c12706de90 to your computer and use it in GitHub Desktop.
Save garretfick/d6e3f0531b1ef86c8b05f3c12706de90 to your computer and use it in GitHub Desktop.
setup-october.py
"""
A simple, one step setup script for installing OctoberCMS in Vagrant.
"""
import argparse
import os
import shutil
import subprocess
def git(*args):
"""
Run a command in Git, such as clone.
"""
return subprocess.check_call(['git'] + list(args))
def assure_path_exists(path):
"""
Make sure the path exists
"""
real_path = os.path.realpath(os.path.dirname(path))
if not os.path.exists(real_path):
os.makedirs(real_path)
def setup(install_dir):
"""
The starting point for setup. Install Vagrant at the specified location
"""
real_install_dir = os.path.realpath(install_dir)
assure_path_exists(real_install_dir)
# Clone the repository into the desired directory
git('clone', 'https://github.com/scotch-io/scotch-box.git', real_install_dir)
# We don't want the git history from Scotchbox, so remove the .git folder
# We will want to have our own history that won't really be related to
# the Vagrant box
shutil.rmtree(os.path.join(real_install_dir, '.git'))
# We want a specific working directory since this makes vagrant much easier to because
# it expects to run from a very particular directory
os.chdir(real_install_dir)
# Start Vagrant - this may take a while because the Vagrant image may need
# to download
subprocess.check_call(['vagrant', 'up'])
# Remove the index.php file since we don't want it at all
subprocess.check_call(['vagrant', 'ssh', '-c', 'rm /var/www/public/index.php'])
# Then install October CMS in the public directory
subprocess.check_call(['vagrant', 'ssh', '-c', 'cd /var/www/public && curl -s https://octobercms.com/api/installer | php'])
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Setup a OctoberCMS in a Vagrant image')
parser.add_argument('dir', help='Root directory for the project. The Vagrantfile for the project will be located in this directory')
args = parser.parse_args()
setup(args.dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment