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

_install_dir=/srv/http
_gitname=web
_gitroot=git://parabolagnulinux.org/parabolaweb.git
_gitbranch=master

. /usr/bin/libremessages

download() {
	msg "Connecting to GIT server...."
	cd "$_install_dir"
	if [[ -d ${_gitname} ]]; then
		msg2 "Updating existing tree"
		cd ${_gitname} && git pull ${_gitroot}
	else
		msg2 "Cloning tree"
		git clone ${_gitroot} ${_gitname}
		cd ${_gitname}
	fi
	git checkout ${_gitbranch}
	msg "GIT checkout done or server timeout"
}

clean() {
	msg "Purging old .pyc files...."
	cd "$_install_dir/$_gitname"
	find . -name '*.pyc' -delete
}

configure() {
	msg "Checking configuration...."
	cd "$_install_dir/$_gitname"
	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
}

migrate() {
	msg "Updating database...."
	msg2 "Running migrations...."
	./manage.py migrate
	msg2 "Loading fixtures...."
	./manage.py loaddata */fixtures/*.json
}

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

	[[ ! -d "$_install_dir" ]] && mkdir "$_install_dir"

	download
	clean
	configure
	clean
	migrate

	msg "Checking media/admin_media symlink...."
	if [ ! -e media/admin-media ]; then
		rm media/admin_media
		ln -s /usr/lib/python2.7/site-packages/django/contrib/admin/media media/admin_media
	fi
}

main "$@"