Created
June 7, 2012 17:35
-
-
Save robballou/2890232 to your computer and use it in GitHub Desktop.
Move a feature tar file into the drupal directory
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 | |
# | |
# Move the feature tar file contents into your site and remove it | |
# | |
# Usage: | |
# move_feature.sh [feature file] [drupal directory] | |
# | |
# | |
if [[ $# -ne 2 ]]; then | |
echo 'Usage: move_feature.sh [feature_file] [drupal_directory]' | |
exit 1 | |
fi | |
TEMPORARY_DIR=/tmp/tmp_feature | |
if [[ ! -f $1 ]]; then | |
echo 'Feature file does not exist' | |
exit 1 | |
fi | |
if [[ ! -d $2 ]]; then | |
echo 'Site directory does not exist' | |
exit 1 | |
fi | |
# cleanup our temporary directory, incase it exists | |
if [[ -d $TEMPORARY_DIR ]]; then | |
rm -fr $TEMPORARY_DIR | |
fi | |
# create a temporary directory and untar our feature | |
mkdir $TEMPORARY_DIR && tar -xf $1 -C $TEMPORARY_DIR | |
if [[ $? -ne 0 ]]; then | |
echo 'Error creating tmp directory/untarring feature' | |
exit 1 | |
fi | |
# get the tar filename from the command line argument | |
FILENAME=`basename $1` | |
FILENAME=`echo $FILENAME | sed s/\.tar//` | |
# the features directory relative to the site | |
FEATURES_DIRECTORY=$2/sites/all/modules/features | |
# if the features directory does not exist, create it | |
if [[ ! -d $FEATURES_DIRECTORY ]]; then | |
echo 'Creating features directory' | |
mkdir $2/sites/all/modules/features | |
fi | |
# if the feature directory instead the features dir does not exist, create it | |
if [[ ! -d $FEATURES_DIRECTORY/$FILENAME ]]; then | |
echo 'Creating features directory for' $FILENAME | |
mkdir $FEATURES_DIRECTORY/$FILENAME | |
else | |
echo 'Cleaning old files' | |
rm $FEATURES_DIRECTORY/$FILENAME/* | |
fi | |
mv $TEMPORARY_DIR/$FILENAME/* $FEATURES_DIRECTORY/$FILENAME | |
RETVALUE=$? | |
# cleanup after ourselves | |
if [[ RETVALUE -eq 0 ]]; then | |
rm -fr $TEMPORARY_DIR | |
# if we're on a system with ~/.Trash, move it there (Mac only?) | |
# otherwise, just remove it | |
if [[ -d ~/.Trash ]]; then | |
mv $1 ~/.Trash | |
else | |
rm $1 | |
fi | |
else | |
echo 'Moving the feature files failed. Temporary directory still exists at' $TEMPORARY_DIR | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment