Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Last active October 12, 2022 20:36
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 jazzsequence/d382e94607186f160eef7a88d95f9a4d to your computer and use it in GitHub Desktop.
Save jazzsequence/d382e94607186f160eef7a88d95f9a4d to your computer and use it in GitHub Desktop.
Roots Sage install script on Pantheon
#!/bin/bash
themedir="web/app/themes/"
echo "Enter the site name. \n
This will be used to clone your site locally to /{User}/pantheon-local-copies/{site_name) and to interact with your site."
read $sitename
echo "Enter your theme name. \n
This is used to create the theme directory. As such, it should ideally be all lowercase with no spaces (hyphens or underscores recommended)."
read $sagename
echo "Enter your SFTP username. \n
This will only be stored in this terminal session. This can be found in your site dashboard."
read $sftpuser
echo "Enter your SFTP hostname. \n
This will only be stored in this terminal session. This can be found in your site dashboard."
read $sftphost
sagedir=$themedir/$sagename
# Clone the site
terminus local:clone $sitename
if [ $? -ne 0 ]; then
echo "Site could not be cloned. Did you enter the correct site name?"
exit;
fi
# Move to the new site directory.
cd ~/pantheon-local-copies/$sitename
# Set the main branch to track master from Pantheon.
git branch -u origin/master
# Update to PHP 8.0
sed -i '' "s/php_version: 7.4/php_version: 8.0" pantheon.upstream.yml
git commit -am "[Sage Install] Update PHP version to 8.0"
# Create the new Sage theme
composer create-project roots/sage $sagedir
# Require Roots/acorn
composer require roots/acorn --working-dir=$sagedir
# Install all the Sage dependencies
composer install --no-dev --prefer-dist --working-dir=$sagedir
# NPM the things
npm install --prefix $sagedir
npm run build --prefix $sagedir
# Remove /public from .gitignore
sed -i '' "s/\/public//" $sagedir/.gitignore
# Commit the theme
git add $sagedir
git commit -m "[Sage Install] Add the Sage theme"
# Switch to SFTP mode
terminus connection:set $sitename.dev sftp
# Create a files/cache directory on the host.
sftp -P 2222 $sftpuser@$sftphost:/files <<< $'mkdir cache'
# Switch back to Git mode.
terminus connection:set $sitename.dev git
# Create the symlink to /files/cache.
cd web/app
ln -sfn uploads/cache
git add .
git commit -m "[Sage Install] Add a symlink for /files/cache to /uploads/cache"
cd ../..
# Check of jq is installed
if [ ! command -v jq &> /dev/null ]; then
if [ ! command -v brew & /dev/null ]; then
echo 'Brew was not found. Exiting here. You\'ll need to add the following lines to your `composer.json`:'
echo ' "scripts": {'
echo ' "post-install-cmd": ['
echo ' "@composer install --working-dir=web/app/themes/$sagename"'
echo ' ],'
exit
fi
brew install jq
fi
# Add a post-install hook to the composer.json.
jq -r '.scripts += { "post-install-cmd": [ "@composer install --working-dir=%sagedir%" ] }' composer.json > composer.new.json
sed -i '' "s,%sagedir%,$sagedir," composer.new.json
rm composer.json
mv composer.new.json composer.json
# Commit the change to composer.json
git add composer.json
git commit -m "[Sage Install] Add post-install-cmd hook to also run install on Sage theme"
git pull --ff --commit
git push origin HEAD:master
# Activate the new theme
terminus wp -- $sitename.dev theme activate $sagename
# Switch back to SFTP so files can be written.
terminus connection:set $sitename.dev sftp
# Open the site. This should generate requisite files on page load.
open https://dev-$sitename.pantheonsite.io
# Commit any additions found in SFTP mode.
terminus env:commit $sitename.dev --message="[Sage Install] Add any leftover files found in SFTP mode."
# Switch back to Git.
terminus connection:set $sitename.env git
git pull --ff --commit
@jazzsequence
Copy link
Author

This script is Mac only and assumes Homebrew is installed. For non-OSX/non-brew environments, these steps would need to be performed manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment