summaryrefslogtreecommitdiff
path: root/src/xbs-abs/helper-abs
blob: 0471c8132442ed46a37f4e34c1032ce1d4de30ff (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
#!/bin/bash

#   Copyright (c) 2013 Luke Shumaker <lukeshu@sbcglobal.net>
#   For code from db-functions (arch_svn):
#     Copyright (c) 2012 Pierre Schmitz <pierre@archlinux.de>
#   For code from db-move+db-remove (move+unrelease):
#     Copyright (c) 2008-2009 Aaron Griffin <aaronmgriffin@gmail.com>
#     Copyright (c) 2009 Abhishek Dasgupta <abhidg@gmail.com>
#     Copyright (c) 2009, 2011 Dan McGee <dan@archlinux.org>
#     Copyright (c) 2009-2012 Pierre Schmitz <pierre@archlinux.de>
#   For code just from db-move (move):
#     Copyright (c) 2011 Rémy Oudompheng <remyoudompheng@gmail.com>
#     Copyright (c) 2012 Florian Pritz <bluewind@xinu.at>
#   For code just from db-remove (unrelease):
#     Copyright (c) 2009 Eric Bélanger <snowmaniscool@gmail.com>
#     Copyright (c) 2011 Florian Pritz <bluewind@xinu.at>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

load_config() {
	. $(librelib conf.sh)
	load_files xbs-abs
	check_vars SVNURL SVNREPO ARCHES || exit 1
}

# This is taken from dbscripts:db-fuctions
arch_svn() {
	if [[ -z "${SVNUSER}" ]]; then
		/usr/bin/svn "${@}"
	else
		sudo -u "${SVNUSER}" -- /usr/bin/svn --username "${USER}" "${@}"
	fi
}

status() {
	load_config
	[[ -z $(arch_svn status -q) ]]
}

download() {
	load_config
	if [[ -d "$SVNREPO/.svn" ]]; then
		arch_svn -q up "$SVNREPO"/*
	else
		# checkout non-recursive, then lazy load
		# nescessary because:
		#  > DO NOT CHECK OUT THE ENTIRE SVN REPO. Your address may be blocked.
		arch_svn -q checkout -N "$SVNURL" "$SVNREPO"
	fi
}

release() {
	local repo=$1
	local arch=$2

	"${0}.d/archrelease" -f "${repo}-${arch}"
}

unrelease() {
	local pkgbase=$1
	local repo=$2
	local arch=$3

	local svnrepo="$repo-$arch"
	load_config

	arch_svn up -q "${SVNREPO}/${pkgbase}"

	# This is based off code from dbscripts:db-remove
	remove_pkgs=$(. "${SVNREPO}/$pkgbase/repos/$svnrepo/PKGBUILD"; echo ${pkgname[@]})
	arch_svn rm --force -q "${SVNREPO}/$pkgbase/repos/$svnrepo"
	arch_svn commit -q "${SVNREPO}/$pkgbase" -m "${0##*/}: $pkgbase removed by $(id -un)"
}

move() {
	local repo_from=$1
	local repo_to=$2
	local pkgbase=$3

	load_config
	arch_svn up -q "${SVNREPO}/${pkgbase}"

	local tag_list=""
	local pkgarch
	local arches=()
	# this is based off code from dbscripts:db-move
	for pkgarch in "${ARCHES[@]}" 'any'; do
		dir_from="${SVNREPO}/${pkgbase}/repos/${repo_from}-${pkgarch}"
		dir_to="${SVNREPO}/${pkgbase}/repos/${repo_to}-${pkgarch}"

		if [ -f "${dir_from}/PKGBUILD" ]; then
			if [ -d "${dir_to}" ]; then
				for file in $(arch_svn ls "${dir_to}"); do
					arch_svn rm -q "${dir_to}/$file@"
				done
			else
				mkdir "${dir_to}"
				arch_svn add -q "${dir_to}"
			fi

			for file in $(arch_svn ls "${dir_from}"); do
				arch_svn mv -q -r HEAD "${dir_from}/$file@" "${dir_to}/"
			done
			arch_svn rm --force -q "${dir_from}"
			tag_list="$tag_list, $pkgarch"
			arches+=("$pkgarch")
		fi
	done
	tag_list="${tag_list#, }"
	arch_svn commit -q "${SVNREPO}/${pkgbase}" -m "${0##*/}: moved ${pkgbase} from [${repo_from}] to [${repo_to}] (${tag_list})"
	echo "${arches[*]}"
}

releasepath() {
	local pkgbase=$1
	local repo=$2
	local arch=$3

	load_config
	arch_svn up -q "${SVNREPO}/${pkgbase}"
	echo "${SVNREPO}/${pkgbase}/repos/${repo}-${arch}"
}

case "$1" in
	status|download|release|unrelease|move|releasepath) "$@";;
	*) exit 127;;
esac