##
##  webmin.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:         webmin
Summary:      Web Interface for Unix System Administration
URL:          http://www.webmin.com/
Vendor:       Jamie Cameron
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Web
License:      BSD-style
Version:      1.560
Release:      20110805

#   list of sources
Source0:      http://download.sourceforge.net/webadmin/webmin-%{version}.tar.gz
Source1:      rc.webmin

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, perl
PreReq:       OpenPKG, openpkg >= 20160101, perl

%description
    Webmin is a web-based interface for system administration for Unix.
    Using any browser that supports tables and forms (and Java for the
    File Manager module), you can manipulate user accounts, Apache, DNS,
    file sharing and so on. Webmin consists of a simple web server, and
    several of CGI programs which directly update system files. The web
    server and all CGI programs are written in Perl using standard modules.

%track
    prog webmin = {
        version   = %{version}
        url       = http://sourceforge.net/projects/webadmin/files/
        regex     = webmin-(__VER__)\.tar\.gz
    }

%prep
    %setup -q
    %{l_shtool} subst \
        -e 's;^[^a-zA-Z0-9]*chown.*$;true;g' \
        -e 's;^[^a-zA-Z0-9]*chgrp.*$;true;g' \
        -e 's;^[^a-zA-Z0-9]*chmod.*$;true;g' \
        -e 's;^.*\(\$perl \-e.*\$port\);# Do not check the server port: \1;g' \
        -e 's/\(.*\)echo "ERROR: The Webmin install script must be run as root.*/\1true; fi; if false; then/g' \
        setup.sh
    for badfname in `find . -name '*\\**' -print | %{l_shtool} subst -e 's;\\*;\\\\\*;g;'`
    do
        gudfname=`echo ${badfname} | %{l_shtool} subst -e 's;\\\\\*;=;'`
        eval mv ${badfname} ${gudfname}
    done

%build

%install
    case "%{l_platform -t}" in
        *-sunos*   ) os="1"  ;;
        *-freebsd* ) os="42" ;;
        *-linux*   ) os="6"  ;;
        * ) echo "platform %{l_platform -t} not supported" 2>&1; exit 1 ;;
    esac
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d \
        $RPM_BUILD_ROOT%{l_prefix}/etc/webmin \
        $RPM_BUILD_ROOT%{l_prefix}/lib/webmin \
        $RPM_BUILD_ROOT%{l_prefix}/var/webmin
    install_dir=$RPM_BUILD_ROOT%{l_prefix}/lib/webmin
    config_dir=$RPM_BUILD_ROOT%{l_prefix}/etc/webmin
    var_dir=$RPM_BUILD_ROOT%{l_prefix}/var/webmin
    upgrading=0
    perl=%{l_prefix}/bin/perl
    os_type=$os
    port=8080
    login='admin'
    password='admin'
    password2='admin'
    ssl=1
    atboot=0
    nostart=1
    nochown=1
    export config_dir var_dir upgrading os_type perl port \
        login password password2 ssl atboot nostart nochown
    ./setup.sh $install_dir 2>&1 >/dev/null
    rm -f $RPM_BUILD_ROOT%{l_prefix}/etc/webmin/uninstall.sh
    %{l_shtool} subst \
        -e "s;$RPM_BUILD_ROOT;;g" \
        $RPM_BUILD_ROOT%{l_prefix}/etc/webmin/* \
        >/dev/null 2>&1
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.webmin} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/webmin/*/config' \
        '%config %{l_prefix}/etc/webmin/*/admin.acl' \
        '%config %{l_prefix}/etc/webmin/config' \
        '%config %{l_prefix}/etc/webmin/miniserv.conf' \
        '%config %{l_prefix}/etc/webmin/miniserv.pem' \
        '%config %{l_prefix}/etc/webmin/miniserv.users' \
        '%config %{l_prefix}/etc/webmin/webmin.acl'

%files -f files

%clean

%post
    #   after upgrade, restart service
    [ $1 -eq 2 ] || exit 0
    eval `%{l_rc} webmin status 2>/dev/null`
    [ ".$webmin_active" = .yes ] && %{l_rc} webmin restart
    exit 0

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

