summaryrefslogtreecommitdiffstats
path: root/bin/closeproject
blob: 19b443361e519c3919b4b07cd958a39956488cc8 (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
#!/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 [[ -z $(dbquery "SELECT id FROM project WHERE project_name = '${project_name}'") ]]
	then
		eerror "Project ${project_name} does not exists."
	fi

	svn_home=${SVN_ROOT}/${project_name}
	trac_home=${TRAC_ROOT}/${project_name}
	trac_db=trac_${project_name}

	eheading "setting trac permissions"
	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

	for perm in TICKET_CREATE TICKET_MODIFY WIKI_CREATE WIKI_MODIFY
	do
		eexec trac-admin ${trac_home} permission remove authenticated ${perm}
	done

	# apply changes to /etc/apache2/vhosts.d/dev_vhost.include
	eexec sed -i -e "s/Use SVNProject ${project_name}/Use SVNProjectClosed ${project_name}/" /etc/apache2/vhosts.d/dev_vhost.include
	eexec /etc/init.d/apache2 reload

	# set project to private in database
	dbquery "UPDATE project SET private = 1 WHERE project_name = '${project_name}'"

	eheading "committing changes to our git-repository in /etc"
	pushd /etc > /dev/null
	eexec git add ${APACHE_PROJECT_CONF/\/etc\/}
	eexec git commit -m "opened project ${project_name}"
	popd > /dev/null
}

# 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