ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@fandra.org>
To: devel@linux.iplabs.ru
Subject: [devel] I: specfile cleaner
Date: Sun, 14 Jan 2001 04:20:17 +0300
Message-ID: <20010114042016.A6353@LDV.fandra.org> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 584 bytes --]

Greetings!

Если Вы собираете пакеты, то небольшой "чистильщик" spec-файлов не
повредит.
usage: cleanup_spec specfile1 [specfileN]*


Regards,
	Dmitry

+-------------------------------------------------------------------------+
Dmitry V. Levin     mailto://ldv@fandra.org
Software Engineer   PGP pubkey http://www.fandra.org/users/ldv/pgpkeys.html
IPLabs Linux Team   http://linux.iplabs.ru
Fandra Project      http://www.fandra.org
+-------------------------------------------------------------------------+
UNIX is user friendly. It's just very selective about who its friends are.

[-- Attachment #1.2: cleanup_spec --]
[-- Type: text/plain, Size: 1751 bytes --]

#!/bin/sh -e

PROG="${0##*/}"

: "${TMPDIR:=$HOME/tmp}"
TMPFILE="$(mktemp "$TMPDIR/$PROG.XXXXXX")"

Exit()
{
	RETVAL=$?
	trap "" EXIT
	rm -f "$TMPFILE"
	exit $RETVAL
}

trap "Exit " SIGHUP SIGPIPE SIGINT SIGTERM EXIT

RemoveEmpty()
{
	awk 'BEGIN{empty=0} /^.+$/{empty=0} /^$/{if(!empty){print;empty=1}} {if(!empty)print $0}' <$1 >"$TMPFILE" &&
		cat "$TMPFILE" >"$1"
}

RemoveClean()
{
	awk 'BEGIN{clean=0} {printed=0} /^%(pre|post|trig|files|changelog)/{clean=0} /^./{if(clean){print "%clean";clean=0}} /^%clean$/{clean=1;printed=1} /^$/{if(clean){printed=1}} {if(!printed)print $0}' <$1 >"$TMPFILE" &&
		cat "$TMPFILE" >"$1"
}

CleanFiles()
{
	awk 'BEGIN{found=0} {printed=0} /^./{found=0} /^%(description|prep|build|install|pre|post|trig|files|changelog)([^_]|$)/{found=1} /^%(pre|post|trig).*[ 	]-p[ 	]/{found=0} /^$/{if(found)printed=1} {if(!printed)print $0}' <$1 >"$TMPFILE" &&
		cat "$TMPFILE" >"$1"
}

for F in "$@"; do
	perl -pi -e 's/%\{([A-Za-z_0-9]+)\}([^A-Za-z_0-9]|$)/%$1$2/g' "$F"
	perl -pi -e 's/%\{([A-Za-z_0-9]+)\}([^A-Za-z_0-9]|$)/%$1$2/g' "$F"
	perl -pi -e 's/%\{([A-Za-z_0-9]+)\}([^A-Za-z_0-9]|$)/%$1$2/g' "$F"
	perl -pi -e 's/[ 	]+$//g' "$F"
	perl -pi -e 's/^([A-Za-z_0-9]+:)[ 	]+/\1 /g' "$F"
	perl -pi -e 's/^%make\s+/%make_build /g;s/%_prefix/%prefix/g;s/%_initrddir/%_initdir/g;s/%_install_info/%install_info/g;s/%_remove_install_info/%uninstall_info/g' "$F"
	perl -pi -e 's/^prereq: /PreReq: /ig;s/^buildrequires: /BuildRequires: /ig;s/^buildprereq: /BuildPreReq: /ig' "$F"

	perl -pi -e 's/^buildroot: .*//ig' "$F"
	perl -pi -e 's/^rm\s+-rf\s+"?\$RPM_BUILD_ROOT"?$//g' "$F"
	perl -pi -e 's/^%defattr\s*\(\s*-\s*,\s*root\s*,\s*root\s*(,\s*(-|0?755)\s*)?\)//g' "$F"

	RemoveEmpty "$F"
	RemoveClean "$F"
	CleanFiles "$F"
done

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

             reply	other threads:[~2001-01-14  1:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-14  1:20 Dmitry V. Levin [this message]
2001-01-16  1:56 ` [devel] " Dmitry V. Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010114042016.A6353@LDV.fandra.org \
    --to=ldv@fandra.org \
    --cc=devel@linux.iplabs.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git