-
Notifications
You must be signed in to change notification settings - Fork 15
/
db-functions-svn
106 lines (88 loc) · 2.96 KB
/
db-functions-svn
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
#!/hint/bash
if [[ -n ${SVNUSER} ]]; then
setfacl -m u:"${SVNUSER}":rwx "${WORKDIR}"
setfacl -m d:u:"${USER}":rwx "${WORKDIR}"
setfacl -m d:u:"${SVNUSER}":rwx "${WORKDIR}"
fi
arch_svn() {
if [[ -z ${SVNUSER} ]]; then
/usr/bin/svn "${@}"
else
sudo -u "${SVNUSER}" -- /usr/bin/svn --username "${USER}" "${@}"
fi
}
# source_pkgbuild pkgbase tag
#
# Source the PKGBUILD from the package's git/svn/whatever repo.
# Depending on how the VCS is used the tag might be "trunk" or "repos/$repo-$arch"
# or the full package version (epoch:pkgver-pkgrel) or any other recognized tag.
source_pkgbuild() {
local pkgbase=${1}
local tag=${2}
. <(arch_svn cat "${SVNREPO}/${pkgbase}/${tag}/PKGBUILD" 2>/dev/null || echo "false")
}
# Export PKGBUILD resource(s) from the package's git/svn/whatever repo.
# Depending on how the VCS is used the tag might be "trunk" or "repos/$repo-$arch"
# or the full package version (epoch:pkgver-pkgrel) or any other recognized tag.
export_from_vcs() {
local pkgbase=${1}
local tag=${2}
local src=${3}
local dest=${4}
if [[ ! -e ${dest} ]]; then
mkdir -p "${dest%/?*}"
arch_svn export -q "${SVNREPO}/${pkgbase}/${tag}/${src}" "${dest}" 2>/dev/null
fi
}
# Which repo is this package in?
find_repo_for_package() {
local pkgbase=${1}
local pkgarch=${2}
local candidates=("${@:3}")
local repos=($(arch_svn ls "${SVNREPO}/${pkgbase}/repos/" | grep -xFf \
<(printf '%s\n' "${candidates[@]/%/-${pkgarch}/}" "${candidates[@]/%/-any/}")))
#TODO: check the PKGBUILD exists?
if (( ${#repos[@]} > 1 )); then
die "%s is present in multiple repos (%s)" "${pkgbase}" "${repos[*]}"
fi
(( ${#repos[@]} == 1 )) || return $?
printf '%s\n' "${repos[@]%/}"
}
# Commit changes staged by (successive?) vcs_(re)?move_package runs.
vcs_commit() {
arch_svn commit -q "${WORKDIR}/svn/${pkgbase}" -m "${1}"
}
# Write to the VCS in order to track a package moving between different pacman
# repositories.
vcs_move_package() {
local pkgbase=${1}
local vcsrepo_from=${WORKDIR}/svn/${pkgbase}/repos/${2}
local vcsrepo_to=${WORKDIR}/svn/${pkgbase}/repos/${3}
if [[ ! -d ${WORKDIR}/svn ]]; then
arch_svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null
fi
arch_svn up -q "${WORKDIR}/svn/${pkgbase}" >/dev/null
if [[ -d ${vcsrepo_to} ]]; then
while read -r file; do
arch_svn rm -q "${vcsrepo_to}/${file}@"
done < <(arch_svn ls "${vcsrepo_to}")
else
mkdir "${vcsrepo_to}"
arch_svn add -q "${vcsrepo_to}"
fi
while read -r file; do
arch_svn mv -q -r HEAD "${vcsrepo_from}/${file}@" "${vcsrepo_to}/"
done < <(arch_svn ls "${vcsrepo_from}")
arch_svn rm --force -q "${vcsrepo_from}"
}
# Write to the VCS in order to track a package being deleted from a pacman
# repository.
vcs_remove_package() {
local pkgbase=${1}
local vcsrepo=${WORKDIR}/svn/${pkgbase}/repos/${2}
if [[ ! -d ${WORKDIR}/svn ]]; then
arch_svn checkout -q -N "${SVNREPO}" "${WORKDIR}/svn" >/dev/null
fi
arch_svn up -q "${WORKDIR}/svn/${pkgbase}" > /dev/null
arch_svn rm --force -q "${vcsrepo}"
}