Created
February 28, 2012 21:06
-
-
Save kostajh/1935141 to your computer and use it in GitHub Desktop.
Rebuild script for Drupal Install Profile
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
# This script facilitates obtaining the latest DB data from the production | |
# Drupal 5 site. | |
# The script gets an ordered dump of the D5 database, and commits it to the | |
# [email protected]:mysite_d5.git repository master branch. | |
# We make use of the rebuild.config file, so please make sure that your | |
# settings are correct there! | |
# We also assume that your drush aliases are setup correctly for | |
# @mysite.dev and @mysite_d5.prod. Please check mysite.aliases.drushrc.example, | |
# make sure your @mysite.dev alias is set up correctly, rename the file | |
# to mysite.aliases.drushrc.php and move it into your ~/.drush directory. | |
# Reading options from rebuild.config | |
FILENAME=rebuild.config | |
while read option | |
do | |
export $option | |
done < $FILENAME | |
DRUSH="$DRUSH_PATH" | |
cd $D5_GIT_REPO | |
git checkout master | |
git reset --hard | |
git pull | |
$DRUSH @mysite_d5.prod sql-dump --result-file=~/dumps/mysite-d5-production.sql --gzip --ordered-dump --structure-tables-key=common | |
scp [email protected]:dumps/mysite-d5-production.sql.gz $D5_GIT_REPO'/database' | |
cd $D5_GIT_REPO'/database' | |
gunzip -f mysite-d5-production.sql.gz | |
export COMMIT_MSG='Dump of MySite D5 Production database:' | |
export COMMIT_DATE=`date +%F-%T` | |
export COMMIT="$COMMIT_MSG $COMMIT_DATE" | |
git add mysite-D5-production.sql | |
git commit -m "$COMMIT" | |
git push origin master |
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
D5_DRUPAL_ROOT=/path/to/drupal5/drupal_root | |
D7_DRUPAL_ROOT=/path/to/drupal7/drupal_root | |
DRUSH_PATH=/path/to/drush/drush | |
D7_DATABASE=d7_database | |
D5_DATABASE=d5_database | |
D5_GIT_REPO=/path/to/d5/git_repo | |
D7_GIT_REPO=/path/to/d7/git_repo | |
D7_GIT_REPO_BRANCH=develop |
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/bash | |
# simple prompt | |
prompt_yes_no() { | |
while true ; do | |
printf "$* [Y/n] " | |
read answer | |
if [ -z "$answer" ] ; then | |
return 0 | |
fi | |
case $answer in | |
[Yy]|[Yy][Ee][Ss]) | |
return 0 | |
;; | |
[Nn]|[Nn][Oo]) | |
return 1 | |
;; | |
*) | |
echo "Please answer yes or no" | |
;; | |
esac | |
done | |
} | |
# Reading options from rebuild.config | |
FILENAME=rebuild.config | |
while read option | |
do | |
export $option | |
done < $FILENAME | |
DRUSH="$DRUSH_PATH" | |
# Start our rebuilding | |
clear | |
cat <<EOF | |
*** IMPORTANT *** | |
The following values were read from rebuild.config in your resources directory. | |
Please make sure they are correct before proceeding: | |
D5_DRUPAL_ROOT = $D5_DRUPAL_ROOT | |
D7_DRUPAL_ROOT = $D7_DRUPAL_ROOT | |
DRUSH_PATH = $DRUSH_PATH | |
D7_DATABASE = $D7_DATABASE | |
D5_DATABASE = $D5_DATABASE | |
D5_GIT_REPO = $D5_GIT_REPO | |
D7_GIT_REPO = $D7_GIT_REPO | |
EOF | |
if ! prompt_yes_no "Are sure these values are correct?" ; then | |
exit 1 | |
fi | |
cat <<EOF | |
The following operations will be done: | |
1. Delete $D7_DRUPAL_ROOT | |
2. Rebuild the Drupal directory in $D7_DRUPAL_ROOT | |
3. Re-install the mysite install profile in $D7_DRUPAL_ROOT | |
4. Optionally migrate files and content from the Drupal 5 database called | |
$D5_DATABASE to the Drupal 7 database called $D7_DATABASE | |
5. Optionally create symlinks from your git repo in $D7_GIT_REPO | |
to the new site directory in $D7_DRUPAL_ROOT | |
EOF | |
if ! prompt_yes_no "Are you sure you want to proceed?" ; then | |
exit 1 | |
fi | |
echo 'Rebuilding MySite...' | |
echo 'Removing '$D7_DRUPAL_ROOT' directory...' | |
chmod a+w $D7_DRUPAL_ROOT"/sites/default" | |
chmod a+w $D7_DRUPAL_ROOT"/sites/default/files" | |
rm -rf $D7_DRUPAL_ROOT | |
echo 'Executing drush make' | |
$DRUSH make --prepare-install --force-complete $D7_GIT_REPO"/mysite.build" $D7_DRUPAL_ROOT -y | |
cd $D7_DRUPAL_ROOT | |
echo 'Re-installing site database' | |
$DRUSH si mysite --site-name="MySite" --db-url="mysql://root:root@localhost/$D7_DATABASE" -y | |
echo 'Finished rebuilding directory and re-installing site.' | |
# Symlinks | |
cat <<EOF | |
Would you like to have symlinks set up? The script will create symlinks as | |
follows: | |
ln -s $D7_GIT_REPO/modules/custom $D7_DRUPAL_ROOT/profiles/mysite/modules/custom | |
ln -s $D7_GIT_REPO/themes/mysite $D7_DRUPAL_ROOT/profiles/mysite/themes/mysitetheme | |
EOF | |
if ! prompt_yes_no 'Create symlinks?' ; then | |
exit 1 | |
fi | |
echo 'Creating symlinks' | |
cd $D7_DRUPAL_ROOT | |
rm -rf profiles/mysite/modules/custom | |
rm -rf profiles/mysite/themes/mysitetheme | |
ln -s $D7_GIT_REPO"/modules/custom" $D7_DRUPAL_ROOT"/profiles/mysite/modules/custom" | |
ln -s $D7_GIT_REPO"/themes/mysite" $D7_DRUPAL_ROOT"/profiles/mysite/themes/mysitetheme" | |
echo 'Done making symlinks.' | |
# Content migration | |
cat <<EOF | |
The script will run 'drush migrate-import --all', which will run all | |
content migration patterns. You must have the Drupal 5 site setup locally | |
for this to work properly. | |
EOF | |
if ! prompt_yes_no "Migrate content and files?" ; then | |
exit 1 | |
fi | |
echo 'Migrating database content...' | |
echo 'Updating Drupal 5 git repo...' | |
cd $D5_GIT_REPO | |
git checkout master | |
git pull | |
# TODO: Set this so it imports only if git pull brought us new content | |
echo 'Importing Drupal 5 database...' | |
mysql -uroot -proot $D5_DATABASE < $D5_GIT_REPO"/database/mysite-production.sql" | |
cd $D7_DRUPAL_ROOT | |
echo 'Setting date and timezone settings...' | |
$DRUSH vset date_first_day 1 -y | |
$DRUSH vset date_default_timezone 'America/New_York' -y | |
$DRUSH vset date_api_use_iso8601 0 -y | |
$DRUSH vset site_default_country 'US' -y | |
$DRUSH vset configurable_timezones 0 -y | |
$DRUSH vset user_default_timezone 0 -y | |
echo 'Done.' | |
# Run cron to make sure any initialization necessary in Drupal takes place before | |
# nodes are imported. | |
echo 'Running cron...' | |
$DRUSH cron | |
# Migrate isn't resolving dependencies correctly so we specify the migration order here manually | |
$DRUSH mi mysiteUser | |
$DRUSH mi mysiteTouts | |
$DRUSH mi mysiteEducationalProgramNode | |
$DRUSH mi mysiteNewsNode | |
$DRUSH mi mysitePageNode | |
$DRUSH mi mysiteProgramEventNode | |
$DRUSH mi mysiteStaffMemberNode | |
$DRUSH mi mysiteFinish | |
echo 'Done.' | |
# The Webform feature, which contains Webform nodes, is enabled after | |
# all other features so as to not interfere with node IDs that are preserved | |
# from the Drupal 5 site | |
echo 'Enabling our Webforms' | |
$DRUSH en mysite_webforms -y | |
# File migration | |
echo 'Copying files...' | |
mkdir $D7_DRUPAL_ROOT"/sites/default/files/files" | |
cp -Rp $D5_DRUPAL_ROOT"/files/"* $D7_DRUPAL_ROOT"/sites/default/files/files/" | |
echo 'Done.' | |
echo 'Copying images...' | |
mkdir $D7_DRUPAL_ROOT"/sites/default/files/images" | |
cp -Rp $D5_DRUPAL_ROOT"/images/"* $D7_DRUPAL_ROOT"/sites/default/files/images/" | |
echo 'Done.' | |
echo 'Finished content migration!' | |
echo 'Rebuild completed.' |
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
# Simple wrapper around drush site-install to test the mysite.install file | |
# Reading options from rebuild.config | |
FILENAME=rebuild.config | |
while read option | |
do | |
export $option | |
done < $FILENAME | |
DRUSH="$DRUSH_PATH" | |
clear | |
echo 'Verifying your NCMNS profile. Please look for errors in the output below.' | |
cp $D7_GIT_REPO'/mysite.info' $D7_DRUPAL_ROOT'/profiles/mysite/' | |
cp $D7_GIT_REPO'/mysite.profile' $D7_DRUPAL_ROOT'/profiles/mysite/' | |
cp $D7_GIT_REPO'/mysite.install' $D7_DRUPAL_ROOT'/profiles/mysite/' | |
cd $D7_DRUPAL_ROOT | |
$DRUSH si mysite --site-name="MySite" --db-url="mysql://root:root@localhost/$D7_DATABASE" | |
echo 'Finished testing the MySite profile from the Git repo. If you did not see any errors, then you can assume it works.' |
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
# Simple wrapper around drush make --test to ensure the make file is correct. | |
# Reading options from rebuild.config | |
FILENAME=rebuild.config | |
while read option | |
do | |
export $option | |
done < $FILENAME | |
DRUSH="$DRUSH_PATH" | |
clear | |
echo 'Verifying your make file. Please look for errors in the output below.' | |
echo 'projects[drupal][type] = "core"' >> temp.txt | |
cat temp.txt >> $D7_GIT_REPO'/mysite.make' | |
rm temp.txt | |
$DRUSH make $D7_GIT_REPO'/mysite.make' --test | |
sed '$d' $D7_GIT_REPO'/mysite.make' > tmp.txt | |
mv tmp.txt $D7_GIT_REPO'/mysite.make' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment