From 453176dfa17b19dd21182957ee896ca47c605dbc Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Thu, 23 May 2013 14:28:56 +0530 Subject: [PATCH] Script to create new trac instances Simple bash script to create a new trac env, setup database and deploy the instance. This automates otherwise a lenghty procedure for creating new trac projects. --- .gitignore | 1 + new_project.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ trac.config.sample | 5 ++++ 3 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100755 new_project.sh create mode 100644 trac.config.sample diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..390a9c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +trac.config diff --git a/new_project.sh b/new_project.sh new file mode 100755 index 0000000..c6ce782 --- /dev/null +++ b/new_project.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# Script to create a new project and trac instance +# +# 1. Create Mysql database with collate utf-8 +# > CREATE DATABASE DEFAULT CHARACTER SET utf8 COLLATE utf8_bin; +# 2. then execute trac-admin /path/to/trac/env initenv +# > supply the db string as mysql://user:password@localhost/dbname +# 3. Deploy the project +# > trac-admin /path/to/trac/env deploy /path/to/trac/env/deploy/ +# 4. chmod to add group permissions +# > chmod g+rwx /path/to/trac/env -R +# + +readConfig() { + configFile='trac.config' + + if [ ! -e $configFile ]; then + echo "$configFile does not exist. Make sure you have a config file in the + same path." + exit 1; + elif [ ! -r $configFile ]; then + echo "Cannot read file $configFile. Permission denied." + exit 1; + fi + + tuser=$(sed -n 's/tuser=\(.*\)/\1/p' $configFile) + tpassword=$(sed -n 's/tpassword=\(.*\)/\1/p' $configFile) + ruser=$(sed -n 's/ruser=\(.*\)/\1/p' $configFile) + rpassword=$(sed -n 's/rpassword=\(.*\)/\1/p' $configFile) + rpassword=$(sed -n 's/rpassword=\(.*\)/\1/p' $configFile) + trac_project=$(sed -n 's/trac_project=\(.*\)/\1/p' $configFile) +} + +createDB() { + echo "Creating DB trac_$project for $project" + /usr/bin/mysql -u $ruser -p$rpassword -e "create database trac_$1 default + character set utf8 collate utf8_bin;grant all privileges on trac_$1.* to + '$tuser'@'localhost' identified by '$tpassword';" +} + +initTracEnv() { + echo "Initing Env: $project" + /usr/local/bin/trac-admin $trac_project$1 initenv "\"$1\"" + "mysql://$tuser:$tpassword@localhost:3306/trac_$1" "git" + "/vol/www/gitorious/repositories/" +} + +deployTracEnv() { + echo "Deploying to $trac_project$project/deploy/" + /usr/local/bin/trac-admin $trac_project$1 deploy $trac_project$1"/deploy/" +} + +chmodTracEnv() { + echo "Changing permissions of $trac_project$project" + chmod g+rwx $trac_project$project -R +} + +usage() { + echo "Usage is $0 --name " +} + +setup() { + createDB && initTracEnv && deployTracEnv && chmodTracEnv; + echo "Done.." + exit 0; +} + +if [ "$1" == "--help" ]; then + usage + exit 0; +elif [ "$1" == "--name" ]; then + project=$2 + if [ -z $project ]; then + echo "You have to give a project name. Please see --help." + exit 1; + fi + readConfig + setup +else + echo "Invalid option. Please see --help." + exit 1; +fi diff --git a/trac.config.sample b/trac.config.sample new file mode 100644 index 0000000..6dd9b6f --- /dev/null +++ b/trac.config.sample @@ -0,0 +1,5 @@ +tuser=mysql_trac_username +tpassword=mysql_trac_passwd +ruser=mysql_root_user +rpassword=mysql_root_passwd +trac_project=path/to/the/dir/where/all/trac/envs/are/kept -- 1.7.10.4