Skip to content

Instantly share code, notes, and snippets.

@andreav
Last active December 11, 2015 04:38
Show Gist options
  • Save andreav/4546413 to your computer and use it in GitHub Desktop.
Save andreav/4546413 to your computer and use it in GitHub Desktop.
drupal7 pack unpack bash scripts
>>>>> drupal7 pack unpack bash scripts <<<<<<<
* drupal7-install.sh is only used to install first time, and set right permissions
* copy drupal7-pack.sh drupal7-unpack.sh under "sites/all/custom/pack"
- work on your site from the UI
* run drupal7-pack.sh to export your repo to code, then commit and push
- Into another direcotory:
* clone your repo
* run drupal7-unpack.sh to upload code
* optionally save everthing to db
#!/bin/bash
MYSITENAME=mysite
usage()
{
cat << EOF
usage: $0 [--wget|--git]
EOF
exit 128
}
[ "$#" -ne 1 ] && usage
[ "$1" != '--wget' ] && [ "$1" != '--git' ] && usage
# drupal download
#================
if [ "$1" == '--wget' ]; then
wget -nc http://ftp.drupal.org/files/projects/drupal-7.18.tar.gz
tar zxvf drupal-7.18.tar.gz
mv drupal-7.18 $MYSITENAME
else
git clone --recursive --branch 7.x http://git.drupal.org/project/drupal.git $MYSITENAME
fi
cd $MYSITENAME
# drupal initialization
#======================
mkdir sites/all/libraries && touch sites/all/libraries/.placeholder
mkdir sites/default/files && touch sites/default/files/.placeholder
mkdir sites/default/files/private && touch sites/default/files/private/.placeholder
chgrp -Rv www-data sites/default/files
chmod 2775 sites/default/files
chmod 2775 sites/default/files/private
chmod g+w -R sites/default/files
DBNAME=$MYSITENAME-db
DBUSER=admin
DBPASS=admin
DBSUUSER=root
DBSUPASS=itpass
ACCOUNTNAME=admin
ACCOUNTPASS=admin
SITENAME=mysite.mysite
SITEMAIL=admin@mysite.mysite
drush si standard -y --db-url=mysql://$DBUSER:$DBPASS@localhost/$DBNAME --db-su=$DBSUUSER --db-su-pw="$DBSUPASS" --account-name=$ACCOUNTNAME --account-pass=$ACCOUNTPASS --site-name=$SITENAME --site-mail=$SITEMAIL
# git initialization
#===================
mv .gitignore .gitignore.orig
sed -e 's@^sites\/\*\/files@#sites\/\*\/files@g' -e 's@sites\/\*\/private@#sites\/\*\/private@' .gitignore.orig > .gitignore
git init .
git add .
git commit -m 'Core initialized'
#!/bin/bash
[ ! -e './sites/all/modules' ] && echo '[ERROR] - Run from inside site root' && exit 1
[ ! -e 'sites/default/settings.php' ] && echo '[ERROR] - Site not yet initialized, maybe you want to run unpack.sh?' && exit 1
[ ! -e './sites/all/custom/pack' ] && mkdir -p ./sites/all/custom/pack
# disable for the module list
# rm to avoid override options
drush dis -y mysite_config
rm -rf ./sites/all/modules/ctools_export/mysite_config
drush pm-list --status=enabled --type=module --pipe > sites/all/custom/pack/mysite.enmod
drush pm-list --status=disabled --type=module --pipe > sites/all/custom/pack/mysite.dismod
git add sites/all/custom/pack/
drush ctex mysite_config
drush sql-dump --ordered-dump --result-file=sites/all/custom/pack/db-backup
git add sites/all/modules/ctools_export/mysite_config
git add sites/all/custom/pack/db-backup
git add sites/default/files
#git commit -m "packed everything"
#!/bin/bash
[ ! -e './sites/all/modules' ] && echo '[ERROR] - Run from inside site root' && exit 1
SITENAME=$( basename $PWD )
chgrp -Rv www-data sites/default/files
chmod 2775 sites/default/files
chmod 2775 sites/default/files/private
chmod g+w -R sites/default/files
if [ ! -e 'sites/default/settings.php' ]; then
DBNAME=$SITENAME-db
DBUSER=admin
DBPASS=admin
DBSUUSER=root
DBSUPASS=itspass
ACCOUNTNAME=admin
ACCOUNTPASS=admin
SITENAME=$SITENAME.$SITENAME
SITEMAIL=admin@$SITENAME.$SITENAME
drush si standard -y --db-url=mysql://$DBUSER:$DBPASS@localhost/$DBNAME --db-su=$DBSUUSER --db-su-pw="$DBSUPASS" --account-name=$ACCOUNTNAME --account-pass=$ACCOUNTPASS --site-name=$SITENAME --site-mail=$SITEMAIL
fi
drush dis -y $( cat sites/all/custom/pack/mysite.dismod )
drush en -y $( cat sites/all/custom/pack/mysite.enmod )
drush dis -y mysite_config
drush cbum -y --result-file=sites/all/custom/pack/db-backup.BEFORE-UNPACK mysite_config
# Maybe now I could save to db and disable module:
# However keeping it enabled will let you revert changes ....
# i.e. display suite will show edit - revert instead of edit - delete on custom fields.
# drush cbsa mysite_config
# drush dis -y mysite_config
# drush cc all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment