#!/bin/bash # rpmdev-newspec -- generate new rpm .spec file from template # # Copyright (c) Warren Togami , # Ville Skyttä # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA SPECDIR="/etc/rpmdevtools" DEFTYPE="minimal" DEFSPEC="newpackage.spec" CONFIG="/etc/rpmdevtools/newspec.conf" if [ -f "$CONFIG" ] ; then . "$CONFIG" fi usage() { ret=${1:-0} cat <.spec", or "$DEFSPEC" if appname is not given. -t TYPE Force use of the TYPE spec template. The default is guessed from , falling back to "$DEFTYPE" if the guesswork does not result in a more specific one or if is not given. See $SPECDIR/spectemplate-*.spec for available types. -m Emit templates that use macros instead of shell style variables. -h Show this usage message System wide configuration file is $CONFIG. EOF exit $ret } appname= specfile= spectype= while [ -n "$1" ] ; do case "$1" in -t|--type) shift spectype="$1" ;; -o|--output) shift specfile="$1" ;; -m|--macros) NEWSPEC_PREFER_MACROS=1 ;; -h|--help) usage 0 ;; *.spec) [ -z "$specfile" ] && specfile="$1" [ -z "$appname" ] && appname="$(basename $1 .spec)" ;; *) appname="$1" [ -z "$specfile" ] && specfile="$appname.spec" ;; esac shift done specfilter= if [ -z "$spectype" ] ; then case "$appname" in perl-*) spectype=perl cpandist="${appname##perl-}" specfilter="; s/^%setup.*/%setup -q -n $cpandist-%{version}/ \ ; s|^\\(URL:\\s*\\).*|\1http://search.cpan.org/dist/$cpandist/|" ;; php-pear-*) spectype=php-pear pearname="$(echo ${appname##php-pear-} | tr - _)" specfilter="; s/\\bFoo_Bar\\b/$pearname/" ;; [Pp]y*) spectype=python ;; ruby-*) spectype=ruby ;; lib*|*-lib|*-libs) spectype=lib ;; *-fonts) spectype=fonts specfilter="; s/\\bFONTNAME\\b/${appname%%-fonts}/" ;; *) spectype=$DEFTYPE ;; esac fi tempspec="$SPECDIR/spectemplate-$spectype.spec" if [ ! -f "$tempspec" ] ; then echo "Template \"$tempspec\" not found, exiting." exit 1 fi [ -z "$specfile" ] && specfile="$DEFSPEC" if [ -f "$specfile" ] ; then echo "Output file \"$specfile\" already exists, exiting." exit 2 elif [ "$specfile" = "-" ] ; then specfile=/dev/stdout fi if [ -n "$NEWSPEC_PREFER_MACROS" ] ; then # This assumes templates are written using the shell style variables, # without surrounding curly braces. specfilter="$specfilter \ ; s/\\\$RPM_SOURCE_DIR\\b/%{_sourcedir}/g \ ; s/\\\$RPM_BUILD_DIR\\b/%{_builddir}/g \ ; s/\\\$RPM_OPT_FLAGS\\b/%{optflags}/g \ ; s/\\\$RPM_ARCH\\b/%{_arch}/g \ ; s/\\\$RPM_OS\\b/%{_os}/g \ ; s/\\\$RPM_DOC_DIR\\b/%{_docdir}/g \ ; s/\\\$RPM_PACKAGE_NAME\\b/%{name}/g \ ; s/\\\$RPM_PACKAGE_VERSION\\b/%{version}/g \ ; s/\\\$RPM_PACKAGE_RELEASE\\b/%{release}/g \ ; s/\\\$RPM_BUILD_ROOT\\b/%{buildroot}/g" fi cat "$tempspec" | sed -e "s/^\\(Name:\\s*\\)$/\\1$appname/ $specfilter" \ > "$specfile" if [ "$specfile" != "/dev/stdout" ] ; then echo "Skeleton specfile ($spectype) has been created to \"$specfile\"." fi