Skip to content

Instantly share code, notes, and snippets.

@lephuongbg
Last active December 20, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lephuongbg/6208098 to your computer and use it in GitHub Desktop.
Save lephuongbg/6208098 to your computer and use it in GitHub Desktop.
Joomla extension deploying script
#!/bin/bash
# Auto deploy module
JOOMLA="$HOME/public_html/joomla3"
ADMIN="$JOOMLA/administrator"
ADMIN_COMP="$ADMIN/components"
SITE_COMP="$JOOMLA/components"
# Function to move language files
mvlangs(){
local src=$1
local dest=$2
mv "$src"/en-GB.*.ini "$dest/en-GB/" 2> /dev/null;
mv "$src"/vi-VN.*.ini "$dest/vi-VN/" 2> /dev/null;
}
# Function to check for folder existance,
# and move shell current working directory to that folder if existed
chkdir(){
if [ -d $1 ]; then
# Move shell to this directory
cd $1;
else
echo "No such directory: \"$1\"";
exit 1;
fi
}
# Get the name of current working directory
getdirname(){
local path=`pwd`;
local name=`basename $path`;
echo $name;
}
# Check for valid extension source directory
chkext(){
local ext=$1;
local found=`grep --exclude-dir=.svn --exclude-dir=.git type=\"$ext\" *.xml`
if [ -z "$found" ]; then
echo "Not a valid $ext directory";
exit 1;
fi
}
# Alias for rsync with some extra options
dsync(){
rsync -rc --delete "$@"
}
# MAIN
if [ $# -lt 1 ]; then
echo -e "Invalid command!\n"\
"\tdeploy MODE [options] PATH\n"\
"MODE: module, template, components, plugins\n"\
"PATH: path to extension directory\n";
else
case "$1" in
"module")
shopt -u dotglob;
# Check valid path and move shell current directory
chkdir $2;
# Check for valid module directory
chkext "module";
# Get current directory name
MOD=`getdirname`;
echo "Module: $MOD";
# Synchronize source with destination
dsync ./ "$JOOMLA/modules/$MOD" && \
mvlangs "$JOOMLA/modules/$MOD" "$JOOMLA/language";
echo "Success!";
;;
"plugin")
if [ $# -lt 3 ]; then
echo -e "Invalid arguments:\n"\
"\tdeploy\tplugin\t{group}\t{plugindir}\n";
else
# Check valid path
chkdir $3;
# Check for valid plugin directory
chkext "plugin";
# Get plugin name
PLUG=`getdirname`;
GROUP=$2;
echo "Plugin: $GROUP - $PLUG";
# Check for plugin group existance
if [ ! -d "$JOOMLA/plugins/$GROUP" ]; then
echo "No such group: $GROUP";
# Prompt for plugin creating new group
read -p "Do you want to create group $GROUP?" -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
mkdir "$JOOMLA/plugins/$GROUP"
echo -e "\n"
fi
fi
# Check again if user has created new group
if [ -d "$JOOMLA/plugins/$GROUP" ]; then
# Copy plugin data
dsync ./ "$JOOMLA/plugins/$GROUP/$PLUG" && \
mvlangs "$JOOMLA/plugins/$GROUP/$PLUG" "$JOOMLA/administrator/language";
# Detect media folder existance in source
if [ -d "$JOOMLA/plugins/$GROUP/$PLUG/media" ]; then
# Copy media files into our own media folder
dsync "$JOOMLA/plugins/$GROUP/$PLUG/media/" "$JOOMLA/media/plg_"$GROUP"_"$PLUG
rm -r "$JOOMLA/plugins/$GROUP/$PLUG/media"
fi
echo "Success!";
fi
fi
;;
"component")
shopt -u dotglob
# Check and move shell's current directory
chkdir $2
# Check for valid component directory
chkext "component"
# Get current directory name
COMP=`getdirname`;
echo "Component: $COMP"
# Synchronize administrator part
dsync administrator/ "$ADMIN_COMP/$COMP" && \
mvlangs "$ADMIN_COMP/$COMP/language" "$ADMIN/language" && \
rm -r $ADMIN_COMP/$COMP/language;
# Synchronize site part
dsync site/ "$SITE_COMP/$COMP" && \
mvlangs "$SITE_COMP/$COMP/language" "$JOOMLA/language" && \
rm -r $SITE_COMP/$COMP/language;
# Copy manifest
cp ${COMP:4}.xml "$ADMIN_COMP/$COMP"
# Copy media
if [ -d "media" ]; then
dsync media/ "$JOOMLA/media/$COMP"
fi
echo "Success!";
;;
"template")
# Check and move shell's current directory
chkdir $2
# Check for valid template directory
chkext "template"
# Get current directory name
TMPL=`getdirname`
echo "Template: $TMPL"
# Synchronize template directory
dsync ./ "$JOOMLA/templates/$TMPL" && \
mvlangs "$JOOMLA/templates/$TMPL/language" "$JOOMLA/language"
rm -r "$JOOMLA/templates/$TMPL/language" && \
echo "Success";
;;
*)
echo "Unsupported mode!"
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment