Last active
February 7, 2018 21:56
-
-
Save sherakama/7200cf6d8cd630c51d070d329c5f56e1 to your computer and use it in GitHub Desktop.
Clones a site from anchorage and fires off a lando box.
This file contains 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
#!/bin/csh | |
################## | |
# Variables | |
################## | |
# Path to a place to store your sites. | |
WEBSERVERROOT=/httpdocs #no trailing slash | |
# Path to your lando configuration file for Drupal 7 | |
LANDOCONFIG=/Users/admin/scripts/su/d7.lando.yml | |
# The shortname of the site you are cloning | |
SHORTNAME=$1 | |
# Wether to include files from the archive dump on the server. | |
INCLUDEFILES=$2 | |
# Your sunet id | |
SUNETID="sheamck" | |
# Lando DB User (Also used in settings.php) | |
DBUSER="drupal7" | |
# Lando DB Pass (Also used in settings.php) | |
DBPASS="drupal7" | |
# Lando DB Name (Also used in settings.php) | |
DBNAME="drupal7" | |
# Lando DB Server (Also used in settings.php) | |
DBSERVER="database" | |
# The user on your computer who should own the files. | |
OWNER="admin" | |
# The group on your computer who should own the files. | |
GROUP="staff" | |
############# | |
# Prompts | |
############# | |
# Must provide a shortname or you cannot continue. | |
if [ -z "$1" ]; then | |
echo "You must provide a shortname in parameter #1" | |
exit; | |
fi | |
# If dir exists empty it. | |
if [ -d $WEBSERVERROOT/$SHORTNAME ]; then | |
echo "Are you sure you want remove all files and rebuild in $WEBSERVERROOT/$SHORTNAME" | |
select yepnope in "Yes, I know what I am doing!" "No way. Die die die."; do | |
case $yepnope in | |
'Yes, I know what I am doing!' ) | |
echo "Removing all files in $WEBSERVERROOT/$SHORTNAME" | |
sudo rm -Rf $WEBSERVERROOT/$SHORTNAME | |
break;; | |
'No way. Die die die.' ) | |
echo 'Terminating.'; | |
exit;; | |
esac | |
done | |
fi | |
################ | |
# RUN | |
################ | |
# Move to site root. | |
mkdir $WEBSERVERROOT/$SHORTNAME | |
cd $WEBSERVERROOT/$SHORTNAME | |
# Get resources from server. | |
drush -y rsync --include-conf @anc.$SHORTNAME . | |
BUCKET="$(drush @anc.${SHORTNAME} vget s3fs_bucket | sed 's/s3fs_bucket\: \"//' | sed 's/\"//' | tr -d '\r\n' )" | |
echo $BUCKET; | |
aws --profile anchorage s3 cp --recursive s3://$BUCKET/s3fs-private/ sites/default/files/private/ | |
aws --profile anchorage s3 cp --recursive s3://$BUCKET/s3fs-public/ sites/default/files/ | |
# Fix up a few permissions | |
echo "Fixing up a few file permissions" | |
sudo chown -Rf $OWNER:$GROUP $WEBSERVERROOT/$SHORTNAME | |
sudo chmod -Rf 0755 $WEBSERVERROOT/$SHORTNAME | |
sudo chmod -Rf 0777 $WEBSERVERROOT/$SHORTNAME/sites/default/files | |
# Clean up a few items | |
echo "Removing sites specific files." | |
sudo rm -Rf $WEBSERVERROOT/$SHORTNAME/.git | |
sudo rm $WEBSERVERROOT/$SHORTNAME/sites/default/settings.local.php | |
sudo rm $WEBSERVERROOT/$SHORTNAME/sites/default/settings.php | |
# Add the our files. | |
echo "Adding our configuration files." | |
cp $LANDOCONFIG $WEBSERVERROOT/$SHORTNAME/.lando.yml | |
cp $WEBSERVERROOT/$SHORTNAME/sites/default/default.settings.php $WEBSERVERROOT/$SHORTNAME/sites/default/settings.php | |
# Replace the shortname from RewriteBase. | |
sed -i .bak "s/\/$SHORTNAME/\//g" $WEBSERVERROOT/$SHORTNAME/.htaccess | |
sed -i .bak "s/RewriteRule sites/# RewriteRule sites/g" $WEBSERVERROOT/$SHORTNAME/.htaccess | |
# Copy the DB over from the extraction so we can import it later. | |
echo "Dumping database from source." | |
drush -y @anc.$SHORTNAME sql-dump > $WEBSERVERROOT/$SHORTNAME/db.sql | |
# Set the DB credentials in settings.php | |
echo "Appending database credentials to settings.php" | |
cat << FOE >> ${WEBSERVERROOT}/${SHORTNAME}/sites/default/settings.php | |
\$databases = array( | |
'default' => | |
array ( | |
'default' => | |
array ( | |
'database' => '${DBNAME}', | |
'username' => '${DBUSER}', | |
'password' => '${DBPASS}', | |
'host' => '${DBSERVER}', | |
'port' => '3306', | |
'driver' => 'mysql', | |
'prefix' => '', | |
), | |
), | |
); | |
FOE | |
# Navigate to the directory | |
cd $WEBSERVERROOT/$SHORTNAME | |
# Replace lando shortname | |
echo "Changing shortname in lando config file." | |
LANDONAME=$(echo ${SHORTNAME} | sed 's/\_//g') | |
sed -i .bak "s/\[shortname\]/${LANDONAME}/g" $WEBSERVERROOT/$SHORTNAME/.lando.yml | |
rm $WEBSERVERROOT/$SHORTNAME/.lando.yml.bak | |
# Start lando | |
lando restart | |
# Import DB using lando | |
lando db-import db.sql | |
# Add custom fixes in order to get the site to work in the lando box. | |
echo "Starting Lando Drush Command Fixups." | |
lando drush cc drush | |
lando drush sqlq 'update system set status=0 where name="simplesamlphp_auth"' | |
# lando drush rr | |
lando drush -y vset file_default_scheme public | |
lando drush -y dis s3fs anchorage_helper stanford_ssp | |
lando drush vset preprocess_css 0 | |
lando drush vset preprocess_js 0 | |
lando drush cc all | |
lando drush uli | |
# If the user specified no files then enable dummyimage. | |
if [ "$INCLUDEFILES" = "no-files" ]; then | |
lando drush dl dummyimage -y | |
lando drush en dummyimage -y | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment