colab.spec
4.44 KB
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
%define name colab
%define version 2.0a2
%define unmangled_version 2.0a2
%define release 1
%define buildvenv /var/tmp/%{name}-%{version}
Summary: Collaboration platform for communities
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{name}-%{unmangled_version}.tar.gz
License: GPLv2
Group: Development/Tools
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
Vendor: Sergio Oliveira <sergio@tracy.com.br>
Url: https://github.com/colab-community/colab
BuildArch: noarch
BuildRequires: colab-deps, python-virtualenv
Requires: colab-deps, solr, mailman-api
%description
Integrated software development platform.
%prep
%setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version}
%build
# install colab into virtualenv to make sure dependencies are OK
rm -rf %{buildvenv}
cp -r /usr/lib/colab %{buildvenv}
PATH=%{buildvenv}/bin:$PATH pip install --no-index .
virtualenv --relocatable %{buildvenv}
# cleanup virtualenv
rpm -ql colab-deps | sed '/^\/usr\/lib\/colab\// !d; s#/usr/lib/colab/##' > cleanup.list
while read f; do
if [ -f "%{buildvenv}/$f" ]; then
rm -f "%{buildvenv}/$f"
fi
done < cleanup.list
rm -f cleanup.list
find %{buildvenv} -type d -empty -delete
%install
mkdir -p %{buildroot}/etc/colab
mkdir -p %{buildroot}/usr/lib
# install virtualenv
rm -rf %{buildroot}/usr/lib/colab
cp -r %{buildvenv} %{buildroot}/usr/lib/colab
mkdir -p %{buildroot}/%{_bindir}
cat > %{buildroot}/%{_bindir}/colab-admin <<EOF
#!/bin/sh
set -e
if [ "$USER" = colab ]; then
exec /usr/lib/colab/bin/colab-admin "\$@"
else
exec sudo -u colab /usr/lib/colab/bin/colab-admin "\$@"
fi
EOF
chmod +x %{buildroot}/%{_bindir}/colab-admin
# install initscript
install -d -m 0755 %{buildroot}/lib/systemd/system
install -m 0644 misc/lib/systemd/system/colab.service %{buildroot}/lib/systemd/system
# install crontab
install -d -m 0755 %{buildroot}/etc/cron.d
install -m 0644 misc/etc/cron.d/colab %{buildroot}/etc/cron.d
%clean
rm -rf $RPM_BUILD_ROOT
rm -rf %{buildvenv}
%files
/usr/lib/colab
%{_bindir}/*
/etc/cron.d/colab
/lib/systemd/system/colab.service
%post
groupadd colab || true
if ! id colab; then
useradd --system --gid colab --home-dir /usr/lib/colab --no-create-home colab
fi
# only applies if there is a local PostgreSQL server
if [ -x /usr/bin/postgres ]; then
# start/enable the service
postgresql-setup initdb || true
systemctl start postgresql
systemctl enable postgresql
if [ "$(sudo -u postgres -i psql --quiet --tuples-only -c "select count(*) from pg_user where usename = 'colab';")" -eq 0 ]; then
# create user
sudo -u postgres -i createuser colab
fi
if [ "$(sudo -u postgres -i psql --quiet --tuples-only -c "select count(1) from pg_database where datname = 'colab';")" -eq 0 ]; then
# create database
sudo -u postgres -i createdb --owner=colab colab
fi
mkdir -p /etc/colab
if [ ! -f /etc/colab/settings.yaml ]; then
SECRET_KEY=$(openssl rand -hex 32)
cat > /etc/colab/settings.yaml <<EOF
## Set to false in production
DEBUG: true
TEMPLATE_DEBUG: true
## System admins
ADMINS: &admin
-
- John Foo
- john@example.com
-
- Mary Bar
- mary@example.com
MANAGERS: *admin
COLAB_FROM_ADDRESS: '"Colab" <noreply@example.com>'
SERVER_EMAIL: '"Colab" <noreply@example.com>'
EMAIL_HOST: localhost
EMAIL_PORT: 25
EMAIL_SUBJECT_PREFIX: '[colab]'
SECRET_KEY: '$SECRET_KEY'
SITE_URL: 'http://localhost:8000/'
BROWSERID_AUDIENCES:
- http://localhost:8000
# - http://example.com
# - https://example.org
# - http://example.net
ALLOWED_HOSTS:
- localhost
# - example.com
# - example.org
# - example.net
## Disable indexing
ROBOTS_NOINDEX: false
#PROXIED_APPS:
# gitlab:
# upstream: 'http://localhost:8080/gitlab/'
EOF
chown root:colab /etc/colab/settings.yaml
chmod 0640 /etc/colab/settings.yaml
fi
mkdir -p /etc/colab/settings.d
if [ ! -f /etc/colab/settings.d/00-database.yaml ]; then
cat > /etc/colab/settings.d/00-database.yaml <<EOF
DATABASES:
default:
ENGINE: django.db.backends.postgresql_psycopg2
NAME: colab
USER: colab
EOF
chown root:colab /etc/colab/settings.d/00-database.yaml
chmod 0640 /etc/colab/settings.d/00-database.yaml
fi
fi
if [ -f /etc/colab/settings.yaml ]; then
colab-admin migrate
fi
mkdir -p /var/lib/colab-assets
chown colab:colab /var/lib/colab-assets
mkdir -p /usr/share/nginx/
ln -s /var/lib/colab-assets /usr/share/nginx/colab
if [ -f /etc/colab/settings.yaml ]; then
yes yes | colab-admin collectstatic
fi