-
-
Save jbickar/e354e57897bee18dd0c0254553a0215a to your computer and use it in GitHub Desktop.
su-clone-lando.sh
This file contains hidden or 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/bash | |
################## | |
# Variables | |
################## | |
# Path to a place to store your sites. | |
WEBSERVERROOT=/Users/jbickar/Sites #no trailing slash | |
# Path to your lando configuration file for Drupal 7 | |
LANDOCONFIG=/Users/jbickar/Sites/d7.lando.yml | |
# The shortname of the site you are cloning | |
SHORTNAME=$1 | |
# Whether to include files from the archive dump on the server. | |
INCLUDEFILES=$2 | |
# Your sunet id | |
SUNETID="jbickar" | |
# 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="jbickar" | |
# 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 | |
################ | |
# Get resources from server. | |
echo "Starting dump on server..." | |
if [ "$INCLUDEFILES" = "no-files" ]; then | |
drush @sse.ds_$SHORTNAME ard --destination=/afs/ir/group/webservices/backups/$SUNETID-copy.tar.gz --tar-options="--exclude=sites/default/files" --overwrite | |
else | |
drush @sse.ds_$SHORTNAME ard --destination=/afs/ir/group/webservices/backups/$SUNETID-copy.tar.gz --overwrite | |
# echo "Skipping drush ard" | |
fi | |
# Get the files from the server. | |
echo "Copying archive to local..." | |
scp [email protected]:/afs/ir/group/webservices/backups/$SUNETID-copy.tar.gz $WEBSERVERROOT/$SUNETID-copy.tar.gz | |
# Remove old unzipped directory. | |
if [ -d $WEBSERVERROOT/$SUNETID-copy ]; then | |
echo "Cleaning up old archive expansion" | |
sudo rm -Rf $WEBSERVERROOT/$SUNETID-copy | |
fi | |
# Expand in to new directory. | |
echo "Creating $WEBSERVERROOT/$SUNETID-copy" | |
mkdir $WEBSERVERROOT/$SUNETID-copy | |
# Expand | |
echo "Unzipping tar to $WEBSERVERROOT/$SUNETID-copy" | |
tar -zxf $SUNETID-copy.tar.gz -C $WEBSERVERROOT/$SUNETID-copy | |
# Move public_html in to shortname dir. | |
echo "Copying public_html to $WEBSERVERROOT/$SHORTNAME" | |
sudo mv $WEBSERVERROOT/$SUNETID-copy/public_html $WEBSERVERROOT/$SHORTNAME | |
# 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 | |
# If the user specified no files then create the directory. | |
if [ "$INCLUDEFILES" = "no-files" ]; then | |
mkdir $WEBSERVERROOT/$SHORTNAME/sites/default/files | |
fi | |
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 | |
# Comment out a setting that doesn't work with Lando's apache | |
sed -i .bak '/Header Set Cache-Control/s/^/#/' $WEBSERVERROOT/$SHORTNAME/.htaccess | |
# Copy the DB over from the extraction so we can import it later. | |
DBSHORT=$(echo $SHORTNAME | sed 's/\-/_/g') | |
DBDUMP="ds_$DBSHORT.sql" | |
echo "Copying database dump to $WEBSERVERROOT/$SHORTNAME/db.sql" | |
cp $WEBSERVERROOT/$SUNETID-copy/$DBDUMP $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 $DBSHORT | sed 's/\_//g') | |
sed -i .bak "s/\[shortname\]/${LANDONAME}/g" $WEBSERVERROOT/$SHORTNAME/.lando.yml | |
rm $WEBSERVERROOT/$SHORTNAME/.lando.yml.bak | |
# Set $base_url | |
printf "\n" >> ${WEBSERVERROOT}/${SHORTNAME}/sites/default/settings.php | |
echo "\$base_url = 'https://"$LANDONAME".lndo.site';" >> ${WEBSERVERROOT}/${SHORTNAME}/sites/default/settings.php | |
printf "\n" >> ${WEBSERVERROOT}/${SHORTNAME}/sites/default/settings.php | |
# Start lando | |
lando stop | |
lando rebuild -y | |
lando start | |
# 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 dis webauth -y | |
# lando drush dis stanford_sites_systemtools -y | |
# lando drush dis stanford_sites_helper -y | |
# 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 | |
# drush uli; tr to strip the carriage return | |
ULI=$(lando drush uli | tr -d '\r') | |
open $ULI |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment