<commit_before>#!/bin/bash
TERMINUS='/home/vagrant/cli/php/boot-fs.php'
LOCAL_DIR="/srv/www/drupal/$1"; #should be an empty dir
SITENAME=$1
DB="pantheon_$( echo $1 | sed -r 's/-//')"
DBUSER="$( echo $1 | sed -r 's/-//')"
DBPASS="$( echo $1 | sed -r 's/-//')"
SITE_ID=$( php $TERMINUS site info --site=$SITENAME --bash --nocache=1 | grep id | awk '{print $2}' )
GIT_REMOTE="ssh://codeserver.dev.$SITE_ID@codeserver.dev.$SITE_ID.drush.in:2222/~/repository.git"
echo "GIT_REMOTE=$GIT_REMOTE"

if [ ! -d $LOCAL_DIR ] ; then
	mkdir -p $LOCAL_DIR;
fi

cd $LOCAL_DIR

URLS=$( php $TERMINUS site backups-urls --site=$SITENAME --nocache --bash );
if [[ 1 = "$?" ]]; then
	echo "Must make a backup first \`terminus site backup-make --site=$SITENAME --env=dev\`"
	exit
fi

# code first
if [[ ! -d code ]]; then
	mkdir -p code
	cd code
	git clone $GIT_REMOTE .
	# setup git repo with remote connection
	git remote rm origin
	git remote add origin $GIT_REMOTE
	# reset and mode changes that may have been introduced
	git reset --hard HEAD
	cd ../
fi

DB_URL=$( echo "$URLS" | grep "database" )
curl "$DB_URL" > "database.sql.gz"
gunzip database.sql.gz

FILES_URL=$( echo "$URLS" | grep "files" )
curl "$FILES_URL" > files.tar.gz
mkdir -p files
tar -vxf files.tar.gz -C ./files/

# import db
mysql -e "DROP DATABASE $DB" #in case it already exists
mysql -e "create database $DB"
mysql -e "grant all privileges on $DB.* to $DBUSER@'%' identified by '$DBPASS'"
mysql $DB < database.sql

# create the local config if it's wordpress
cd code
if [[ -f ./wp-config.php ]]; then
	cp wp-config-sample.php wp-config-local.php
	sed -i 's/database_name_here/'$DB'/' wp-config-local.php
	sed -i 's/username_here/'$DBUSER'/' wp-config-local.php
	sed -i 's/password_here/'$DBPASS'/' wp-config-local.php
fi
<commit_msg>Updated script to work after refactor<commit_after>#!/bin/bash
TERMINUS='php /home/vagrant/cli/php/boot-fs.php'
LOCAL_DIR="/srv/www/drupal/$1"; #should be an empty dir
SITENAME=$1
DB_NAME="pantheon_$( echo $1 | sed -r 's/-//')"
DBUSER="$( echo $1 | sed -r 's/-//')"
DBPASS="$( echo $1 | sed -r 's/-//')"
SITE_ID=$( $TERMINUS site info --site=$SITENAME --bash --nocache=1 | grep id | awk '{print $2}' )
GIT_REMOTE="ssh://codeserver.dev.$SITE_ID@codeserver.dev.$SITE_ID.drush.in:2222/~/repository.git"
echo "GIT_REMOTE=$GIT_REMOTE"

if [ ! -d $LOCAL_DIR ] ; then
	mkdir -p $LOCAL_DIR;
fi

cd $LOCAL_DIR

$TERMINUS site get-backup --site=$SITENAME --element=files --env='dev' --to-directory=$LOCAL_DIR
$TERMINUS site get-backup --site=$SITENAME --element=database --env='dev' --to-directory=$LOCAL_DIR

DB=$( ls . | grep "database.*gz" )
FILES=$( ls . | grep "files.*gz" )

# code first
if [[ ! -d code ]]; then
	mkdir -p code
	cd code
	git clone $GIT_REMOTE .
	# setup git repo with remote connection
	git remote rm origin
	git remote add origin $GIT_REMOTE
	# reset and mode changes that may have been introduced
	git reset --hard HEAD
	cd ../
fi

# import files
tar -vxf $FILES 

# import db
gunzip $DB
DB=$( ls . | grep "database.*\.sql$" )

mysql -e "DROP DATABASE $DB_NAME" #in case it already exists
mysql -e "create database $DB_NAME"
mysql -e "grant all privileges on $DB_NAME.* to $DBUSER@'%' identified by '$DBPASS'"
mysql -vvv $DB_NAME < $DB

# create the local config if it's wordpress
cd code
if [[ -f ./wp-config.php ]]; then
	cp wp-config-sample.php wp-config-local.php
	sed -i 's/database_name_here/'$DB'/' wp-config-local.php
	sed -i 's/username_here/'$DBUSER'/' wp-config-local.php
	sed -i 's/password_here/'$DBPASS'/' wp-config-local.php
fi

{'fraction_non_alphanumeric': 0.1739498167465464, 'fraction_numerical': 0.006484352974344516, 'mean_word_length': 3.6561679790026247, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '736283', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1358, 'n_words': 405}