????
Current Path : /usr/bin/ |
Current File : //usr/bin/rpmdev-newspec |
#!/bin/bash # rpmdev-newspec -- generate new rpm .spec file from template # # Copyright (c) Warren Togami <warren@togami.com>, # Ville Skyttä <ville.skytta at iki.fi> # # 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 version() { cat <<EOF rpmdev-newspec version 1.2 Copyright (c) Warren Togami <warren@togami.com>, Ville Skyttä <ville.skytta at iki.fi> 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. EOF } help() { cat <<EOF rpmdev-newspec generates new rpm .spec files from templates. EOF usage echo "" echo "Report bugs at <https://bugzilla.redhat.com/>, component rpmdevtools," echo "or at <https://fedorahosted.org/rpmdevtools/>." } usage() { # Don't emit available types at build time to avoid them from being # embedded in the man page. types= if [ -z "$RPM_BUILD_ROOT" ] ; then indent=" " types=$(ls $SPECDIR/spectemplate-*.spec 2>/dev/null | \ sed 's,.*spectemplate-,,;s,\.spec$,,' | tr '\n' ' ' | \ fmt -w 60 | sed "s/^/$indent/") [ -z "$types" ] && types="${indent}None ($SPECDIR/spectemplate-*.spec)" fi cat <<EOF Usage: rpmdev-newspec [option]... [appname[.spec]] Options: -o FILE, --output FILE Output the specfile to FILE. "-" means stdout. The default is derived from <appname>, or "$DEFSPEC" if <appname> is not given. -t TYPE, --type TYPE Force use of the TYPE spec template. The default is guessed from <appname>, falling back to "$DEFTYPE" if the guesswork does not result in a more specific one or if <appname> is not given.${types:+ Available types: $types} -m, --macros Emit templates using macros instead of shell style variables. -h, --help Show this usage message and exit. -v, --version Print version information and exit. System wide configuration file is $CONFIG. EOF } appname= specfile= spectype= specfile_set= while [ -n "$1" ] ; do case "$1" in -t|--type) shift spectype="$1" ;; -o|--output) shift specfile="$1" specfile_set=1 case "$specfile" in *.spec) [ -z "$appname" ] && appname="$(basename $1 .spec)" ;; esac ;; -m|--macros) NEWSPEC_PREFER_MACROS=1 ;; -h|--help) help exit 0 ;; -v|--version) version exit 0 ;; *.spec) [ -z "$specfile" ] && specfile="$1" 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 ;; [Pp]y*) spectype=python ;; ruby-*|ocaml-*|R-*) spectype="${appname%%-*}" ;; lib*|*-lib|*-libs) spectype=lib ;; *-fonts|*-fonts-simple) spectype=fonts-simple appname="${appname%%-simple}" specfilter="; s/<FONTNAME>/${appname%%-fonts}/" [ -n "$specfile_set" ] || specfile="$appname.spec" ;; *-fonts-multi) spectype=fonts-multi appname="${appname%%-multi}" specfilter="; s/<FONTNAME>/${appname%%-fonts}/" [ -n "$specfile_set" ] || specfile="$appname.spec" ;; *) 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