Last active
November 9, 2016 09:50
-
-
Save j6s/a545300e2de5f541a99b924d42add289 to your computer and use it in GitHub Desktop.
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/env ruby | |
require 'yaml' | |
# | |
# Enables and opens the install tool of TYPO3 pages inside of a Homestead | |
# development box. | |
# - Requires a Homestead environment | |
# - Will fail for non-TYPO3 pages | |
# | |
# Usage: | |
# install_tool.rb page.dev | |
# => will touch ENABLE_INSTALL_TOOL in the folder that is mapped to page.dev | |
# will also open http://page.dev/typo3/sysext/install/Start/Install.php | |
# | |
# Uses FirefoxDeveloperEdition as browser. change the @browser variable to | |
# use a different Browser. | |
# | |
#@browser = '/Applications/Google\ Chrome.app'; | |
@browser = '/Applications/FirefoxDeveloperEdition.app'; | |
@homestead = YAML.load_file(Dir.home + '/.homestead/Homestead.yaml') | |
# | |
# Resolves a path map: takes a path inside of the box, applies all path mappings | |
# and returns the path on the host system. | |
# Note: Returned paths may or may not exist on the host as not all paths in the box | |
# can be mapped to paths on the host | |
# | |
def findPathMap(pathInBox) | |
folders = @homestead['folders'] | |
pathOnHost = pathInBox; | |
folders.each do |folder| | |
pathOnHost = pathOnHost.sub(folder['to'], folder['map'].sub('~', Dir.home)) | |
end | |
return pathOnHost; | |
end | |
# | |
# Finds the homestead site configuration for the given hostname | |
# The host configuration is in the following format: | |
# { "map" => (HOSTNAME), "to" => (PATH IN BOX) } | |
# | |
def findSite(input) | |
puts "trying #{input}" | |
sites = @homestead['sites'] | |
site = nil; | |
sites.each do |s| | |
site = s if s['map'] == input | |
end | |
return site | |
end | |
# | |
# Enables the install tool and opens it in a browser | |
# | |
def enableInstallToolAndOpen(site) | |
to = findPathMap(site['to']) | |
f = "#{to}/typo3conf/ENABLE_INSTALL_TOOL"; | |
url = "http://#{site['map']}/typo3/sysext/install/Start/Install.php"; | |
puts "Toching #{f}" | |
puts `touch #{f}` | |
puts "Opening #{url}" | |
puts `open -a #{@browser} "#{url}"` | |
end | |
# --------------------------- | |
# gets user input | |
if ARGV.length == 0 | |
puts "Please pass site as parameter" | |
exit | |
end | |
input = ARGV[0]; | |
site = findSite(input) | |
site = findSite(input.downcase) if site == nil | |
site = findSite(input + '.dev') if site == nil | |
site = findSite(input.downcase + '.dev') if site == nil | |
if site != nil | |
enableInstallToolAndOpen(site) | |
else | |
puts "No matching site was found" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment