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

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

if (( $# >= 1 )); then
	warning "Calling %s with a specific repository is no longer supported" "${0##*/}"
	exit 1
fi

pushd "${STAGING}" >/dev/null
while read -d '' -r file; do
	pub="${FTP_BASE}/${file}"
	if [[ -f "$pub" ]]; then
		if cmp -s -- "$pub" "$file"; then
			rm -vf -- "$file"
		else
			warning "file already exists: %s" "$file"
		fi
	else
		mkdir -p -- "${pub%/*}"
		mv -vn "$file" "$pub"
	fi
done < <(find other sources -type f -print0 2>/dev/null)
popd >/dev/null

# Find repos with packages to release
mapfile -t -d '' repos < <(
	for f in "${STAGING}"/**/*${PKGEXTS}; do
		repo=${f%/*}
		repo=${repo##*/}
		if in_array "$repo" "${PKGREPOS[@]}"; then
			printf '%s\0' "$repo"
		fi
	done | sort -uz
)

# 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

# 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}/${repo}/"*${PKGEXTS}))
	if (( $? == 0 )); then
		for pkg in "${pkgs[@]}"; do
			if [[ -h ${pkg} ]]; then
				# As a special hack for
				#  1. inheriting arch=(any) packages between db-import
				#     upstreams, and
				#  2. re-adding previously removed binaries that have not been
				#     cleaned up yet,
				# allow symlinks that point to packages under ${FTP_BASE}/pool/.
				if [[ -f ${pkg} && "$(readlink -f -- "$pkg")" = "${FTP_BASE}"/pool/*${PKGEXTS} ]]; then
					continue
				fi
				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 ! pacman-key -v "${pkg}.sig" >/dev/null 2>&1; then
				die "Package %s does not have a valid signature" "$repo/${pkg##*/}"
			fi
			if ! check_pkgvcs "${pkg}" "${repo}"; then
				die "Package %s is not consistent with %s repository" "$repo/${pkg##*/}" "$VCS"
			fi
			if ! check_pkgrepos "${pkg}"; then
				die "Package %s already exists in another repository" "$repo/${pkg##*/}"
			fi
			if ! check_packager "${pkg}"; then
				if [[ $DBSCRIPTS_CONFIG = *.archlinux32 ]]; then
					warning "Package %s does not have a valid packager" "$repo/${pkg##*/}"
				else
					die "Package %s does not have a valid packager" "$repo/${pkg##*/}"
				fi
			fi
			if ! check_buildinfo "${pkg}"; then
				if [[ $DBSCRIPTS_CONFIG = *.archlinuxarm ]]; then
					warning "Package %s does not have a .BUILDINFO file" "$repo/${pkg##*/}"
				else
					die "Package %s does not have a .BUILDINFO file" "$repo/${pkg##*/}"
				fi
			fi
			if ! check_builddir "${pkg}"; then
				if [[ $DBSCRIPTS_CONFIG = *.archlinuxarm ]]; then
					warning "Package %s was not built in a chroot" "$repo/${pkg##*/}"
				else
					die "Package %s was not built in a chroot" "$repo/${pkg##*/}"
				fi
			fi
		done
		if ! check_splitpkgs "${repo}" "${pkgs[@]}"; then
			die "Missing split packages for %s" "$repo"
		fi
	else
		die "Could not read %s" "$STAGING"
	fi
done

for repo in "${repos[@]}"; do
	msg "Updating [%s]..." "$repo"
	any_pkgs=($(getpkgfiles "${STAGING}/${repo}/"*-any${PKGEXTS} 2>/dev/null))
	for pkgarch in "${ARCHES[@]}"; do
		add_pkgs=()
		arch_pkgs=($(getpkgfiles "${STAGING}/${repo}/"*"-${pkgarch}"${PKGEXTS} 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_ln "${pkg}" "$FTP_BASE/${PKGPOOL}"
			fi
			ln -s "../../../${PKGPOOL}/${pkgfile}" "$FTP_BASE/$repo/os/${pkgarch}"
			# also move signatures
			if [[ -f ${pkg}.sig ]]; then
				mv_ln "${pkg}.sig" "$FTP_BASE/${PKGPOOL}"
			fi
			if [[ -f $FTP_BASE/${PKGPOOL}/${pkgfile}.sig ]]; then
				ln -s "../../../${PKGPOOL}/${pkgfile}.sig" "$FTP_BASE/$repo/os/${pkgarch}"
			fi
			add_pkgs+=("${pkgfile}")
		done
		if (( ${#add_pkgs[@]} >= 1 )); then
			arch_repo_modify add "${repo}" "${pkgarch}" "${add_pkgs[@]}"
		fi
	done
done

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

find "$STAGING" -depth -mindepth 1 -type d -empty -exec rmdir -- {} \;