File shellinabox.spec of Package shellinabox

#
# spec file for package shellinabox
#
# Copyright (c) 2008-2009 Markus Gutschke <markus@shellinabox.com> and
# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


#
%define pkg_name shellinabox
%define pkg_user %{pkg_name}
%define pkg_service %{pkg_name}d
%define pkg_home %{_localstatedir}/lib/%{pkg_user}
%if ! %{defined _fillupdir}
  %define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif
Name:           shellinabox
#
Version:        2.20+git.1548649128.4f0ecc3
Release:        0
Summary:        AJAX/Web based terminal emulator
License:        SUSE-GPL-2.0-with-openssl-exception
Group:          Productivity/Networking/Web/Utilities
URL:            https://github.com/shellinabox
Source0:        %{pkg_name}-%{version}.tar
# Fix possible buffer overwrite error in launcher.c
#Patch:  launcher-buffer-overwrite.patch
Source1:        %{pkg_name}.service
Source2:        firewalld-service.xml
Source3:        %{pkg_name}.sysconfig
# Required at build-time for verification of post-install scriptlet
BuildRequires:  check-create-certificate
BuildRequires:  firewall-macros
BuildRequires:  libopenssl-devel
BuildRequires:  libtool
BuildRequires:  pam-devel
# shadow is needed for useradd / groupadd
BuildRequires:  shadow
BuildRequires:  zlib-devel
Requires:       check-create-certificate
Requires(pre):  shadow
Requires(post): openssl
Requires(post): %fillup_prereq
Provides:       user(shellinabox)
Provides:       group(shellinabox)

%description
Shell In A Box implements a web server that can export arbitrary command l
ine tools to a web based terminal emulator. This emulator is accessible to
any JavaScript and CSS enabled web browser and does not require any additional
browser plugins.

All client-server communications are encrypted, if SSL/TLS certificates have been
installed.

%prep
%setup -q
#%patch -p1

%build
autoreconf --install
# disable runtime loading (does not work properly),
# link the libraries directly
%configure --disable-runtime-loading
make %{?_smp_mflags}

%install
%make_install

install -d -m 0755      \
    %{buildroot}%{pkg_home}/ \
    %{buildroot}%{_sbindir} \
    %{buildroot}%{_usr}/share/%{pkg_name}

install -p -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{pkg_name}.service

install -p -D -m 0644 %{pkg_name}/*.css %{buildroot}/%{_usr}/share/%{pkg_name}

# configure certificates
mkdir -p %{buildroot}%{_sysconfdir}/%{pkg_name}/certs

# firewall service definition
install -D -m 644 %{SOURCE2} %{buildroot}%{_libexecdir}/firewalld/services/shellinabox.xml

install -p -D -m 0644 %{SOURCE3} %{buildroot}/%{_fillupdir}/sysconfig.%{pkg_name}

ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{pkg_name}

%pre
%service_add_pre %{pkg_name}.service
getent group %{pkg_user} >/dev/null || %{_sbindir}/groupadd -r %{pkg_user}
getent passwd %{pkg_user} >/dev/null || %{_sbindir}/useradd -g %{pkg_user} -s /bin/false -r -c "user for %{pkg_user}" -d %{pkg_home} %{pkg_user}

%post
%service_add_post %{pkg_name}.service
%fillup_only

. %{_sysconfdir}/sysconfig/%{pkg_name}
CERTFILE="$SHELLINABOXD_CERTDIR//certificate.pem"
if [ ! -e "$CERTFILE" ]; then
    echo -e "\nNo shellinabox certificate found, creating one now..."
    if ! %{_sbindir}/check-create-certificate -c -C $CERTFILE.crt -K $CERTFILE.key -B $CERTFILE -D shellinabox -O Shellinabox -U Shellinabox; then
        echo "WARNING: Failed to create certificate for shellinabox" >&2
        exit 1
    fi

    # only combined key is needed
    rm $CERTFILE.crt $CERTFILE.key
    chown shellinabox:shellinabox $CERTFILE

    echo -n "Created certificate: "
    openssl x509 -in $CERTFILE -fingerprint -noout
fi

%firewalld_reload

%preun
%service_del_preun %{pkg_name}.service

%postun
if test -e %{_localstatedir}/run/%{pkg_name}.pid; then
    rm %{_localstatedir}/run/%{pkg_name}.pid
fi
%service_del_postun %{pkg_name}.service

%files

%attr(-,%{pkg_user},%{pkg_user}) %dir %{pkg_home}
%doc %attr(0444,root,root) %{_mandir}/man1/%{pkg_name}d.1*
%doc %{_datadir}/doc/%{pkg_name}
%{_bindir}/%{pkg_service}
%{_unitdir}/%{pkg_name}.service
%{_sbindir}/rc%{pkg_name}
%{_fillupdir}/sysconfig.%{pkg_name}
%dir %{_usr}/share/%{pkg_name}
%{_usr}/share/%{pkg_name}/*.css
%dir %{_sysconfdir}/%{pkg_name}/
%dir %{_sysconfdir}/%{pkg_name}/certs
%dir %{_libexecdir}/firewalld
%dir %{_libexecdir}/firewalld/services
%{_libexecdir}/firewalld/services/shellinabox.xml

%changelog
openSUSE Build Service is sponsored by