summaryrefslogtreecommitdiffstats
path: root/mockit
blob: c4d974511084816a44710057aa11777164809163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/bin/bash

if [ "$2" = "" ]; then
	echo -e "\nusage: $0 [ options ] SRPM distro [ min_ver [, max_ver [, mock_options ]]]\n"
	echo -e "\t--redis            store build command in redis queue"
	echo -e "\t--valkey           store build command in valkey queue"
	echo -e "\t--list             list queue content"
	echo -e "\t--nobase | --scl   only build SCL packages"
	echo -e "\t--noscl | --base   only build base packages\n"
	exit 0
fi

# Script options
BUILD_BASE=1
BUILD_SCLS=1
REDIS=0
REMOTE=0

# ARCH detection and check
if [ "$(uname -m)" = "x86_64" ]; then
	SUF=x
	QUEUE=mockx
	REDISCLI="valkey-cli"
else
	SUF=a
	QUEUE=mocka
	REDISCLI="valkey-cli -h remi"
fi

if [ "$1" == "--redis" -o "$1" == "--valkey" ]; then
	CHECK=$($REDISCLI ping)
	[ "$CHECK" = "PONG" ] || exit 1
	REDIS=1
	shift
fi

# Queue commands
if [ "$1" == "--list" ]; then
	echo "-- x86_64 queue: $($REDISCLI scard mockx) tasks --"
	a=$($REDISCLI smembers mockx)
	[ -n "$a" ] && $REDISCLI smembers mockx | \
       sed -e 's/^.*-r/  /;s/rebuild/\t/' | sort || \
       ps -ef | grep mock/mock | grep -v grep

	echo -e "\n-- aarch64 queue: $($REDISCLI scard mocka) tasks --"
	a=$($REDISCLI smembers mocka)
	[ -n "$a" ] && $REDISCLI smembers mocka  | \
      sed -e 's/^.*-r/  /;s/rebuild/\t/'| sort || \
      ps -ef | ssh remi@ampere 'ps -ef | grep mock/mock | grep -v grep'

	exit 0
elif [ "$1" == "--clean" ]; then
	$REDISCLI del mockx
	$REDISCLI del mocka
	exit 0
fi

if [ "$1" == "--nobase" -o "$1" == "--scl" ]; then
	BUILD_BASE=0
	shift
elif [ "$1" == "--noscl" -o "$1" == "--base" ]; then
	BUILD_SCLS=0
	shift
fi

SRPM=$1
DIST=$2
shift 2

# PHP version build range
if [ "$1" = "" ]; then
	MIN=56
else
	MIN=$1
	shift
fi
if [ "$1" = "" ]; then
	MAX=84
else
	MAX=$1
	shift
fi

case $DIST in
	*x)
		if [ $SUF != x ]; then
			echo "Not an x86_64 builder"
			exit 1
		fi
		;;
	*a)
		if [ $SUF != a ]; then
			if [ $REDIS -ge 1 ]; then
				REMOTE=1
			else
				echo "Not an aarch64 builder"
				exit 1
			fi
		fi
		;;
	*)
		DIST=$DIST$SUF
		;;
esac

# SRPM abolute path
case $DIST in
	*x)
		mocketc=/home/rpmbuild/SPECS/remirepo/tools/mock
		srpmdir=/home/rpmbuild/site/rpms/SRPMS
		;;
	*a)
		mocketc=/home/remi/mock
		srpmdir=/home/remi/SRPMS
		;;
esac

if [ -f $srpmdir/$SRPM ]; then
	SRPM=$srpmdir/$SRPM
elif [ -f $PWD/$SRPM ]; then
	SRPM=$PWD/$SRPM
elif [ ! -f $SRPM ]; then
	echo "file not found '$SRPM'"
	exit 1
fi

# Send to remote aarch64 builder
if [ $REMOTE -ge 1 ]; then
	LST=/tmp/srpm_aarch64_sent.list
	touch $LST
	if ! grep -q $SRPM $LST; then
		scp $SRPM remi@ampere:todo/
		echo $SRPM >>$LST
	fi
	mocketc=/home/remi/mock
	QUEUE=mocka
	SRPM=/home/remi/todo/$(basename $SRPM)
fi

# PHP version matrix
echo mockit $SRPM $DIST $MIN $MAX $@
case $DIST in
	fc39x|fc39a|fc40x|fc40a|fc41x|fc41a|el9x|el9a|el10x|el10a)
		LST="82 81 74 80 83 84"
		SCL="74 80 81 82 83 84"
		;;
	el8a)
		LST="72 73 74 80 81 82 83 84"
		SCL="72 73 74 80 81 82 83 84"
		;;
	el8x)
		LST="72 73 74 80 81 82 83 84"
		SCL="56 70 71 72 73 74 80 81 82 83 84"
		;;
	allx)
		if [ $REDIS -ge 1 ]; then
			for i in fc39x fc40x fc41x el8x el9x el10x fc39a fc40a fc41a el8a el9a el10a
			do
				[ $BUILD_BASE -ge 1 ] && $0 --valkey --base $SRPM $i $MIN $MAX $@
				[ $BUILD_SCLS -ge 1 ] && $0 --valkey --scl  $SRPM $i $MIN $MAX $@
			done
		else
			echo Not supported for direct build
		fi
		;;
	ztsx)
		if [ $REDIS -ge 1 ]; then
			[ $MAX -gt 83 ] && MAX=83
			for i in fc39x fc40x el8x el9x
			do
				[ $BUILD_BASE -ge 1 ] && $0 --valkey --base $SRPM $i $MIN $MAX $@
			done
		else
			echo Not supported for direct build
		fi
		;;
	*)
		echo Unkown DIST $DIST
		exit 1
		;;
esac

ID=${QUEUE:-$PPID}

# Build base/modules
[ $BUILD_BASE -ge 1 ] && for i in $LST
do
	if [ 0$i -ge $MIN -a 0$i -le $MAX ]; then
		CMD="mock -q --configdir=$mocketc -r ${DIST}${i} rebuild $SRPM $@"
		if [ $REDIS -ge 1 ]; then
			$REDISCLI sadd $QUEUE "$CMD"
		else
			echo -n "$(date +%X)    $i "
			$CMD --uniqueext=$ID && echo " Ok." || echo " Error !"
		fi
	fi
done
# Build Software Collections
[ $BUILD_SCLS -ge 1 ] && for i in $SCL
do
	if [ 0$i -ge $MIN -a 0$i -le $MAX ]; then
		CMD="mock -q --configdir=$mocketc -r ${DIST}scl${i} rebuild $SRPM $@"
		if [ $REDIS -ge 1 ]; then
			$REDISCLI sadd $QUEUE "$CMD"
		else
			echo -n "$(date +%X) scl$i "
			$CMD --uniqueext=$ID && echo " Ok." || echo " Error !"
		fi
	fi
done

if [ $REDIS -ge 1 ]; then
	echo "Queue size: " $($REDISCLI scard $QUEUE)
else
	date +%X
fi