aboutsummaryrefslogtreecommitdiffstats
path: root/approve.sh
blob: ce0bf28c497f9c237d1ab6c135b6950acf50e7df (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
#!/bin/bash -e

SRCBASEDIR=/home/mandrake/uploads/queue
DESTBASEDIR=/home/mandrake/uploads/approved
REJECTEDDIR=/home/mandrake/uploads/rejected
DISTRO=cooker

function list() {
	echo "The following packages are currently queued:" >&2
	find -L "$SRCBASEDIR/$DISTRO" -name "*.src.rpm" |\
		sed "s@$SRCBASEDIR/$DISTRO/@@;s@\(.*\)/\([0-9]\+[^_]\+\)@\1 \2 @" |\
		sort -k2 |\
		while read media id pkg; do
			printf "%-15s %s %15s %s\n" "$media" "$id" "$pkg"
		done
}

function inspect() {
	regexp="*.src.rpm"
	if [ -n "$1" ]; then
		regexp="*$1*.src.rpm"
	fi
	for i in `find -L "$SRCBASEDIR/$DISTRO" -name "$regexp" | sed "s@$SRCBASEDIR/$DISTRO/@@" | sort`; do
		echo $i
		rpm -qp --changelog $SRCBASEDIR/$DISTRO/$i | head | sed "s/^/\t/"
		echo
	done
}

function list_approved() {
	echo "The following packages are currently approved:"
	find -L "$DESTBASEDIR/$DISTRO" -name "*.src.rpm" |\
		sed "s@$DESTBASEDIR/$DISTRO/@@;s@\(.*\)/\([0-9]\+[^_]\+\)@\1 \2 @" |\
		sort -k2 |\
		while read media id pkg; do
			printf "%-15s %s %15s %s\n" "$media" "$id" "$pkg"
		done
}

function move() {
	id="$1"
	dest="$2"
	queuename=$(basename $dest)

	echo "Searching for packages with id $id..."
	packages=$(find -L "$SRCBASEDIR/$DISTRO" -name "${id}_*.rpm")

	echo "- Found packages:"
	for pkg in $packages; do
	        echo -e "\t$pkg" | sed "s@$SRCBASEDIR/$DISTRO/@@;s/${id}_@[0-9]\+://;s/${id}_//"
	done

	echo "- Moving packages to $queuename..."
	for srcpath in $packages; do
	        destpath=$(echo "$srcpath" | sed "s@$SRCBASEDIR@$dest@")
	        mv "$srcpath" "$destpath"
	done
}

#
# Parse command line
#
if [ -z "$1" ]; then
	echo "Usage: $(basename $0) --list-queued"
	echo -e "Usage: $(basename $0) --inspect [id]\n  to inspect packages changelog"
	echo "Usage: $(basename $0) --list-approved"
	echo "Usage: $(basename $0) --approve <id> [id...]"
	echo "Usage: $(basename $0) --reject <id> [id...]"
	echo "	Where id = 20070315170513.oden.kenobi.7558, for example"
	exit 1
fi

if [ "$1" == "--list-queued" ]; then
	list
elif [ "$1" == "--inspect" ]; then
	shift
	inspect $*
elif [ "$1" == "--list-approved" ]; then
	list_approved
elif [ "$1" == "--approve" ]; then
	while [ -n "$2" ]; do
		move "$2" "$DESTBASEDIR"
		shift
	done
elif [ "$1" == "--reject" ]; then
	while [ -n "$2" ]; do
		move "$2" "$REJECTEDDIR"
		shift
	done
else
	echo "Unknow command: $1"
	exit 1
fi