rpmbph 8.77 KB
Newer Older
1
#!/bin/bash
Vitaly Lipatov's avatar
Vitaly Lipatov committed
2
# 2003-2009 (c) Etersoft www.etersoft.ru
3 4 5 6
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
# BPH - backport; use hasher
7

8 9 10 11 12
# Makes backport package to any target platfrom (RPM, DEB, TGZ)
#       .    alt4
#    alt0.M24.4
# TODO: use RPMBUILDARG

13 14
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
15
load_mod repl rpm
16 17 18 19 20 21 22 23

DISTRVERSION=`distr_vendor -v`

alt_tolocal()
{
local SPECNAME
SPECNAME=$1

Vitaly Lipatov's avatar
Vitaly Lipatov committed
24
BASERELEASE=$(get_numrelease $SPECNAME)
25

Vitaly Lipatov's avatar
Vitaly Lipatov committed
26 27
FIXPATCHFUZZ="%define _default_patch_fuzz 3"

28 29 30
# Set buildreq
if [ "$VENDOR" = "alt" ] ; then
	BUILDREQ="BuildRequires: rpm-build-compat >= 0.95"
31
	[ -z "$BUILDCOMMAND" ] && BUILDCOMMAND=$ETERBUILDBIN/rpmbsh
32 33
	# Change release according to alt policy with extensions
	# General rule: alwars alt(N-1).MM.(N)
34
	set_release $SPECNAME alt$(decrement_release $BASERELEASE).$MDISTR.$BASERELEASE
35 36
	ADDDEF=""
	CLEANTEXT=""
37 38
	# due new libtool, affected on ALT Linux
	RECONFT="%undefine __libtoolize"
39
else
Vitaly Lipatov's avatar
Vitaly Lipatov committed
40
	# Need our compat package and disable strong patch checking
Vitaly Lipatov's avatar
Vitaly Lipatov committed
41
	BUILDREQ="BuildRequires: rpm-build-altlinux-compat >= 0.95\n$FIXPATCHFUZZ"
42
	[ -z "$BUILDCOMMAND" ] && BUILDCOMMAND=$ETERBUILDBIN/rpmbb
43 44 45 46 47
	set_release $SPECNAME eter$BASERELEASE$VENDOR
	ADDDEF="%defattr(-, root, root)"
	CLEANTEXT=""
fi

48 49
if [ "$VENDOR" = "mdv" ] || [ "$VENDOR" = "pclinux" ] ; then
	# due new libtool, affected on Mandriva 2009.0
50
	test -z "$VERBOSE" || echo "Disable libtoolize"
51 52
	RECONFT="%define _disable_libtoolize 1"
fi
53

54
# Do not add BuildReq if already exist
Vitaly Lipatov's avatar
Vitaly Lipatov committed
55
cat $SPECNAME | grep rpm-build-compat &>/dev/null && BUILDREQ="$FIXPATCHFUZZ"
56

57 58 59 60 61 62 63 64
FIXMKTEMP=""

# fix readlink -m, introduced by new libtool and missed in RHEL4 (replace with readlink -e)
if [ "`distr_vendor -d`/$DISTRVERSION" = "ASPLinux/11.2" ] ; then
	test -z "$VERBOSE" || echo "Add subst readlink -m"
	FIXMKTEMP="%__subst 's|readlink -m|readlink -f|g' libtool ltmain.sh"
fi

65 66 67 68 69
if [ "`distr_vendor -d`" = "Ubuntu" ] || [ "`distr_vendor -d`" = "Debian" ]; then
	test -z "$VERBOSE" || echo "Add remove_optflags -m64"
	FIXMKTEMP="%remove_optflags -m64"
fi

70 71
# fix mktemp using for MCBC
if [ "$VENDOR" = "mcbc" ] ; then
72 73
	test -z "$VERBOSE" || echo "Add subst mktemp -dt"
	FIXMKTEMP="%__subst 's|mktemp -dt|mktemp -d|g' configure"
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
fi

# Too old problem
TOCHANGELOG=
if [ "$MDISTR" = "M23" ] ; then
	if grep "%configure" $SPECNAME >/dev/null && ! grep "^autoreconf" $i >/dev/null && ! grep "^%__autoreconf" $i >/dev/null ; then
		RECONFT="%__autoreconf"
		TOCHANGELOG="add __autoreconf macros in build section for fix so name problem (by script)"
	fi
fi

LISTBUILDDEP=`print_buildreq $SPECNAME`
LISTREQDEP=`print_pkgreq $SPECNAME`
LISTDEP=`echo $LISTBUILDDEP $LISTREQDEP | xargs -n1 echo | sort -u`
LISTGROUP=`eval_spec $SPECNAME | grep Group | sed -e "s|^.*:||g"  | xargs -n1 echo | sort -u`


# Build replacement rules for spec
ALLREPLRULES=""
[ -n "$VERBOSE" ] && echo "Checking req names for $LISTDEP"

export DISTRVERSION

97 98 99 100 101 102
if [ -n "$VERBOSE" ] ; then
	echo -n "Use replacement file: "
	print_pkgrepl_list
	echo
fi

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
for i in $LISTDEP ; do
	tolocal_anyrepl $i `print_pkgrepl_list` || continue
	#NRL="s!\(.*Req.*\)$REPLRULE1\( |,|\$\)!\1$REPLRULE2\2!g"
	NRL="s!(.*Req.*)$ALTPKGNAME( |,|\$)!\1$TARGETPKGNAME\2!g"
	[ -n "$VERBOSE" ] && echo "Use req rule $NRL"
	ALLREPLRULES="$ALLREPLRULES $NRL;"
done

# Build replacement rules for spec
[ -n "$VERBOSE" ] && echo "Checking group names for $LISTGROUP"
ALLGRPREPLRULES=""
for i in $LISTGROUP ; do
	tolocal_anyrepl $i `print_grprepl_list` || continue
	#NRL="s!\(Group.*\)$REPLRULE1\( |,|\$\)!\1$REPLRULE2\2!g"
	NRL="s!(Group.*)$ALTPKGNAME( |,|\$)!\1$TARGETPKGNAME\2!g"
	[ -n "$VERBOSE" ] && echo "Use group name rule $NRL"
	ALLGRPREPLRULES="$ALLGRPREPLRULES $NRL;"
done
#echo GRP: $LISTGROUP, ALLGRPREPLRULES: $ALLGRPREPLRULES

# Replace all packages names in source spec and add %defattr to files sections
# FIXME:    

function awk_e1()
{
	[ -n "$ADDDEF" ] &&	awk 'BEGIN{desk=0}{print;if(/^%files/){printf("%s\n", text)}}' text="$ADDDEF" || cat
}

# add clean before %files
function awk_e2()
{
	[ -n "$CLEANTEXT" ] && awk 'BEGIN{desk=0}{if(/^%files/&&desk==0){printf("%s\n\n", text);desk++};print}' text="$CLEANTEXT" || cat
}

# add rpm-build-compat buildreq
function awk_e3()
{
	[ -n "$BUILDREQ" ] && awk 'BEGIN{desk=0}{if(/^%description/&&desk==0){printf("%s\n\n", text);desk++};print}' text="$BUILDREQ" || cat
}

# add reconf for M23 after %build
function awk_e4()
{
	[ -n "$RECONFT" ] && awk 'BEGIN{desk=0}{print;if(/^%build/&&desk==0){printf("%s\n", text);desk++}}' text="$RECONFT" || cat
}

# fix mktemp param for MCBC after %build
function awk_e5()
{
	[ -n "$FIXMKTEMP" ] && awk 'BEGIN{desk=0}{print;if(/^%build/&&desk==0){printf("%s\n", text);desk++}}' text="$FIXMKTEMP" || cat
}

# apply replacement rules
repl_reqs()
{
	local PREGE
	PREGE="perl -p -e"
	[ -n "$ALLREPLRULES" ] && $PREGE "$ALLREPLRULES" || cat
}

# apply replacement rules
repl_groups()
{
	local PREGE
	PREGE="perl -p -e"
	[ -n "$ALLGRPREPLRULES" ] && $PREGE "$ALLGRPREPLRULES" || cat
}

if [ -n "$VERBOSE" ] ; then
	echo "Requires rules: $ALLREPLRULES"
	echo "Group rules: $ALLGRPREPLRULES"
fi

# apply all rules, awk excludes, remove empty tag lines
mv $SPECNAME $SPECNAME.old &&
	cat $SPECNAME.old | \
		repl_reqs | repl_groups | \
		awk_e1 | awk_e2 | awk_e3 | awk_e4 | awk_e5 | \
		sed -e "s|^BuildRequires: *\$||g" | \
		sed -e "s|^BuildPreReq: *\$||g" | \
		sed -e "s|^Requires: *\$||g" | \
		sed -e "s|^Conflicts: *\$||g" | \
		sed -e "s|^Provides: *\$||g" | \
		sed -e "s|^Obsoletes: *\$||g" | \
		cat > $SPECNAME

189 190 191 192 193
# hack for build old eter packages
if [ -n "$ETERREGNUM" ] ; then
	subst "s|@ETERREGNUM@|$ETERREGNUM|g" $SPECNAME
fi

194 195 196
# Fedora 10 does mismatch for Patch: and %patch0
subst "s|Patch:|Patch0:|g" $SPECNAME

197 198 199 200
# for systems with ash as sh
subst "s|^pushd \(.*\)|cd \1 >/dev/null|g" $SPECNAME
subst "s|^popd|cd - >/dev/null|g" $SPECNAME

201 202 203 204 205 206 207 208 209 210 211 212
#TODO:
#%if %{undefined buildroot}
#BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
#%endif

#TODO:
#%clean section

rm -f $SPECNAME.old

if [ "$VENDOR" = "alt" ] ; then
	subst "1i#" $SPECNAME
213 214 215 216
	# use old compress method for the src.rpm on ALT 4.0 and 4.1
	if [ "$DISTRVERSION" = "4.0" ] || [ "$DISTRVERSION" = "4.1" ] ; then
		export USE_LEGACY_COMPRESSION=1
	fi
217 218 219 220 221 222 223

	subst "1i# This spec is backported to `distr_vendor -d` $DISTRVERSION automatically by rpmbph script. Do not edit it." $SPECNAME
	ENTRY="- backport to `distr_vendor -d` $DISTRVERSION (by rpmbph script)"
	DISTRARG="-$MDISTR"
else
	subst "1i# This spec is autoported from ALT Linux Sisyphus to `distr_vendor -d` $DISTRVERSION automatically by rpmbph script. Do not edit it." $SPECNAME
	ENTRY="- autoport to `distr_vendor -d` $DISTRVERSION (by rpmbph script)"
224
	export USE_VENDOR=$RPMVENDOR
225
	export USE_LEGACY_COMPRESSION=1
226 227 228 229 230 231 232 233 234 235 236 237 238
	DISTRARG=""
fi

test -n "$TOCHANGELOG" && ENTRY=`echo -e "$ENTRY\n- $TOCHANGELOG"`
add_changelog $SPECNAME -e "$ENTRY"

$BUILDCOMMAND $LISTRPMARGS $REMOTEBUILD $DISTRARG $SPECNAME || fatal "Can't build"

}


#############################

239
Usage="Usage: $name [-r -u -U -n -i -m -v] [-M??] spec..."
240 241 242 243 244 245 246 247 248
function mygetopts()
{
name=${0##*/}
Descr="$name - backports spec and rebuild it"

phelp()
{
	echog "$Descr"
	echog "$Usage"
249
	echo  "Use rpmbph -M40 for backport to ALT 4.0 and so on"
250 251 252 253 254 255 256 257 258 259 260 261 262
	echog "Options:"
	echog " -r - remote build"
#	echog " -m - send result via e-mail"
	echog " -u/-U - sign and upload after build"
	echog " -n - do not build in hasher"
	echog " -i - install built packages in test hasher"
	echog " -v - more verbose"
}


while getopts :hniv opt; do
    case $opt in
    h) phelp; exit 0;;
263
    n) BUILDCOMMAND="$ETERBUILDBIN/rpmbs";;
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    v) VERBOSE=1;;
    +?) echog "$name: options should not be preceded by a '+'." 1>&2; exit 2;;
#    ?)  echog "$name: $OPTARG: bad option.  Use -h for help." 1>&2 ; exit 2;;
	?) OPTIND=$((OPTIND-1)); break;
    esac
done

# remove args that were options
if [ $# -gt 0 ]; then 
	shift $((OPTIND - 1))
fi

# pass other options to RPM:
LISTRPMARGS=$@
}

parse_cmd_pre "$@"
mygetopts $LISTARGS

test -z "$LISTNAMES" && fatal "Error: no such file"

if [ "$VENDOR" = "alt" ] ; then
	MDISTR=$MENV
	test -z "$MDISTR" && fatal "missed backport version (f.i. run with -M24 param for Master 2.4)"
288
	DISTRVERSION=$(get_altdistr_version $MDISTR)
289 290 291 292 293 294 295 296
else
	MDISTR=LOCAL
fi

[ -n "$VERBOSE" ] && echo "DISTRVERSION=$DISTRVERSION LISTRPMARGS=$LISTRPMARGS"

unset MENV MENVARG

297
# handle src.rpm too, LISTBUILT - result with full pathes to src.rpms
298
pack_src_rpm $LISTNAMES
299

300 301
export RPMTOPDIR=$RPMDIR/BP

302
# prevent gear detecting (operate inside our dir)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
303
export IGNOREGEAR=1
304 305
# NOTE: we can do cd to some other dir...

306
for i in $LISTBUILT ; do
307 308 309
	uni_rpminstall $i
	SPECNAME=$RPMTOPDIR/SPECS/$(spec_by_srpm $i)
	test -f "$SPECNAME" || fatal "Spec $SPECNAME is not found"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
310 311
	# FIXME: do not remove if not repacked
	#rm -f $SPKG
312
	alt_tolocal $SPECNAME
313 314
done