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

source "$(dirname "$(readlink -e "$0")")/etc/dbscripts.cfg"
source "$(dirname "$(readlink -e "$0")")/share/db-functions"

if [ $# -ge 1 ]; then
	warning "Calling %s with a specific repository is no longer supported" "${0##*/}"
	exit 1
fi

# Find repos with packages to release
staging_repos=($(find  "${staging_directory}" -mindepth 1 -type f -name "*${package_extension_suffixfile}" -printf '%h\n' | sort -u))
if [ $? -ge 1 ]; then
	die "Could not read %s" "${staging_directory}"
fi

repos=()
for staging_repo in "${staging_repos[@]##*/}"; do
	if in_array "${staging_repo}" "${repositories[@]}"; then
		repos+=("${staging_repo}")
	fi
done

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

# check if packages are valid
for repo in "${repos[@]}"; do
	if ! check_repo_permission "${repo}"; then
		die "You don't have permission to update packages in %s" "${repo}"
	fi
	pkgs=($(getpkgfiles "${staging_directory}/${repo}/"*${package_extension_suffixfile}))
	if [ $? -eq 0 ]; then
		for pkg in "${pkgs[@]}"; do
			if [ -h "${pkg}" ]; then
				die "Package %s is a symbolic link" "${repo}/${pkg##*/}"
			fi
			if ! check_pkgfile "${pkg}"; then
				die "Package %s is not consistent with its meta data" "${repo}/${pkg##*/}"
			fi
			if ! check_pkgrepos "${pkg}"; then
				die "Package %s already exists in another repository" "${repo}/${pkg##*/}"
			fi
		done
		# This is fucking obnoxious
		#if ! check_splitpkgs ${repo} "${pkgs[@]}"; then
		#	die "Missing split packages for %s" "${repo}"
		#fi
	else
		die "Could not read %s" "${staging_directory}"
	fi
done

dirs=()
for repo in "${repos[@]}"; do
	msg "Updating [%s]..." "${repo}"
	any_pkgs=($(getpkgfiles "${staging_directory}/${repo}/"*-any${package_extension_suffixfile} 2>/dev/null))
	for pkgarch in "${architectures[@]}"; do
		add_dirs=()
		add_pkgs=()
		arch_pkgs=($(getpkgfiles "${staging_directory}/${repo}/"*-"${pkgarch}"${package_extension_suffixfile} 2>/dev/null))
		for pkg in "${arch_pkgs[@]}" "${any_pkgs[@]}"; do
			pkgfile="${pkg##*/}"
			msg2 "%s (%s)" "${pkgfile}" "${pkgarch}"
			# any packages might have been moved by the previous run
			if [ -f "${pkg}" ]; then
				mv "${pkg}" "${root_dir}/${packages_pool}"
			fi
			ln -s "../../../${packages_pool}/${pkgfile}" "${root_dir}/$repo/os/${pkgarch}"
			# also move signatures
			if [ -f "${pkg}.sig" ]; then
				mv "${pkg}.sig" "${root_dir}/${packages_pool}"
			fi
			if [ -f "${root_dir}/${packages_pool}/${pkgfile}.sig" ]; then
				ln -s "../../../${packages_pool}/${pkgfile}.sig" "${root_dir}/$repo/os/${pkgarch}"
			fi
			add_dirs+=("${staging_directory}/abslibre/$(getpkgarch "${root_dir}/$packages_pool/$pkgfile")/$repo/$(getpkgbase "${root_dir}/$packages_pool/$pkgfile")")
			add_pkgs+=("${pkgfile}")
		done
		for add_dir in "${add_dirs[@]}"; do
			(cd "${add_dir}" && xbs release-server "${repo}" "${pkgarch}") ||
				error 'cd %q && xbs release-server %q %q' "${add_dir}" "${repo}" "${pkgarch}"
		done
		if [ ${#add_pkgs[@]} -ge 1 ]; then
			arch_repo_add "${repo}" "${pkgarch}" "${add_pkgs[@]}"
		fi
		dirs+=("${add_dirs[@]}")
	done
done

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

cd "${staging_directory}"

# Remove left over XBS files
rm -rf -- "${dirs[@]}"
dirname -z -- "${dirs[@]}" |
    xargs -0 realpath -zm --relative-to="${staging_directory}" -- |
    xargs -0 rmdir -p -- 2>/dev/null

# Stage generated source files
while read -r file; do
	pub="${root_dir}/${file}"
	if [[ -f "$pub" ]]; then
		warning "file already exists: %s" "${file}"
	else
		mkdir -p -- "${pub%/*}"
		mv -vn "$file" "$pub"
	fi
done < <(find other sources -type f 2>/dev/null)