Commit 4ca3bff15c326809189260ec7023bc79a056769b

Authored by Antonio Terceiro
1 parent f7189f66

Add RPM spec file

Signed-off-by: Antonio Terceiro <terceiro@softwarelivre.org>
Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Showing 1 changed file with 173 additions and 0 deletions   Show diff stats
colab.spec 0 → 100644
... ... @@ -0,0 +1,173 @@
  1 +%define name colab
  2 +%define version 2.0a1
  3 +%define unmangled_version 2.0a1
  4 +%define release 1
  5 +%define buildvenv /var/tmp/%{name}-%{version}
  6 +
  7 +Summary: Collaboration platform for communities
  8 +Name: %{name}
  9 +Version: %{version}
  10 +Release: %{release}
  11 +Source0: %{name}-%{unmangled_version}.tar.gz
  12 +License: GPLv2
  13 +Group: Development/Tools
  14 +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
  15 +Prefix: %{_prefix}
  16 +Vendor: Sergio Oliveira <sergio@tracy.com.br>
  17 +Url: https://github.com/colab-community/colab
  18 +BuildArch: noarch
  19 +BuildRequires: colab-deps, python-virtualenv
  20 +Requires: colab-deps, solr, mailman-api
  21 +
  22 +%description
  23 +Integrated software development platform.
  24 +
  25 +%prep
  26 +%setup -n %{name}-%{unmangled_version} -n %{name}-%{unmangled_version}
  27 +
  28 +%build
  29 +# install colab into virtualenv to make sure dependencies are OK
  30 +rm -rf %{buildvenv}
  31 +cp -r /usr/lib/colab %{buildvenv}
  32 +PATH=%{buildvenv}/bin:$PATH pip install --no-index .
  33 +virtualenv --relocatable %{buildvenv}
  34 +
  35 +# cleanup virtualenv
  36 +rpm -ql colab-deps | sed '/^\/usr\/lib\/colab\// !d; s#/usr/lib/colab/##' > cleanup.list
  37 +while read f; do
  38 + if [ -f "%{buildvenv}/$f" ]; then
  39 + rm -f "%{buildvenv}/$f"
  40 + fi
  41 +done < cleanup.list
  42 +rm -f cleanup.list
  43 +find %{buildvenv} -type d -empty -delete
  44 +
  45 +%install
  46 +mkdir -p %{buildroot}/etc/colab
  47 +mkdir -p %{buildroot}/usr/lib
  48 +
  49 +# install virtualenv
  50 +rm -rf %{buildroot}/usr/lib/colab
  51 +cp -r %{buildvenv} %{buildroot}/usr/lib/colab
  52 +mkdir -p %{buildroot}/%{_bindir}
  53 +cat > %{buildroot}/%{_bindir}/colab-admin <<EOF
  54 +#!/bin/sh
  55 +set -e
  56 +
  57 +if [ "$USER" = colab ]; then
  58 + exec /usr/lib/colab/bin/colab-admin "\$@"
  59 +else
  60 + exec sudo -u colab /usr/lib/colab/bin/colab-admin "\$@"
  61 +fi
  62 +EOF
  63 +chmod +x %{buildroot}/%{_bindir}/colab-admin
  64 +
  65 +# install initscript
  66 +install -d -m 0755 %{buildroot}/lib/systemd/system
  67 +install -m 0644 misc/lib/systemd/system/colab.service %{buildroot}/lib/systemd/system
  68 +# install crontab
  69 +install -d -m 0755 %{buildroot}/etc/cron.d
  70 +install -m 0644 misc/etc/cron.d/colab %{buildroot}/etc/cron.d
  71 +
  72 +%clean
  73 +rm -rf $RPM_BUILD_ROOT
  74 +rm -rf %{buildvenv}
  75 +
  76 +%files
  77 +/usr/lib/colab
  78 +%{_bindir}/*
  79 +/etc/cron.d/colab
  80 +/lib/systemd/system/colab.service
  81 +
  82 +%post
  83 +groupadd colab || true
  84 +if ! id colab; then
  85 + useradd --system --gid colab --home-dir /usr/lib/colab --no-create-home colab
  86 +fi
  87 +
  88 +# only applies if there is a local PostgreSQL server
  89 +if [ -x /usr/bin/postgres ]; then
  90 +
  91 + # start/enable the service
  92 + postgresql-setup initdb || true
  93 + systemctl start postgresql
  94 + systemctl enable postgresql
  95 +
  96 + if [ "$(sudo -u postgres -i psql --quiet --tuples-only -c "select count(*) from pg_user where usename = 'colab';")" -eq 0 ]; then
  97 + # create user
  98 + sudo -u postgres -i createuser colab
  99 + fi
  100 +
  101 + if [ "$(sudo -u postgres -i psql --quiet --tuples-only -c "select count(1) from pg_database where datname = 'colab';")" -eq 0 ]; then
  102 + # create database
  103 + sudo -u postgres -i createdb --owner=colab colab
  104 + fi
  105 +
  106 + mkdir -p /etc/colab
  107 +
  108 + if [ ! -f /etc/colab/settings.yaml ]; then
  109 + SECRET_KEY=$(openssl rand -hex 32)
  110 + cat > /etc/colab/settings.yaml <<EOF
  111 +## Set to false in production
  112 +DEBUG: true
  113 +TEMPLATE_DEBUG: true
  114 +
  115 +## System admins
  116 +ADMINS: &admin
  117 + -
  118 + - John Foo
  119 + - john@example.com
  120 + -
  121 + - Mary Bar
  122 + - mary@example.com
  123 +
  124 +MANAGERS: *admin
  125 +
  126 +COLAB_FROM_ADDRESS: '"Colab" <noreply@example.com>'
  127 +SERVER_EMAIL: '"Colab" <noreply@example.com>'
  128 +
  129 +EMAIL_HOST: localhost
  130 +EMAIL_PORT: 25
  131 +EMAIL_SUBJECT_PREFIX: '[colab]'
  132 +
  133 +SECRET_KEY: '$SECRET_KEY'
  134 +
  135 +SITE_URL: 'http://localhost:8000/'
  136 +BROWSERID_AUDIENCES:
  137 + - http://localhost:8000
  138 +# - http://example.com
  139 +# - https://example.org
  140 +# - http://example.net
  141 +
  142 +ALLOWED_HOSTS:
  143 + - localhost
  144 +# - example.com
  145 +# - example.org
  146 +# - example.net
  147 +
  148 +## Disable indexing
  149 +ROBOTS_NOINDEX: false
  150 +EOF
  151 + chown root:colab /etc/colab/settings.yaml
  152 + chmod 0640 /etc/colab/settings.yaml
  153 + fi
  154 +
  155 + mkdir -p /etc/colab/settings.d
  156 +
  157 + if [ ! -f /etc/colab/settings.d/00-database.yaml ]; then
  158 + cat > /etc/colab/settings.d/00-database.yaml <<EOF
  159 +DATABASES:
  160 + default:
  161 + ENGINE: django.db.backends.postgresql_psycopg2
  162 + NAME: colab
  163 + USER: colab
  164 +EOF
  165 + chown root:colab /etc/colab/settings.d/00-database.yaml
  166 + chmod 0640 /etc/colab/settings.d/00-database.yaml
  167 + fi
  168 +
  169 +fi
  170 +
  171 +if [ -f /etc/colab/settings.yaml ]; then
  172 + colab-admin migrate
  173 +fi
... ...