summaryrefslogtreecommitdiff
path: root/libre/parabolaweb-utils/parabolaweb-update
blob: 45e17c4f2056e26828536da7be6e6deed0665b28 (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
#!/bin/bash
set -e

. /etc/conf.d/parabolaweb
. /usr/bin/libremessages

find_makefiles() {
	pushd "$WEBDIR" > /dev/null
	echo ./sitestatic
	find . -name static -type d | while read dir; do
		if [[ -e "$WEBDIR/$dir/Makefile" ]]; then
			printf '%s\n' "$dir"
		fi
	done
}

clean() {
	msg "Purging old .pyc files...."
	cd "$WEBDIR"
	find . -name '*.pyc' -delete
	for dir in `find_makefiles`; do
		make -C "$WEBDIR/$dir" clean
	done
}

configure() {
	msg "Checking configuration...."
	cd "$WEBDIR"
	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() {
	msg "Updating database...."
	cd "$WEBDIR"
	msg2 "Running migrations...."
	./manage.py migrate
	msg2 "Loading fixtures...."
	./manage.py loaddata */fixtures/*.json
}

update-filesystem() {
	msg "Updating filesystem..."
	for dir in `find_makefiles`; do
		msg2 "Updating $dir with GNU Make..."
		make -C "$WEBDIR/$dir"
	done
	cd "$WEBDIR"
	msg2 "Collecting static files..."
	echo yes | ./manage.py collectstatic -l
}

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

	parabolaweb-download
	clean
	configure
	clean
	update-database
	update-filesystem
}

main "$@"