Skip to content

Instantly share code, notes, and snippets.

@messageagency
Last active March 30, 2021 21:47
Show Gist options
  • Save messageagency/6223d272b79fe6f7bb2b to your computer and use it in GitHub Desktop.
Save messageagency/6223d272b79fe6f7bb2b to your computer and use it in GitHub Desktop.
Pantheon DB Connection Script
#!/bin/sh
# exit on any errors:
set -e
if [ $# -lt 1 ]
then
echo "Usage: $0 @pantheon-alias"
exit 1
fi
DRUSH='/opt/local/bin/drush'
PANTHEON_USER='PANTHEON USERNAME GOES HERE'
PANTHEON_PASS='PANTHEON PASSWORD GOES HERE'
TEMPLATE='spf-template.spf'
TMP_SPF='/tmp/tmp.spf'
$DRUSH pauth $PANTHEON_USER --password=$PANTHEON_PASS
$DRUSH paliases
echo "fetching connection string"
CONNECTION_STRING=`$DRUSH $1 sql-connect`
echo $CONNECTION_STRING
DATABASE=`echo $CONNECTION_STRING | sed -e 's/.*--database=\([^\\ ]*\).*/\1/g'`
HOST=`echo $CONNECTION_STRING | sed -e 's/.*--host=\([^\\ ]*\).*/\1/g'`
PORT=`echo $CONNECTION_STRING | sed -e 's/.*--port=\([^\\ ]*\).*/\1/g'`
PASSWORD=`echo $CONNECTION_STRING | sed -e 's/.*--password=\([^\\ ]*\).*/\1/g'`
USER=`echo $CONNECTION_STRING | sed -e 's/.*--user=\([^\\ ]*\).*/\1/g'`
eval "echo \"$(< $TEMPLATE)\""
# For some reason, Sequel Pro or Open do not behave the same way given the -f
# flag compared to opening a file from file system. So, we write to a tmp file.
eval "echo \"$(< $TEMPLATE)\"" > $TMP_SPF
open $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>database</key>
<string>${DATABASE}</string>
<key>host</key>
<string>${HOST}</string>
<key>name</key>
<string>${USER}@${HOST}</string>
<key>password</key>
<string>${PASSWORD}</string>
<key>port</key>
<integer>${PORT}</integer>
<key>rdbms_type</key>
<string>mysql</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>SPTCPIPConnection</string>
<key>useSSL</key>
<integer>0</integer>
<key>user</key>
<string>${USER}</string>
</dict>
<key>session</key>
<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.39-MariaDB-log</string>
<key>version</key>
<integer>1</integer>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment