##
##  rpmpopt -- OpenPKG RPM POPT Configuration
##  Copyright (c) 2000-2006 OpenPKG Foundation e.V. <http://openpkg.net/>
##  Copyright (c) 2000-2006 Ralf S. Engelschall <http://engelschall.com/>
##
##  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.
##
##  The purpose of this configuration file is to extend and override
##  the "rpmpopt" directives in the default RPM POPT configuration with
##  OpenPKG specific extensions and adjustments.
##

#   backward compatibility for old RPM extensions
rpm exec --stowaway  echo "install \"openpkg-tools\" and use \"openpkg stowaway\" now please."
rpm exec --makeproxy echo "install \"openpkg-tools\" and use \"openpkg makeproxy\" now please."
rpm exec --fetch     echo "install \"openpkg-tools\" and use \"openpkg fetch\" now please."

#   RPM exentsion: "rpm -bs --[no]restriction"
rpm alias --restriction   --define "restriction yes" \
    --POPTdesc=$"exclude %NoSource files in .src.rpm"
rpm alias --norestriction --define "restriction no" \
    --POPTdesc=$"include %NoSource files in .src.rpm"

#   RPM extension: "rpm --with[out] <name>"
rpm alias --with --define "with_!#:+ yes" \
    --POPTdesc=$"set '%option with_<name> yes'" \
    --POPTargs=$"<name>"
rpm alias --without --define "with_!#:+ no" \
    --POPTdesc=$"set '%option with_<name> no'" \
    --POPTargs=$"<name>"

#   RPM extension: "rpm --option <name> <value>"
rpm alias --option --define "!#:+ !#:+" \
    --POPTdesc=$"set '%option <name> <value>'" \
    --POPTargs=$"<name> <value>"

#   RPM extension: "rpm --tag <string>"
rpm alias --tag --define "l_tag_fmt !#:+" \
    --POPTdesc=$"set 'binary package filename tag'" \
    --POPTargs=$"<string>"

#   RPM extension: "rpm --db-{build,rebuild,cleanup,fixate}"
rpm exec --db-build   rpmdb --build \
    --POPTdesc=$"RPM database administration: build new database (destructive operation; you have to know what you are doing)"
rpm exec --db-rebuild rpmdb --rebuild \
    --POPTdesc=$"RPM database administration: rebuild new from old database (upgrading operation; reasonable after upgrades or on DB corruption)"
rpm exec --db-cleanup rpmdb --cleanup \
    --POPTdesc=$"RPM database administration: cleanup existing database (cleaning operation; reasonable after DB out-of-sync situations)"
rpm exec --db-fixate  rpmdb --fixate \
    --POPTdesc=$"RPM database administration: fixate existing database (harmless operation; for fixating files only)"

#   RPM extension: "rpm --db-private ..."
rpm alias --db-private --define "_rpmdb_private yes" \
    --POPTdesc=$"operate RPM database in Berkeley-DB DB_PRIVATE mode"

#   RPM extension: "rpm --track"
rpm alias --track -bt \
    --POPTdesc=$"run package vendor source tracking script (%track)"

#   RPM extension: "rpm --track-dump"
rpm alias --track-dump -bt --define '___track_dump yes' \
    --POPTdesc=$"dump the vendor source tracking script (%track)"

#   RPM extension: "rpm --test"
rpm alias --test -q --qf '%{TEST}\n' \
    --pipe "grep -v \(none\) | @l_prefix@/lib/openpkg/bash" \
    --POPTdesc=$"run package run-time test script (%test)"

#   RPM adjustment: "rpm --setperms ..."
rpm alias --setperms -q --qf \
    '[\[ -h %{FILENAMES:shescape} \] || chmod %7.7{FILEMODES:octal} %{FILENAMES:shescape}\n]' \
    --pipe "grep -v '(none)' | sed 's/chmod .../chmod /' | @l_prefix@/lib/openpkg/bash" \
    --POPTdesc=$"set permissions of files in a package"

#   RPM adjustment: "rpm --setugids ..."
rpm alias --setugids -q --qf \
    '[run %{FILEUSERNAME:shescape} %{FILEGROUPNAME:shescape} %{FILENAMES:shescape}\n]' \
    --pipe "(echo 'run () { chown -- \"$1\" \"$3\"; chgrp -- \"$2\" \"$3\"; }'; grep -v '(none)') | @l_prefix@/lib/openpkg/bash" \
    --POPTdesc=$"set user/group ownership of files in a package"

#   RPM adjustment: improved and cleaned up "rpm -i/--info"
rpmq alias --info --qf '\
Name:     %-25{NAME} Source RPM:   %{SOURCERPM}\n\
Version:  %-25{VERSION} Signature:    %|DSAHEADER?{dsa:%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{rsa:%{RSAHEADER:pgpsig}}:{%|SIGGPG?{gpg:%{SIGGPG:pgpsig}}:{%|SIGPGP?{pgp:%{SIGPGP:pgpsig}}:{%|SIGMD5?{md5:%{SIGMD5}}:{(none)}|}|}|}|}|\n\
Release:  %-25{RELEASE} Build Host:   %{BUILDHOST}\n\
Group:    %-25{GROUP} Build System: %{ARCH}-%{OS}\n\
Class:    %-25{CLASS} Build Time:   %{BUILDTIME:date}\n\
Distrib:  %-25{DISTRIBUTION} Install Time: %|INSTALLTIME?{%{INSTALLTIME:date}}:{(not installed)}|\n\
License:  %-25{LICENSE} Install Size: %{SIZE} bytes\n\
Packager: %-25{PACKAGER} Relocations:  %|PREFIXES?{[%{PREFIXES} ]}:{(not relocateable)}|\n\
Vendor:   %{VENDOR}\n\
Summary:  %{SUMMARY}\n\
URL:      %{URL}\n\
Description:\n%{DESCRIPTION}\n\
%|PROVIDENAME?{Provides:\n\
[    %{PROVIDENAME} %|PROVIDEFLAGS?{%{PROVIDEFLAGS:depflags} %{PROVIDEVERSION}}:{}|\n]}:{}|\
' --POPTdesc=$"list descriptive information from package(s)"

