#!/bin/bash # Macroszification of files to be mandrake compliant, also do some check. # Copyright (C) 2000 by Chmouel Boudjnah , # MandrakeSoft # Redistribution of this file is permitted under the terms of the GNU # Public License (GPL) function usage () { rval=$1 echo "Usage: $(basename $0) -d --help --nodiff --nocheck --clean SPEC-FILE" echo -e "\t-d: Product only a diff don't change nothing" echo -e '\t-o: Only change the mandir/infodir' echo -e "\t--nocheck: Don't try do check about Prefix %configure" echo -e "\t--clean: remove the old files after" echo -e "\t--nodiff: I don't want to see the diff output" echo -e "\t--help: This help" exit $rval; } while [[ $1 == -* ]];do case $1 in -d) only_diff=1; shift; ;; -o) only_fhs=1; shift; ;; --nocheck) nocheck=1; shift; ;; --nodiff) nodiff=1; shift; ;; --clean) clean=1; shift; ;; -*) usage 0 ;; esac done file=$1; if [[ ! -f $file ]];then echo -e "Error: i really need a spec file to work\n"; usage $val; fi [[ -z $nocheck ]] && grep -E -q "%{?prefix}?" $file && { grep -E -q "^Prefix:[[:space:]]+" $file || { echo "sound like you don't have a Prefix set" exit; } } [[ -z $nocheck ]] && grep -E -q "^%configure" $file && { grep -E -q "^%makeinstall" $file || { echo "sound like you don't have a %makeinstall" exit; } } [[ -z $nocheck ]] && grep -E -q "^Docdir:[[:space:]]+" $file && { echo "You have a Docdir entry, it's not good !!" exit; } mv -f $file $file.old if [[ -z $only_fhs ]];then cat $file.old | perl -e " while (<>) { s@[/]?(usr|%{[_]?prefix})/bin@%{_bindir}@g; s@[/]?(usr|%{[_]?prefix})/man@%{_mandir}@g; s@[/]?(usr|%{[_]?prefix})/sbin@%{_sbindir}@g; s@[/]?(usr|%{[_]?prefix})/etc@%{_sysconfdir}@g; s@[/]?(usr|%{[_]?prefix})/lib@%{_libdir}@g; s@[/]?(usr|%{[_]?prefix})/share@%{_datadir}@g; s@[/]?(usr|%{[_]?prefix})/include@%{_includedir}@g; s@[/]?(usr|%{[_]?prefix})/info@%{_infodir}@g; s@[/]?etc/(rc.d/)?init.d@%{_initrddir}@g; s@/etc@%{_sysconfdir}@; s@/usr@%{prefix}@; print; } " > $file else cat $file.old | perl -e " while (<>) { s@[/]?(usr|%{[_]?prefix})/man@%{_mandir}@g; s@[/]?(usr|%{[_]?prefix})/info@%{_infodir}@g; print; } " > $file fi if [[ -z $nodiff ]];then diff -u $file.old $file fi if [[ -n $only_diff ]];then mv -f $file.old $file fi if [[ -n $clean ]];then rm -f $file.old fi