summaryrefslogtreecommitdiffstats
path: root/db-update
blob: 73897f384836af9fa128e71edc7757a3b618ac0d (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
#!/bin/bash

. "$(dirname $0)/db-functions"
. "$(dirname $0)/config"

if [ $# -ge 1 ]; then
	warning "Calling $(basename $0) with a specific repository is no longer supported"
	exit 1
fi

# Find repos with packages to release
repos=($(find  "${STAGING}" -mindepth 1 -type d ! -empty -printf '%f ' 2>/dev/null))
if [ $? -ge 1 ]; then
	error "Could not read ${STAGING}"
	exit 1
fi

for repo in ${repos[@]}; do
	if ! check_repo_permission "${repo}"; then
		error "You don't have permission to update packages in ${repo}"
		exit 1
	fi
	pkgs=($(getpkgfiles "${STAGING}/${repo}/"*${PKGEXT}))
	if [ $? -eq 0 ]; then
		for pkg in ${pkgs[@]}; do
			if ! check_pkgfile "${pkg}"; then
				error "Package ${repo}/$(basename ${pkg}) is not consistent with its meta data"
				exit 1
			fi
			if ! check_pkgsvn "${pkg}" "${repo}"; then
				error "Package ${repo}/$(basename ${pkg}) is not consistent with svn repository"
				exit 1
			fi
			if [ -f "${FTP_BASE}/$(get_pkgpool_for_host)/$(basename ${pkg})" ]; then
				error "Package ${repo}/$(basename pkg) already exists in ${FTP_BASE}/$(get_pkgpool_for_host)"
				exit 1
			fi
		done
	else
		exit 1
	fi
done

# TODO: this might lock too much (architectures)
for repo in ${repos[@]}; do
	for pkgarch in ${ARCHES[@]}; do
		repo_lock ${repo} ${pkgarch} || exit 1
	done
done

for repo in ${repos[@]}; do
	msg "Updating [${repo}]..."
	any_pkgs=($(getpkgfiles "${STAGING}/${repo}/"*-any${PKGEXT} 2>/dev/null))
	for pkgarch in ${ARCHES[@]}; do
		add_pkgs=()
		arch_pkgs=($(getpkgfiles "${STAGING}/${repo}/"*-${pkgarch}${PKGEXT} 2>/dev/null))
		for pkg in ${arch_pkgs[@]} ${any_pkgs[@]}; do
			pkgfile="$(basename ${pkg})"
			msg2 "${pkgfile} (${pkgarch})"
			# any packages might have been moved by the previous run
			if [ -f "${pkg}" ]; then
				mv "${pkg}" "$FTP_BASE/$(get_pkgpool_for_host)"
			fi
			ln -s "../../../$(get_pkgpool_for_host)/${pkgfile}" "$FTP_BASE/$repo/os/${pkgarch}"
			add_pkgs[${#add_pkgs[*]}]=${pkgfile}
		done
		pushd "$FTP_BASE/$repo/os/${pkgarch}" >/dev/null
		/usr/bin/repo-add -q "$repo$DBEXT" ${add_pkgs[@]} >/dev/null \
			|| die "Could not add packages"
		popd >/dev/null
	done
done

for repo in ${repos[@]}; do
	for pkgarch in ${ARCHES[@]}; do
		repo_unlock ${repo} ${pkgarch}
	done
done