MT Shell Script Installer

From MovableType

Installs Movable Type from SVN repositories.

Originally posted on Adventures in Movable Type. I'm placing this here so others might improve upon it!

Contents

File Structure

This script assumes the following file structure, but can be easily modified.

   /Users/
       beau/
           Sites/
               _live/
                   cgi/
                       branch-frampton
                       tag-mt4.21
                       trunk
                   html/
                       mt-static-dirs/
                           branch-frampton/
                               mt-static    <-- symlink to /Users/beau/Sites/_live/cgi/branch-frampton/mt-static
                           tag-mt4.21/
                               mt-static    <-- symlink to /Users/beau/Sites/_live/cgi/tag-mt4.21/mt-static
                           trunk/
                               mt-static    <-- symlink to /Users/beau/Sites/_live/cgi/trunk/mt-static

Usage

   $ makemt {branch/tag/trunk} {repo_name} {local_dir} {addons_branch}

Checkout MT Trunk:

   $ makemt trunk

Checkout MT frampton branch:

   $ makemt branch frampton

Checkout MT release-40 branch with a (poorly created) custom local branch name "new-final-4" and addons directory from "cal" branch:

   $ makemt branch release-40 new-final-4 branches/cal

Script

Execute the following code as shell script. Mine is placed at /Users/beau/bin/makemt

   #!/bin/bash
   set -e; # exit on error
   set -x; # print each function before executing. Enable for testing.
   # exit; # used to exit script
   # usage: makemt {branch/tag/trunk} {repo_name} {local_dir} {addons_repo_path}
   # target_repo = svn repo name
   # local_repo = local repo dir to place this repo
   # addons_repo_path = repo of addons to checkout
   # examples: 
   #
   # Checkout MT Trunk
   #   makemt trunk
   #
   # Checkout MT frampton branch
   #   makemt branch frampton
   #
   # Checkout MT release-40 branch with a custom local branch name "test-beau-final-4" and addons directory from "cal" branch
   #   makemt branch release-40 test-beau-final-4 branches/cal
   #
   repo_type=${1};
   target_repo=${2};
   local_repo=${3};
   if [ ! $local_repo ]; then
       local_repo=$target_repo;
   fi
   addons_repo_path=${4};
   if [ ! $addons_repo_path ]; then
       addons_repo_path="trunk";
   fi
   case $repo_type in
   "trunk")
       target_repo="trunk";
       local_repo="trunk";
       target_repo_path="trunk";
       if [ ! $addons_repo_path ]; then
           addons_repo_path="trunk";
       fi
       echo "repo_type: $repo_type";;
   "branch")
       local_repo="branch-$local_repo";
       target_repo_path="branches/$target_repo";
       if [ ! $addons_repo_path ]; then
           addons_repo_path="branches/$target_repo";
       fi
       echo "repo_type: $repo_type";;
   # "tag") # UNTESTED
   #     local_repo="tag-$local_repo";
   #     if [ ! $addons_repo_path ]; then
   #         addons_repo_path="tags/$target_repo";
   #     fi
   #     echo "repo_type: $repo_type";;
   # "pruning") # UNTESTED
   #     local_repo="pruning-$local_repo";
   #     if [ ! $addons_repo_path ]; then
   #         addons_repo_path="prunings/$target_repo";
   #     fi
   #     echo "repo_type: $repo_type";;
   *)
       echo "usage: makemt branch/tag/trunk repo_name {local_dir[repo_name]} {addons_repo/path[repo_name]}";
       exit; # exit if no type specified
   esac
   if [ $repo_type ] && [ $target_repo ] && [ $local_repo ] && [ $addons_repo_path ]; then
       echo "target_repo: $target_repo";
       echo "local_repo: $local_repo";
       echo "addons_repo: $addons_repo";
       echo "---------------------------------------------";
       echo "Checkout MT core...";
       svn co -q http://code.sixapart.com/svn/movabletype/$target_repo_path $LIVE_DIR/cgi/$local_repo;
       pushd $LIVE_DIR/cgi/$local_repo/; make -s; popd;
       mkdir $LIVE_DIR/html/mt-static-dirs/$local_repo;
       chmod 777 $LIVE_DIR/html/mt-static-dirs/$local_repo;
       ln -s $LIVE_DIR/cgi/$local_repo/mt-static $LIVE_DIR/html/mt-static-dirs/$local_repo/mt-static;
       chmod -R 777 $LIVE_DIR/cgi/$local_repo/mt-static/support;
       echo "---------------------------------------------";
       echo "Checkout addons...";
       svn co -q http://svn.sixapart.com/repos/eng/mtaddons/$addons_repo_path/addons $LIVE_DIR/cgi/$local_repo/addons;
       svn co -q http://svn.sixapart.com/repos/eng/mtaddons/$addons_repo_path/mt-static/addons $LIVE_DIR/cgi/$local_repo/mt-static/addons;
       svn co -q http://svn.sixapart.com/repos/eng/mtaddons/$addons_repo_path/mt-static/themes/tristan-blue $LIVE_DIR/cgi/$local_repo/mt-static/themes/tristan-blue;
       svn co -q http://svn.sixapart.com/repos/eng/mtaddons/$addons_repo_path/mt-static/themes/tristan-blue-4.2 $LIVE_DIR/cgi/$local_repo/mt-static/themes/tristan-blue-4.2;
       curl http://svn.sixapart.com/repos/eng/mtaddons/$addons_repo_path/mt-cp.cgi > $LIVE_DIR/cgi/$local_repo/mt-cp.cgi;
       chmod 755 $LIVE_DIR/cgi/$local_repo/mt-cp.cgi
       echo "---------------------------------------------";
       echo "Create mt-config.cgi file...";
       mt_config="# Config File Generated via makemt command
   CGIPath /cgi-bin/$local_repo/
   StaticWebPath /mt-static-dirs/$local_repo/mt-static
   #
   ObjectDriver DBI::mysql
   Database mt_r21
   DBUser root
   DBPassword root
   DBHost localhost
   #DBSocket /Applications/MAMP/tmp/mysql/mysql.sock
   #
   ##### CGI LOCATIONS #####
   # AdminScript mt.fcgi
   # CommentScript mt-comments.fcgi
   # TrackbackScript mt-tb.fcgi
   # ActivityFeedScript mt-feed.fcgi
   # XMLRPCScript mt-xmlrpc.fcgi
   # AtomScript mt-atom.fcgi
   # UpgradeScript mt-upgrade.fcgi
   #
   DebugMode 1
   DeleteFilesAtRebuild 1
   # HTTPTimeout 60
   # EnableAddressBook 1
   # ShowIPInformation 1";
       echo "$mt_config" > $LIVE_DIR/cgi/$local_repo/mt-config.cgi;
       mate $LIVE_DIR/cgi/$local_repo/;
       mate $LIVE_DIR/cgi/$local_repo/mt-config.cgi;
   else
       echo "usage: makemt branch/tag/trunk repo_name {local_dir[repo_name]} {addons_repo/path[repo_name]}";
   fi

To Do

  • error check to determine if directories to be created by script already exist.