blob: 28ab0f5b47f00ef9ad06ec0ab2ed11cf539baa5b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
#!/bin/bash
dbquery() {
mysql -s -s -e "$*" trac
}
# main function
main() {
echo
# project_name may not be an empty string and must be >= 3 characters
while [[ ${#project_name} -lt 3 ]]
do
eask_str "a project name (min 3 chars)"
project_name=${REPLY}
done
if [[ -n $(dbquery "SELECT id FROM project WHERE project_name = '${project_name}'") ]]
then
eerror "Project ${project_name} already exists."
fi
eask_str "a project description"
project_desc=${REPLY}
# svn_name may not be an empty string and must be >= 3 characters
eask_str "a gforge svn repository name (LEAVE BLANK if this is a new project)"
gforge_name=${REPLY}
if [[ -n ${gforge_name} && ! -d /mnt/gforge/var/lib/gforge/svn/${gforge_name} ]]
then
eerror "Repository ${gforge_name} does not exists."
fi
# who requests the project ?
while [[ -z ${user_name} ]]
do
eask_str "username of applicant"
user_name=${REPLY}
done
user_email=$(dbquery "SELECT email FROM user WHERE login = '${user_name}'")
if [[ -z ${user_email} ]]
then
eerror "Username ${user_name} does not exist."
fi
einfo
einfo "$(color yellow)public project:$(color) read access for everyone with a spline-dev account." \
"write access only for project members. this is the default."
einfo "$(color yellow)private project:$(color) read and write access only for project members."
einfo
eask_bool "Should the project be private?" n
project_closed=${REPLY}
svn_home=${SVN_ROOT}/${project_name}
trac_home=${TRAC_ROOT}/${project_name}
trac_db=trac_${project_name}
if [[ -z ${gforge_name} ]]
then
eheading "creating new subversion directory"
eexec svnadmin create ${svn_home}
tmpdir=$(mktemp -d)
eexec mkdir -p ${tmpdir}/{trunk,tags,branches}
eexec svn -q import -m "initial import for project ${project_name}" ${tmpdir} file://${svn_home}
eexec chown -R apache:apache ${svn_home}
eexec rm -rf ${tmpdir}
else
eheading "using existing gforge repository"
eexec svnadmin create ${svn_home}
tmpfile=$(mktemp)
svnadmin dump /mnt/gforge/var/lib/gforge/svn/${gforge_name} > ${tmpfile}
svnadmin load ${svn_home} < ${tmpfile}
rm -f ${tmpfile}
fi
eheading "creating new trac project"
eexec mysqladmin create ${trac_db}
eexec trac-admin ${trac_home} initenv --inherit=${TRAC_INI} ${project_name} \
"mysql://${MYSQL_USER}:${MYSQL_PASS}@${MYSQL_HOST}/${trac_db}" svn ${svn_home}
eexec sed -i -e "/^name =/a\\descr = ${project_desc}\\" ${trac_home}/conf/trac.ini
if [[ ${project_closed} == y ]]
then
for perm in BROWSER_VIEW CHANGESET_VIEW FILE_VIEW LOG_VIEW MILESTONE_VIEW \
REPORT_SQL_VIEW REPORT_VIEW ROADMAP_VIEW SEARCH_VIEW TICKET_VIEW \
TIMELINE_VIEW WIKI_VIEW
do
eexec trac-admin ${trac_home} permission remove anonymous ${perm}
done
fi
for perm in TICKET_CREATE TICKET_MODIFY WIKI_CREATE WIKI_MODIFY
do
eexec trac-admin ${trac_home} permission remove authenticated ${perm}
done
eexec trac-admin ${trac_home} permission add authenticated TRAC_ADMIN
eexec trac-admin ${trac_home} permission add authenticated XML_RPC
eexec trac-admin ${trac_home} wiki import WikiStart WikiStart.txt
eexec trac-admin ${trac_home} wiki import GettingStarted GettingStarted.txt
eexec chown apache:apache ${trac_home}/conf/trac.ini
eexec chown -R apache:apache ${trac_home}/attachments
eheading "setting up apache2"
eexec sed -i -e "\$a\\# ${project_name} (added on $(date -R))\\" ${APACHE_PROJECT_CONF}
eexec sed -i -e "\$a\\Use TracProject ${project_name}\\" ${APACHE_PROJECT_CONF}
if [[ ${project_closed} == y ]]
then
eexec sed -i -e "\$a\\Use SVNProjectClosed ${project_name}\\" ${APACHE_PROJECT_CONF}
else
eexec sed -i -e "\$a\\Use SVNProject ${project_name}\\" ${APACHE_PROJECT_CONF}
fi
echo >> ${APACHE_PROJECT_CONF}
eexec /etc/init.d/apache2 reload
eheading "committing changes to our git-repository in /etc"
pushd /etc > /dev/null
eexec git add ${APACHE_PROJECT_CONF/\/etc\/}
eexec git commit -m "added new project ${project_name}"
popd > /dev/null
eheading "adding initial project member to the database"
if [[ ${project_closed} == y ]]
then
eexec dbquery "INSERT INTO project (project_name, private) VALUES ('${project_name}', 1)"
else
eexec dbquery "INSERT INTO project (project_name) VALUES ('${project_name}')"
fi
eexec dbquery "INSERT INTO member (user_id, project_id) VALUES (" \
"(SELECT id FROM user WHERE login = '${user_name}')," \
"(SELECT id FROM project WHERE project_name = '${project_name}'))"
eexec wget --no-check-certificate -q -O/dev/null https://dev.spline.de/account/genusers
eheading "requesting new mailinglist for the project"
# register mailinglist (owner is user_email) for the new project
eexec wget -q -O /dev/null --no-check-certificate --post-data "name=commit_${project_name}&email=${user_email}" \
https://lists.spline.inf.fu-berlin.de/cgi-bin/neueliste.pl
eheading "sending confirmation email to applicant"
sendmail -t <<-EOF
From: dev@spline.de
Subject: your new project has been approved
To: ${user_email}
Dear ${user_name},
your project (${project_name}) has been created and can be found at
https://dev.spline.de/trac/${project_name}
Yours,
the dev.spline.de team
EOF
einfo "mail to ${user_email} has been sent"
eheading "sending DONE email to dev@spline.de"
sendmail -t <<-EOF
From: dev@spline.de
Subject: project ${project_name} for ${user_name} has been created
To: dev@spline.de
Dear dev@spline.de,
the project ${project_name} for user ${user_name} has been created !
Yours,
the dev.spline.de team
EOF
einfo "mail to dev@spline.de has been sent"
echo
einfo
einfo "done! success! jipii! neeeat!"
einfo "you can find the project at $(color yellow)https://dev.spline.de/trac/${project_name}$(color)"
einfo
echo
}
# go to script dir
pushd $(dirname $0) > /dev/null
# get global functions
source "./functions.sh"
# load configuration
source "./config.sh"
# exit on errors
set -e
# start main program
main "$@"
# leave script dir
popd > /dev/null
|