summaryrefslogtreecommitdiff
path: root/update_meta.sh
blob: 14d1a57161ed0c84479b94650cd92aa9db27a8c4 (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
#!/bin/bash 

API=https://build.tizen.org
ACTION=${1:-get}
PRJ=${2:-Tizen:Unified}

PARALLEL_JOBS=8

set -e

function parallel_jobs {
	local max_number=$((0 + ${1:-0}))
	while true; do
		jobs &>/dev/null
		if [[ $(jobs -p | wc -l) -lt $max_number ]]; then
			break
		fi
		sleep 0.3
	done
}

function check_package() {
	pkg=$1
	pkgtype="X"

	# fetch file list for each package and deduce type
	for filename in $(osc -A $API ls -u $PRJ $pkg); do
		case $filename in
			_aggregate)	pkgtype="A"; break;;
			_link)		pkgtype="L"; break;;
			_service)	pkgtype="S"; break;;
			*)			pkgtype="U"; break;;
		esac
	done
	msg="$pkgtype $pkg"

	# uddate aggregate and link packages
	case $pkgtype in
		A)
			mkdir -p $pkg
			osc -A $API api /source/$PRJ/$pkg/_aggregate >$pkg/_aggregate
			osc -A $API api /source/$PRJ/$pkg/_meta >$pkg/_meta
			msg="$msg (updated)"
			;;
		L)
			mkdir -p $pkg
			osc -A $API api /source/$PRJ/$pkg/_link >$pkg/_link
			osc -A $API api /source/$PRJ/$pkg/_meta >$pkg/_meta
			if grep '<build' $pkg/_meta &>/dev/null; then
				msg="$msg (updated, with meta)"
			else
				rm $pkg/_meta
				msg="$msg (updated)"
			fi
			;;
		*)
			content=$(osc -A $API api /source/$PRJ/$pkg/_meta)
			if echo $content | grep -q '<build>' ; then
				mkdir -p $pkg
				echo $content >$pkg/_meta
				msg="$msg (updated)"
			fi
			;;
	esac
	echo $msg
}

cd $PRJ

if [ "$ACTION" == 'get' ] ; then
	# fetch project config
	echo "Fetching project config for $PRJ"
	osc -A $API meta prjconf $PRJ >_config

	# fetch project meta
	echo "Fetching project meta for $PRJ"
	osc -A $API meta prj $PRJ >_meta

	# check that each subdir exists on OBS project
	shopt -s extglob
	for file in $(ls */@(_aggregate|_link)); do
		pkg=$(dirname $file)
		echo "Checking $pkg"
		if ! osc -A $API ls $PRJ $pkg &>/dev/null; then
			echo "Package $pkg was removed on OBS. Removing dir $pkg."
			git rm -rf $pkg
		fi
	done
	# fetch packages list
	osc -A $API ls $PRJ | while read pkg; do
		parallel_jobs $PARALLEL_JOBS
		check_package $pkg &
	done

	parallel_jobs 1
elif [ "$ACTION" == 'put' ] ; then
	find . -type f | while read path; do
		path=$(echo $path|cut -d/ -f2-)
		echo Sending $path to $PRJ
		osc -A $API api -X PUT /source/$PRJ/$path -f $path
	done
else
	>&2 echo "Error: Unknown action: $ACTION"
	exit 1
fi