summaryrefslogtreecommitdiff
path: root/src/xbs-abslibre/helper-abslibre
blob: ce21b991da6fbc71ab81efe2f1543694eab4dd5b (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
143
#!/usr/bin/env bash

# Copyright (C) 2012-2013 Luke Shumaker <lukeshu@sbcglobal.net>
#
# License: GNU GPLv2+
#
# 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/>.

status() {
	[[ -z $(git status -s .) ]]
}

download() {
	. $(librelib conf)
	load_files libretools
	check_vars libretools WORKDIR ABSLIBRERECV ABSLIBRESEND || return 1

	gitget -f -p "$ABSLIBRESEND" checkout "$ABSLIBRERECV" "$WORKDIR/abslibre" || return 1
}

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

	. libremessages
	. $(librelib conf)
	load_files libretools
	check_vars libretools WORKDIR ABSLIBREDEST || return 1
	local pkgbase="$(load_PKGBUILD; printf '%s\n' "${pkgbase:-${pkgname}}")"
	local pkgdir="${ABSLIBREDEST}/${arch}/${repo}/${pkgbase}"

	lock 9 "${ABSLIBREDEST}/${arch}.lock" "Waiting for a lock on the ABSLibre release directory for ${arch}"

	if [[ -e $pkgdir ]]; then
		rm -rf -- "$pkgdir"
	fi
	mkdir -p -- "$pkgdir"
	git ls-files -z | xargs -0 -I{} cp {} "$pkgdir"

	if [[ -e "${ABSLIBREDEST}/${arch}/.git" ]]; then
		cd "$pkgdir"
		git add .
		git commit -q -m "xbs-abslibre: Release ${repo}/${pkgbase} for ${arch} (by $(id -un))"
	fi
}

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

	. libremessages
	. $(librelib conf)
	load_files libretools
	check_vars libretools ABSLIBREDEST || return 1

	local pkgbase="$(load_PKGBUILD; printf '%s\n' "${pkgbase:-${pkgname}}")"
	local pkgdir="${ABSLIBREDEST}/${arch}/${repo}/${pkgbase}"

	lock 9 "${ABSLIBREDEST}/${arch}.lock" "Waiting for a lock on the ABSLibre release directory for ${arch}"

	if [[ -f "${pkgdir}/PKGBUILD" ]]; then
		if [[ -e "${ABSLIBREDEST}/${arch}/.git" ]]; then
			git rm -qrf -- "$pkgdir"
			git commit -q -m "xbs-abslibre: Remove ${repo}/${pkgbase} from ${arch} (by $(id -un))"
		else
			rm -rf -- "$pkgdir"
		fi
	fi
}

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

	. libremessages
	. $(librelib conf)
	load_files libretools
	check_vars libretools ABSLIBREDEST ARCHES || return 1

	local mv
	local arch
	for arch in "${ARCHES[@]}" any; do
		lock 9 "${ABSLIBREDEST}/${arch}.lock" "Waiting for a lock on the ABSLibre release directory for ${arch}"

		local dir_from="${ABSLIBREDEST}/${arch}/${repo_from}/${pkgbase}"
		local dir_to="${ABSLIBREDEST}/${arch}/${repo_to}/${pkgbase}"

		if [[ -f "${dir_from}/PKGBUILD" ]]; then
			if [[ -e "${ABSLIBREDEST}/${arch}/.git" ]]; then
				if [[ -e "${dir_to}" ]]; then
					git rm -qrf -- "$dir_to"
				fi
				mkdir -p -- "${dir_to%/*}"
				git mv -- "$dir_from" "$dir_to"
				git commit -q -m "xbs-abslibre: Move ${pkgbase} from ${repo_from} to ${repo_to} on ${arch} (by $(id -un))"
			else
				rm -rf -- "$dir_to"
				mkdir -p -- "${dir_to%/*}"
				mv "$dir_from" "$dir_to"
			fi
		fi
		lock_close 9
	done
}

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

	. libremessages
	. $(librelib conf)
	load_files libretools
	check_vars libretools ABSLIBREDEST || return 1
	local pkgdir="${ABSLIBREDEST}/${arch}/${repo}/${pkgbase}"

	lock 9 "${ABSLIBREDEST}/${arch}.lock" "Waiting for a lock on the ABSLibre release directory for ${arch}"

	if [[ -f "${pkgdir}/PKGBUILD" ]]; then
		printf '%s\n' "$pkgdir"
		return 0
	fi

	return 1
}

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