rpmbph 6.31 KB
Newer Older
1
#!/bin/bash
2
# 2003-2010, 2012, 2015, 2017 (c) Etersoft www.etersoft.ru
3 4 5
# Author: Vitaly Lipatov <lav@etersoft.ru>
# Public domain
#
Vitaly Lipatov's avatar
Vitaly Lipatov committed
6
# BPH - backport package with hasher checking
7

Vitaly Lipatov's avatar
Vitaly Lipatov committed
8
# Used ROOTDIR if defined (for non ALT systems)
9

10 11
# load common functions, compatible with local and installed script
. `dirname $0`/../share/eterbuild/functions/common
12
load_mod repl rpm git buildsrpm spec branch
13 14


15 16
#############################

17
# FIXME: CURRENTBRANCHNAME??
18
Usage="Usage: $name [-r -u -U -n -i -m -v -q -e] [-b REPONAME] spec..."
19 20 21
function mygetopts()
{
name=${0##*/}
22
Descr="$name (BackPort and Hasher) - backports spec and rebuild it"
23 24 25 26 27

phelp()
{
	echog "$Descr"
	echog "$Usage"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
28
	echo  "Usage: rpmbph [GIRAR] -b $EXAMPLEALTDISTRVERSION for backport to ALT Linux $EXAMPLEALTDISTRVERSION and so on"
29
	echo
30
	echog "Options:"
31
	echog "   -u           sign and upload after build" # will pass to rpmbs/rpmbsh
Vitaly Lipatov's avatar
Vitaly Lipatov committed
32
	echog "   -n           skip build in hasher"
33
	echog "   -i           install built packages in test hasher" # will pass to rpmbs/rpmbsh
Vitaly Lipatov's avatar
Vitaly Lipatov committed
34
	echog "   -b REPONAME  binary repository name (4.1, p5, t6 and so on) (can be overrided with DISTRNAME)"
35
	echo  "$HELP_GIRAR"
36
	echo
37
	echog "Ext. options:"
38 39
	echog "   -v           more verbose"
	echog "   -q           quiet"
40
	echog "   -e           sign and run gear test only task girar build"
41
	echog "   -z           create src.rpm with compatible gzip compression (obsoleted)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
42 43
	echo
	echog "Examples:"
44
	echog " $ rpmbph -b $EXAMPLEALTDISTRVERSION -n -u  - backport to $EXAMPLEALTDISTRVERSION and ask to build it"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
45
#	echog "Set ROOTDIR variable for backport to the other system"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
46
#	echog " -m - send result via e-mail"
47 48
}

49
FORCE=
50
PASSEDARGS=
51
while getopts :hnuaeAfvqb: opt; do
52
    case $opt in
53 54
        h) phelp; exit 0 ;;
        n) NOBUILD=1 ;;
55
        u|e|a|A) PASSEDARGS="$PASSEDARGS -$opt" ;;
56
        f) FORCE=1 ; PASSEDARGS="$PASSEDARGS -$opt" ;;
57 58 59 60 61
        v) VERBOSE=1 ;;
        b) BINARYREPONAME=$OPTARG ;;
        q) QUIET=1 ;;
        +?) echog "$name: options should not be preceded by a '+'." 1>&2; exit 2;;
        ?) OPTIND=$((OPTIND-1)); break;
62 63 64 65
    esac
done

# remove args that were options
66
if [ $# -gt 0 ]; then
67
	[ "$OPTIND" -gt 0 ] && shift $(($OPTIND - 1))
68 69
fi

70 71
# pass other options
LISTRPMARGS="$PASSEDARGS $*"
72 73
}

74
set_girar_host $1 && shift
75

76
parse_cmd_pre_spec "$@"
77 78
mygetopts $LISTARGS

79 80 81
# see functions/alt:set_binaryrepo() for BINARYREPONAME
set_binaryrepo $MENV

82 83 84
# assure we have only specs or src.rpm
LISTNAMES=$(repodirs_to_specs $LISTNAMES)

85
test -z "$LISTNAMES" && fatal "file not found in '$@'"
86

87
if [ "$PKGVENDOR" = "alt" ] ; then
88
	MDISTR=$MENV
89
	[ "$MDISTR" = "sisyphus" ] && fatal "It makes no sense to backport to Sisyphus (You need to try with -b $EXAMPLEALTDISTRVERSION)."
90
	# override by defined target version
91
	DISTRVERSION=$BINARYREPO
92 93 94 95 96 97
else
	MDISTR=LOCAL
fi

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

98
if [ -z "$BUILDCOMMAND" ] ; then
99
	[ -n "$NOBUILD" ] && BUILDCOMMAND="$ETERBUILDBIN/rpmbs $GIRARHOST -w" || BUILDCOMMAND="$ETERBUILDBIN/rpmbsh $GIRARHOST -w"
100
fi
101

102
# set SPECDIR from LISTNAMES if empty (need for is_gear below)
103 104
[ -n "$SPECDIR" ] || set_specdir $LISTNAMES

105 106
# FIXME: detected only by first arg?

Vitaly Lipatov's avatar
Vitaly Lipatov committed
107
# if run for ALT inside gear repo, just create backported spec
108
if [ "$PKGVENDOR" = "alt" ] && is_gear $SPECDIR ; then
109 110 111 112

	for SPEC in $LISTNAMES ; do

		set_specdir $SPEC
113
		docmd cd $SPECDIR || fatal
114

115 116
		checkout_original_branch

117 118 119
		is_last_commit_tag || fatal "We allow backport only when last commit has (release) tag"
		LASTTAG="$(get_last_tag)" || fatal "Can't get tag for last tag"

120 121 122
		# set USEBRANCH
		set_usebranch

123
		# spec name for branch
124
		BPSPEC=$SPEC.$USEBRANCH
125 126 127

		set_currentbranch

128 129 130
		#[ -f "$BPSPEC" ] && fatal "File $BPSPEC is already exists, check it and remove"
		cp -f $SPEC $BPSPEC || fatal "Can't copy to $BPSPEC"
		# backport spec
131 132
		docmd $ETERBUILDBIN/rpmbps -b $BINARYREPO $BPSPEC || fatal

133 134 135
		# checkout to $USEBRANCH
		checkout_bpbranch

136 137
		# if version-release from backported spec is already committed
		if [ -z "$FORCE" ] && is_last_commit_tag "$(get_version $BPSPEC)-$(get_release $BPSPEC)" ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
138
			info "Tag $(get_last_tag) already exists for the last commit, skipping"
139
			rm -f $BPSPEC
140 141 142 143
			# so just skipping
			continue
		fi

144
		docmd git merge --no-ff $LASTTAG
145 146

		# override spec conflicts
Vitaly Lipatov's avatar
Vitaly Lipatov committed
147
		docmd mv -f $BPSPEC $SPEC || fatal
148

149
		# FIXME: Ctrl-\ and q will cancelled less with return error code
150 151 152 153 154 155 156 157 158
		if [ -z "$QUIET" ] && tty -s ; then
			if [ "$(git diff | wc -l)" = "0" ] ; then
				info "Strange, there is no differences in backported spec."
			else
				( echo "etersoft-build-utils INFO: Please check diff for backported spec:" ; \
				echo "# etersoft-build-utils NOTE: You can press Ctrl-\ for cancel the process."; \
				echo ; git diff ) | less
				[ $? = 0 ] || fatal "Cancelled by user. You are still in $USEBRANCH branch with modified spec."
			fi
159
		fi
160

161 162 163 164
		docmd git add $SPEC
		if ! git_commit_ignore_nothing -a -m "backported to $USEBRANCH as $(get_version $SPEC)-$(get_release $SPEC) (with rpmbph script)" ; then
			#git checkout $CURBRANCH
			fatal "Commit error. You are still in $CURBRANCH branch with modified and uncommitted spec file."
165
		fi
166 167
		cd - >/dev/null
	done
168

169
	docmd $BUILDCOMMAND -b $BINARYREPO $LISTRPMARGS $LISTNAMES
170 171
	RET=$?

172 173 174 175 176 177 178 179 180
	# TODO: move it to some exit handler?
	# usually it will done in rpmbs after upload
	for SPEC in $LISTNAMES ; do
		set_specdir $SPEC
		docmd cd $SPECDIR || fatal
		checkout_original_branch
		cd - >/dev/null
	done

181
	exit $RET
182 183
fi

184
# handle src.rpm and spec both, LISTBUILT - result with full paths to src.rpms
185
pack_src_rpm
186

187 188
export RPMTOPDIR=$(mktemp -d || fatal "can't create tmp dir")
mark_file_to_remove $RPMTOPDIR
189

190
# prevent gear detecting (operate inside our dir)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
191
export IGNOREGEAR=1
192 193
# NOTE: we can do cd to some other dir...

194
for i in $LISTBUILT ; do
195 196 197 198 199 200
	uni_rpminstall "$i"

	# Note! Use $i package only before rm it
	SPECNAME=$RPMTOPDIR/SPECS/$(spec_by_srpm "$i")
	test -f "$SPECNAME" || fatal "Spec $SPECNAME (got from $i) is not found in $RPMTOPDIR/SPECS"

201
	# remove primary src.rpm only if src.rpm was not primary
202
	rhas "$LISTNAMES" "$i" || rm -f "$i"
203

204
	docmd $ETERBUILDBIN/rpmbps -b $BINARYREPO $SPECNAME
205

206
	docmd $BUILDCOMMAND -b $BINARYREPO $LISTRPMARGS $SPECNAME || fatal "Can't build"
207 208 209 210

	# move results to common place
	cp -fv $RPMTOPDIR/SRPMS/*.rpm $RPMDIR/SRPMS/ 2>/dev/null

211
	uni_rpmrm $SPECNAME || true
212 213
done

214 215
rm -rf $RPMTOPDIR
remove_file_from_remove $RPMTOPDIR