##
##  taskboard.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         taskboard
Summary:      Kanban Task Board
URL:          http://taskboard.matthewross.me/
Vendor:       Matthew Ross
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      MIT
Version:      0.3.1
Release:      20160125

#   list of sources
Source0:      https://github.com/kiswa/TaskBoard/archive/v%{version}.tar.gz
Source1:      rc.taskboard
Source2:      taskboard-apache.conf
Patch0:       taskboard.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
PreReq:       apache
PreReq:       apache-php
PreReq:       apache-php::with_json = yes
PreReq:       apache-php::with_session = yes
PreReq:       apache-php::with_mbstring = yes
PreReq:       apache-php::with_ctype = yes
PreReq:       apache-php::with_iconv = yes
PreReq:       apache-php::with_mhash = yes
PreReq:       apache-php::with_sqlite = yes

%description
    Taskboard is a Kanban-inspired app for keeping track of things that
    need to get done. The goal of TaskBoard is to provide a simple and
    clean interface to a functional and minimal application for keeping
    track of tasks.

%track
    prog taskboard = {
        version   = %{version}
        url       = https://github.com/kiswa/TaskBoard/releases
        regex     = v(__VER__)\.tar\.gz
    }

%prep
    %setup -q -n TaskBoard-%{version}
    %patch -p0

%build
    rm -f LICENSE VERSION readme.md
    %{l_shtool} subst \
        -e 's;sqlite:taskboard\.db;sqlite:%{l_prefix}/var/taskboard/db/taskboard.db;' \
        api/api.php

%install
    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/taskboard \
        $RPM_BUILD_ROOT%{l_prefix}/lib/taskboard \
        $RPM_BUILD_ROOT%{l_prefix}/var/taskboard/run/session \
        $RPM_BUILD_ROOT%{l_prefix}/var/taskboard/log \
        $RPM_BUILD_ROOT%{l_prefix}/var/taskboard/db/uploads

    #   install program
    cp -rp * \
        $RPM_BUILD_ROOT%{l_prefix}/lib/taskboard/
    ln -s ../../../var/taskboard/db/uploads \
        $RPM_BUILD_ROOT%{l_prefix}/lib/taskboard/api/uploads

    #   install default Apache webserver configuration
    l_hostname=`%{l_shtool} echo -e %h`
    l_domainname=`%{l_shtool} echo -e %d | cut -c2-`
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        -e "s;@l_hostname@;$l_hostname;g" \
        -e "s;@l_domainname@;$l_domainname;g" \
        %{SOURCE taskboard-apache.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/taskboard/

    #   install run-command script
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.taskboard} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/taskboard' \
        '%config %attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/etc/taskboard/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/taskboard/*' \
        '%attr(-,%{l_rusr},%{l_rgrp}) %{l_prefix}/var/taskboard/*/*'

%files -f files

%clean

%post
    #   after upgrade, restart service
    if [ $1 -eq 1 ]; then
        ( echo "1. By default, TaskBoard runs its own Apache server on IPv4 address"
          echo "   127.0.0.1, TCP port 8081. Please change this by editing the"
          echo "   \"Listen 127.0.0.1:8081\" directives in the configuration file"
          echo "   $RPM_INSTALL_PREFIX/etc/taskboard/taskboard-apache.conf"
          echo ""
          echo "2. After this optional adjustment, start TaskBoard by running"
          echo "     \$ $RPM_INSTALL_PREFIX/bin/openpkg rc taskboard start"
          echo "   and connect to TaskBoard at"
          echo "     http://127.0.0.1:8081/"
          echo "   and login with user \"admin\" and password \"admin\""
        ) | %{l_rpmtool} msg -b -t notice
    elif [ $1 -eq 2 ]; then
        eval `%{l_rc} taskboard status 2>/dev/null`
        [ ".$taskboard_active" = .yes ] && %{l_rc} taskboard restart
    fi
    exit 0

%preun
    #   before erase, stop service and remove log files
    if [ $1 -eq 0 ]; then
        %{l_rc} phabricator stop 2>/dev/null
        rm -f $RPM_INSTALL_PREFIX/var/phabricator/log/*        >/dev/null 2>&1 || true
        rm -f $RPM_INSTALL_PREFIX/var/phabricator/run/*        >/dev/null 2>&1 || true
        rm -f $RPM_INSTALL_PREFIX/var/phabricator/db/*.db      >/dev/null 2>&1 || true
        rm -f $RPM_INSTALL_PREFIX/var/phabricator/db/uploads/* >/dev/null 2>&1 || true
    fi
    exit 0

