Skip to content

Instantly share code, notes, and snippets.

@danshumaker
Forked from aaronbauman/p-connect.sh
Last active April 16, 2018 16:27
Show Gist options
  • Save danshumaker/4c972c97a0049af31a97 to your computer and use it in GitHub Desktop.
Save danshumaker/4c972c97a0049af31a97 to your computer and use it in GitHub Desktop.
Connect to a Pantheon database in Sequel Pro
#!/bin/sh
# Dan Shumaker modified&added features:
# 1. Use terminus instead of drush
# 2. Save standard options (if user wants to they can save their settings on lines 14-18 and not have to have any cli options)
# 3. Auto generate standard live,test,dev enviornment files
# 4. Removed dependency on separate spf template file.
#
# Tested with El Capitan, Sequel Pro 1.1 (Obac 177), terminus 0.10.0
# original: https://gist.github.com/aaronbauman/f50cc691eb3ed60a358c
# exit on any errors:
set -e
TUS='/Users/XXX/vendor/bin/terminus'
LOGIN='XXXX@XXXX'
PASS='XXX'
SITE='XXX'
PENV='live'
if [ $# -eq 5 ]
then
echo "Usage: $0 TUS login password site env"
TUS=$1
LOGIN=$2
PASS=$3
SITE=$4
PENV=$5
fi
$TUS auth login $LOGIN --password="$PASS"
# Use terminus to update the aliases
terminus sites aliases
# Function so we can repeat it for the standard three environments
save_env() {
PENV=$1
echo "Fetching connection info for env = " $PENV
SUSER=`$TUS site connection-info --site=$SITE --env=$PENV --field=sftp_username`
SPASS=$PASS
SHOST=`$TUS site connection-info --site=$SITE --env=$PENV --field=sftp_host`
SPORT=`$TUS site connection-info --site=$SITE --env=$PENV --field=git_port`
if [[ $SPORT =~ ^(Notice:)* ]]; then
# Default to port 2222
SPORT=2222
fi
MUSER=`$TUS site connection-info --site=$SITE --env=$PENV --field=mysql_username`
MPASS=`$TUS site connection-info --site=$SITE --env=$PENV --field=mysql_password`
MPORT=`$TUS site connection-info --site=$SITE --env=$PENV --field=mysql_port`
MDATABASE=`$TUS site connection-info --site=$SITE --env=$PENV --field=mysql_database`
MHOST=`$TUS site connection-info --site=$SITE --env=$PENV --field=mysql_host`
TMP_SPF=${SITE}_${PENV}.spf
cat << TEMPLATE > $TMP_SPF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ContentFilters</key>
<dict/>
<key>auto_connect</key>
<true/>
<key>data</key>
<dict>
<key>connection</key>
<dict>
<key>colorIndex</key>
<integer>2</integer>
<key>database</key>
<string>${MDATABASE}</string>
<key>host</key>
<string>${MHOST}</string>
<key>kcid</key>
<string>-8839967931455730304</string>
<key>name</key>
<string>${SITE} - ${PENV} - ${MDATABASE}</string>
<key>password</key>
<string>${MPASS}</string>
<key>port</key>
<integer>${MPORT}</integer>
<key>rdbms_type</key>
<string>mysql</string>
<key>ssh_host</key>
<string>${SHOST}</string>
<key>ssh_keyLocation</key>
<string></string>
<key>ssh_keyLocationEnabled</key>
<integer>0</integer>
<key>ssh_password</key>
<string>${SPASS}</string>
<key>ssh_port</key>
<integer>${SPORT}</integer>
<key>ssh_user</key>
<string>${SUSER}</string>
<key>sslCACertFileLocation</key>
<string></string>
<key>sslCACertFileLocationEnabled</key>
<integer>0</integer>
<key>sslCertificateFileLocation</key>
<string></string>
<key>sslCertificateFileLocationEnabled</key>
<integer>0</integer>
<key>sslKeyFileLocation</key>
<string></string>
<key>sslKeyFileLocationEnabled</key>
<integer>0</integer>
<key>type</key>
<string>SPSSHTunnelConnection</string>
<key>useSSL</key>
<integer>0</integer>
<key>user</key>
<string>${MUSER}</string>
</dict>
</dict>
<key>encrypted</key>
<false/>
<key>format</key>
<string>connection</string>
<key>queryFavorites</key>
<array/>
<key>queryHistory</key>
<array/>
<key>rdbms_type</key>
<string>mysql</string>
<key>rdbms_version</key>
<string>5.5.40-MariaDB-log</string>
<key>version</key>
<integer>1</integer>
</dict>
</plist>
TEMPLATE
}
# If you want a specific multi-dev environment then specify it on the command line
if [ $# -eq 5 ]
then
save_env $5
open $TMP_SPF
else
# Otherwise generate the standard three environments on pantheon
save_env live
save_env test
save_env dev
fi
@derimagia
Copy link

Take a look at the terminus plugin I took from inspiration from aaronbauman: https://github.com/derimagia/terminus-pancakes

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