summaryrefslogtreecommitdiff
path: root/parabolaweb-update.in
blob: 093786093e91921de054b6a658a40543fc9a7f45 (plain)
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
#!/bin/bash -e

#   Copyright (c) 2012-2013, 2015, 2019 Luke Shumaker <lukeshu@parabola.nu>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e
. @pkgconffile@
. libremessages

clean() {
	cd "$WEBDIR"
	msg "Purging old .pyc files..."
	find . -name '*.pyc' -delete
	if $RUNMAKE &>/dev/null; then
		msg "Purging old GNU Make generated files..."
		make clean
	fi
}

configure() {
	cd "$WEBDIR"
	msg "Checking configuration..."
	if [[ ! -f local_settings.py ]]; then
		msg2 "Configuration file missing, opening editor..."
		cp local_settings.py.example local_settings.tmp.$$.py
		if "$EDITOR" local_settings.tmp.$$.py; then
			mv local_settings.tmp.$$.py local_settings.py
		else
			rm local_settings.tmp.$$.py
			msg "Failed to configure, exiting"
			exit 1
		fi
		msg2 "Creating database..."
		./manage.py syncdb
	else
		msg2 "Current configuration checks out"
	fi
}

update-database() {
	cd "$WEBDIR"
	msg "Updating database..."
	msg2 "Running migrations..."
	./manage.py migrate
	if [[ -f devel/management/commands/update_types_permissions.py ]]; then
		msg2 "Updating permissions..."
		./manage.py update_types_permissions
	fi
	msg2 "Loading fixtures..."
	./manage.py loaddata main/fixtures/*.json
	./manage.py loaddata devel/fixtures/*.json
	./manage.py loaddata mirrors/fixtures/*.json
	./manage.py loaddata releng/fixtures/*.json
}

update-filesystem() {
	cd "$WEBDIR"
	msg "Updating filesystem..."
	if $RUNMAKE &>/dev/null; then
		msg2 "Re-creating GNU Make generated files..."
		make
	fi
	msg2 "Collecting static files..."
	echo yes | ./manage.py collectstatic -l
}

main() {
	if [[ -z "$EDITOR" ]]; then
		error 'Please set the $EDITOR variable'
		exit 1
	fi

	if [[ -d "$WEBDIR" ]]; then
		clean
	fi
	gitget checkout "$GITURL" "$WEBDIR"
	configure
	update-database
	update-filesystem
	sudo systemctl stop uwsgi@parabolaweb.service
}

main "$@"