if not os.path.exists(abbrev):
  # Copy files
  dest_shared = "%s/shared" %abbrev
  copytree('templates_rails_use', abbrev)
  copytree('templates_rails_shared', dest_shared)
  
  # Parameters to fill in
  config_vm_box = "%s/%s-%s" %(owner, distro, abbrev)
  local_box = "vagrant-%s-%s.box" %(distro, abbrev)
  if abbrev == 'min':
    config_vm_box = "%s/%s" %(owner, distro)
    local_box = "vagrant-%s.box" %(distro)
  
  # Update files outside the shared directory
  common.replace_string_in_file("%s/Vagrantfile" %abbrev, '<BOX_NAME>', config_vm_box)
  common.replace_string_in_file("%s/Vagrantfile" %abbrev, '<PORT_GEN_HOST>', port_output_gen)
  common.replace_string_in_file("%s/Vagrantfile" %abbrev, '<PORT_RAILS_HOST>', port_output_rails)
  common.replace_string_in_file("%s/Vagrantfile" %abbrev, '<PORT_PG_HOST>', port_output_pg)
  common.replace_string_in_file("%s/download_new_box.sh" %abbrev, '<BOX_NAME>', config_vm_box)
  common.replace_string_in_file("%s/install_local_box.sh" %abbrev, '<BOX_NAME>', config_vm_box)
  common.replace_string_in_file("%s/install_local_box.sh" %abbrev, '<LOCAL_BOX>', local_box)
  
  # Update files inside the shared directory
  common.replace_string_in_file("%s/shared/test_pg.sh" %abbrev, '<PORT_RAILS_HOST>', port_output_rails)
  common.replace_string_in_file("%s/shared/test_pg.sh" %abbrev, '<PORT_PG_HOST>', port_output_pg)
  common.replace_string_in_file("%s/shared/test_sq.sh" %abbrev, '<PORT_RAILS_HOST>', port_output_rails)
  
  # Remove irrelevant files; rename the info-*.sh file to info.sh
  if abbrev == 'min':
    os.remove("%s/shared/test_pg.sh" %abbrev)
from shutil import copytree

import common

abbrev = sys.argv[1] # 'rbenv-rubymn', 'rbenv-rubygems', etc.
port_output_gen = sys.argv[2] # '8081', '8082', etc.
port_output_rails = sys.argv[3] # '3000', '3001', etc.
port_output_pg = sys.argv[4] # '15432', '15433', etc.
distro = sys.argv[5] # 'debian-jessie', 'debian-stretch', etc.
owner = sys.argv[6] # 'jhsu802701', 'rubymn', etc.

# 1. Create Bash script rbenv-*.sh for using the new project-specific Vagrant setup.
#    This requires multiple parameters.
file1 = "%s.sh" %abbrev
shutil.copy('rbenv.sh', file1)
common.replace_string_in_file(file1, 'rbenv', "%s" %abbrev)
common.replace_string_in_file(file1, '8080', "%s" %port_output_gen)
common.replace_string_in_file(file1, '3000', "%s" %port_output_rails)
common.replace_string_in_file(file1, '15432', "%s" %port_output_pg)
common.replace_string_in_file(file1, 'debian-jessie', "%s" %distro)
common.replace_string_in_file(file1, 'jhsu802701', "%s" %owner)

# 2. Copy ruby-rbenv.sh in packer_rails_custom to ruby-rbenv-*.sh in packer_rails_custom.
# NOTE: requires manual customization
file2 = "packer_rails_custom/ruby-%s.sh" %abbrev
shutil.copy('packer_rails_custom/ruby-rbenv.sh', file2)

# 3. Copy user-rbenv.json in packer_rails_custom to user-rbenv-*.json in packer_rails_custom.
#    Update the reference to ruby-rbenv.sh
file3 = "packer_rails_custom/user-%s.json" %abbrev
shutil.copy('packer_rails_custom/user-rbenv.json', file3)
def update_gitignore(str2):
  str1 = '# END OF .gitignore'
  str3 = "%s\n%s" %(str2, str1)
  common.replace_string_in_file('.gitignore', str1, str3)
import os, sys, shutil
from shutil import copytree

import common

abbrev = 'rbenv-rubymn'
deb_branch = 'jessie'

# 1. Copy packer_rails_general/debian.json into the root directory
#    NOTE: So far, the json file is for the minimal Vagrant box.
#    Changes are needed to configure this file for the rbenv/rbenv-* box.
shutil.copy('packer_rails_general/debian.json', 'debian.json')

# 2. Update name of virtual machine in debian.json
common.replace_string_in_file('debian.json', 'packer-debian', "packer-debian-%s" %(deb_branch))

# 3. Update file name of Vagrant box in debian.json
name1 = "vagrant-debian-%s.box" %(deb_branch)
name2 = "vagrant-debian-%s-%s.box" %(deb_branch, abbrev)
common.replace_string_in_file('debian.json', name1, name2)

# 4. Add provisioning script to scripts/user directory
shutil.copy("packer_rails_custom/ruby-%s.sh" %(abbrev), "scripts/user/ruby-%s.sh" %(abbrev))

# 4. Update list of provisioning scripts executed as root
str_root_txt = common.string_from_file('packer_rails_general/root.json')
common.replace_string_in_file('debian.json', '"scripts/root/vagrant.sh"', str_root_txt)

# 5. Update list of provisioning scripts executed as user
file_template_scripts = "packer_rails_custom/user-%s.json" %(abbrev)