|
| 1 | +#!/bin/sh |
| 2 | +# Copyright (c) 2024, Red Hat, Inc. |
| 3 | +# |
| 4 | +# All rights reserved. |
| 5 | +# |
| 6 | +# Redistribution and use in source and binary forms, with or without |
| 7 | +# modification, are permitted provided that the following conditions |
| 8 | +# are met: |
| 9 | +# |
| 10 | +# 1. Redistributions of source code must retain the above copyright |
| 11 | +# notice, this list of conditions and the following disclaimer. |
| 12 | +# 2. Redistributions in binary form must reproduce the above copyright |
| 13 | +# notice, this list of conditions and the following disclaimer in the |
| 14 | +# documentation and/or other materials provided with the |
| 15 | +# distribution. |
| 16 | +# 3. Neither the name of the Red Hat nor the names of its |
| 17 | +# contributors may be used to endorse or promote products derived |
| 18 | +# from this software without specific prior written permission. |
| 19 | +# |
| 20 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | +# |
| 32 | +# Authors: Mikolaj Izdebski <mizdebsk@redhat.com> |
| 33 | + |
| 34 | +set -eu |
| 35 | +jpbindingdir="@{jpbindingdir}" |
| 36 | + |
| 37 | +if [ -z "${RPM_BUILD_ROOT:-}" ]; then |
| 38 | + echo RPM_BUILD_ROOT env variable has not been set >&2 |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | +if [ -z "${RPM_SPECPARTS_DIR:-}" ]; then |
| 42 | + echo RPM_BUILD_ROOT env variable has not been set >&2 |
| 43 | + exit 1 |
| 44 | +fi |
| 45 | + |
| 46 | +rpmname="" |
| 47 | +basepkg="" |
| 48 | +pkg="" |
| 49 | +ghost="" |
| 50 | +target="" |
| 51 | +variant="" |
| 52 | +provides="" |
| 53 | +requires="" |
| 54 | +recommends="" |
| 55 | +with_meta_requires=true |
| 56 | +description="" |
| 57 | +with_description=true |
| 58 | +summary="" |
| 59 | +with_summary=true |
| 60 | +with_files=true |
| 61 | +with_package=true |
| 62 | +with_install=true |
| 63 | +verbose=false |
| 64 | + |
| 65 | +while [ $# -gt 0 ]; do |
| 66 | + case "$1" in |
| 67 | + --rpm-name) |
| 68 | + rpmname="$2" |
| 69 | + shift |
| 70 | + ;; |
| 71 | + --base-pkg) |
| 72 | + basepkg="$2" |
| 73 | + shift |
| 74 | + ;; |
| 75 | + --binding-pkg) |
| 76 | + pkg="$2" |
| 77 | + shift |
| 78 | + ;; |
| 79 | + --ghost) |
| 80 | + ghost="$2" |
| 81 | + shift |
| 82 | + ;; |
| 83 | + --target) |
| 84 | + target="$2" |
| 85 | + shift |
| 86 | + ;; |
| 87 | + --variant) |
| 88 | + variant="$2" |
| 89 | + shift |
| 90 | + ;; |
| 91 | + --provides) |
| 92 | + provides="${provides} |
| 93 | +Provides: $2" |
| 94 | + shift |
| 95 | + ;; |
| 96 | + --requires) |
| 97 | + requires="${requires} |
| 98 | +Requires: $2" |
| 99 | + shift |
| 100 | + ;; |
| 101 | + --recommends) |
| 102 | + recommends="${recommends} |
| 103 | +Recommends: $2" |
| 104 | + shift |
| 105 | + ;; |
| 106 | + --no-meta-requires) |
| 107 | + with_meta_requires=false |
| 108 | + ;; |
| 109 | + --description) |
| 110 | + description="$2" |
| 111 | + shift |
| 112 | + ;; |
| 113 | + --no-description) |
| 114 | + with_description=false |
| 115 | + ;; |
| 116 | + --summary) |
| 117 | + summary="$2" |
| 118 | + shift |
| 119 | + ;; |
| 120 | + --no-summary) |
| 121 | + with_summary=false |
| 122 | + ;; |
| 123 | + --no-files) |
| 124 | + with_files=false |
| 125 | + ;; |
| 126 | + --no-package) |
| 127 | + with_package=false |
| 128 | + ;; |
| 129 | + --no-install) |
| 130 | + with_install=false |
| 131 | + ;; |
| 132 | + --verbose) |
| 133 | + verbose=true |
| 134 | + ;; |
| 135 | + *) |
| 136 | + echo "Unknown option $1" >&2 |
| 137 | + exit 1 |
| 138 | + esac |
| 139 | + shift |
| 140 | +done |
| 141 | + |
| 142 | +debug() |
| 143 | +{ |
| 144 | + if ${verbose}; then |
| 145 | + echo "$@" >&2 |
| 146 | + fi |
| 147 | +} |
| 148 | + |
| 149 | +if [ -z "${basepkg}" ]; then |
| 150 | + if [ -n "${rpmname}" ]; then |
| 151 | + basepkg="${rpmname}" |
| 152 | + debug "Assuming default --base-pkg ${basepkg}" |
| 153 | + else |
| 154 | + echo "Missing required option --base-pkg" >&2 |
| 155 | + exit 1 |
| 156 | + fi |
| 157 | +fi |
| 158 | + |
| 159 | +if [ -z "${ghost}" ]; then |
| 160 | + echo "Missing required option --ghost" >&2 |
| 161 | + exit 1 |
| 162 | +fi |
| 163 | + |
| 164 | +if [ -z "${target}" ]; then |
| 165 | + echo "Missing required option --target" >&2 |
| 166 | + exit 1 |
| 167 | +fi |
| 168 | + |
| 169 | +if [ -z "${variant}" ]; then |
| 170 | + echo "Missing required option --variant" >&2 |
| 171 | + exit 1 |
| 172 | +fi |
| 173 | + |
| 174 | +if [ -z "${pkg}" ]; then |
| 175 | + pkg="${basepkg}-${variant}" |
| 176 | + debug "Assuming default --binding-pkg ${pkg}" |
| 177 | +fi |
| 178 | + |
| 179 | +if [ -z "${summary}" ]; then |
| 180 | + summary="${basepkg} binding for ${variant}" |
| 181 | +fi |
| 182 | + |
| 183 | +if [ -z "${description}" ]; then |
| 184 | + description="Configures ${basepkg} to work with ${variant}." |
| 185 | +fi |
| 186 | + |
| 187 | +sp=${RPM_SPECPARTS_DIR}/${pkg}.specpart |
| 188 | +: >${sp} |
| 189 | + |
| 190 | +if ${with_package}; then |
| 191 | + echo "%package -n ${pkg}" >>${sp} |
| 192 | + if ${with_summary}; then |
| 193 | + echo "Summary: ${summary}" >>${sp} |
| 194 | + fi |
| 195 | + echo "${provides}" >>${sp} |
| 196 | + echo "${requires}" >>${sp} |
| 197 | + echo "${recommends}" >>${sp} |
| 198 | + echo "Requires: javapackages-tools" >>${sp} |
| 199 | + if ${with_meta_requires}; then |
| 200 | + echo "Requires(meta): ${basepkg}" >>${sp} |
| 201 | + fi |
| 202 | + echo "" >>${sp} |
| 203 | +fi |
| 204 | + |
| 205 | +if ${with_description}; then |
| 206 | + echo "%description -n ${pkg}" >>${sp} |
| 207 | + echo "${description}" | fold >>${sp} |
| 208 | + echo "" >>${sp} |
| 209 | +fi |
| 210 | + |
| 211 | +if ${with_files}; then |
| 212 | + echo "%files -n ${pkg}" >>${sp} |
| 213 | + echo "%ghost ${jpbindingdir}/${ghost}" >>${sp} |
| 214 | + echo "%dir ${jpbindingdir}/${ghost}.d" >>${sp} |
| 215 | + echo "${jpbindingdir}/${ghost}.d/${variant}" >>${sp} |
| 216 | +fi |
| 217 | + |
| 218 | +if ${verbose}; then |
| 219 | + debug "Added the following package:" |
| 220 | + sed 's/./ :: &/' ${sp} >&2 |
| 221 | +fi |
| 222 | + |
| 223 | +if ${with_install}; then |
| 224 | + install -d -m 755 ${RPM_BUILD_ROOT}${jpbindingdir}/${ghost}.d/ |
| 225 | + ln -sf ${target} ${RPM_BUILD_ROOT}${jpbindingdir}/${ghost}.d/${variant} |
| 226 | +fi |
0 commit comments