##
##  clamshell.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:         clamshell
Summary:      Standlone OpenID Server
URL:          http://wiki.guruj.net/Clamshell!Home
Vendor:       Stephen Bounds
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      GPL
Version:      0.6.8
Release:      20090705

#   list of sources
Source0:      http://wiki.guruj.net/pages/Clamshell/_files/clamshell-%{version}.zip
Source1:      clamshell.conf

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, infozip
PreReq:       OpenPKG, openpkg >= 20160101
PreReq:       apache
PreReq:       apache-php
PreReq:       apache-php::with_bc = yes
PreReq:       apache-php::with_session = yes

%description
    Clamshell is an OpenID server.

%track
    prog clamshell = {
        version   = %{version}
        url       = http://wiki.guruj.net/Clamshell!Download
        regex     = clamshell-(__VER__)\.zip
    }

%prep
    %setup -q -T -c
    unzip -q -x %{SOURCE0}

%build

%install
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/clamshell \
        $RPM_BUILD_ROOT%{l_prefix}/share/clamshell \
        $RPM_BUILD_ROOT%{l_prefix}/var/clamshell
    %{l_shtool} subst \
        -e 's;conf/prefs\.module;%{l_prefix}/etc/clamshell/clamshell.conf;' \
        clamshell/modules/config.module
    %{l_shtool} install -c -m 644 \
        %{SOURCE clamshell.conf} $RPM_BUILD_ROOT%{l_prefix}/etc/clamshell/
    %{l_shtool} subst \
        -e 's;users/;%{l_prefix}/var/clamshell/;' \
        clamshell/modules/profile.module
    rm -f clamshell/[A-Z]*
    cp -rp \
        clamshell/.htaccess \
        clamshell/clamshell.php \
        clamshell/locale \
        clamshell/modules \
        clamshell/templates \
        $RPM_BUILD_ROOT%{l_prefix}/share/clamshell/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/etc/clamshell' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/share/clamshell' \
        '%attr(-,%{l_nusr},%{l_ngrp}) %{l_prefix}/var/clamshell'

%files -f files

%clean

%post
    if [ ".$1" = .1 ]; then
        #   add hook to Apache configuration
        apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
        if [ -f $apacheconf ]; then
            ( echo "Alias /clamshell $RPM_INSTALL_PREFIX/share/clamshell"
              echo "<Directory $RPM_INSTALL_PREFIX/share/clamshell>"
              echo "    Order allow,deny"
              echo "    Allow from all"
              echo "    AllowOverride all"
              echo "</Directory>"
            ) | $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -a -i "$RPM_INSTALL_PREFIX:clamshell" $apacheconf
        fi

        #   display final hints on initial installation
        ( echo "1. To complete this installation of Clamshell please start"
          echo "   your Apache webserver:"
          echo "     \$ $RPM_INSTALL_PREFIX/bin/openpkg rc apache start"
          echo ""
          echo "2. Enter Clamshell by connecting with a browser to:"
          echo "     http://<hostname>/clamshell/?admin=true"
          echo "   Login as 'admin' (with initial password 'admin') to"
          echo "   initialize the admin user credentials and then please"
          echo "   immediately change the 'admin' password to a custom one!"
          echo ""
          echo "3. You can now either use"
          echo "     http://<hostname>/clamshell/<username>     or"
          echo "     http://<hostname>/clamshell/?u=<username>"
          echo "   for the OpenID of <username> or any arbitrary URL"
          echo "   if you include into its output:"
          echo "     <link rel=\"openid.server\""
          echo "           href=\"http://<hostname>/clamshell/<username>\">"
          echo "     <link rel=\"openid.delegate\""
          echo "           href=\"http://<hostname>/clamshell/<username>\">"
          echo ""
          echo "4. Test your OpenID installation via:"
          echo "     http://www.openidenabled.com/resources/openid-test/"
        ) | %{l_rpmtool} msg -b -t notice
    fi

%preun
    #   before erase, remove database
    [ $1 -eq 0 ] || exit 0
    rm -f  $RPM_INSTALL_PREFIX/var/clamshell/* >/dev/null 2>&1 || true
    exit 0

%postun
    if [ ".$1" = .0 ]; then
        #   remove hook from Apache configuration
        apacheconf="$RPM_INSTALL_PREFIX/etc/apache/apache.conf"
        if [ -f $apacheconf ]; then
            $RPM_INSTALL_PREFIX/lib/openpkg/rpmtool config \
                -r -i "$RPM_INSTALL_PREFIX:clamshell" $apacheconf
        fi
    fi

