1
#!/bin/bash
2
3
# Script to create a new project and trac instance
4
#
5
# 1. Create Mysql database with collate utf-8
6
#    > CREATE DATABASE <trac_project> DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
7
# 2. then execute trac-admin /path/to/trac/env initenv
8
#    > supply the db string as mysql://user:password@localhost/dbname
9
# 3. Deploy the project
10
#    > trac-admin /path/to/trac/env deploy /path/to/trac/env/deploy/
11
# 4. chmod to add group permissions
12
#    > chmod g+rwx /path/to/trac/env -R
13
#
14
15
readConfig() {
16
  configFile='trac.config'
17
18
  if [ ! -e $configFile ]; then
19
    echo "$configFile does not exist. Make sure you have a config file in the
20
    same path."
21
    exit 1;
22
  elif [ ! -r $configFile ]; then
23
    echo "Cannot read file $configFile. Permission denied."
24
    exit 1;
25
  fi
26
27
  tuser=$(sed -n 's/tuser=\(.*\)/\1/p' $configFile)
28
  tpassword=$(sed -n 's/tpassword=\(.*\)/\1/p' $configFile)
29
  ruser=$(sed -n 's/ruser=\(.*\)/\1/p' $configFile)
30
  rpassword=$(sed -n 's/rpassword=\(.*\)/\1/p' $configFile)
31
  rpassword=$(sed -n 's/rpassword=\(.*\)/\1/p' $configFile)
32
  trac_project=$(sed -n 's/trac_project=\(.*\)/\1/p' $configFile)
33
}
34
35
createDB() {
36
  echo "Creating DB trac_$project for $project"
37
  /usr/bin/mysql -u $ruser -p$rpassword -e "create database trac_$project default
38
  character set utf8 collate utf8_bin;grant all privileges on trac_$project.* to
39
  '$tuser'@'localhost' identified by '$tpassword';"
40
}
41
42
initTracEnv() {
43
  echo "Initing Env: $project"
44
  /usr/local/bin/trac-admin $trac_project$project initenv "\"$project\""
45
  "mysql://$tuser:$tpassword@localhost:3306/trac_$project" "git"
46
  "/vol/www/gitorious/repositories/"
47
}
48
49
deployTracEnv() {
50
  echo "Deploying to $trac_project$project/deploy/"
51
  /usr/local/bin/trac-admin $trac_project$project deploy $trac_project$project"/deploy/"
52
}
53
54
chmodTracEnv() {
55
  echo "Changing permissions of $trac_project$project"
56
  chmod g+rwx $trac_project$project -R
57
}
58
59
usage() {
60
	echo "Usage is $0 --name <name of the project>"
61
}
62
63
setup() {
64
	createDB && initTracEnv && deployTracEnv && chmodTracEnv;
65
  echo "Done.."
66
  exit 0;
67
}
68
69
if [ "$1" == "--help" ]; then
70
  usage
71
  exit 0;
72
elif [ "$1" == "--name" ]; then
73
  project=$2
74
  if [ -z $project ]; then
75
    echo "You have to give a project name. Please see --help."
76
    exit 1;
77
  fi
78
  readConfig
79
  setup
80
else
81
  echo "Invalid option. Please see --help."
82
  exit 1;
83
fi