summaryrefslogtreecommitdiff
path: root/pbs-plumb-download
blob: 1ba4e689d2105e949c5619a76c8f518c77208f92 (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
#!/bin/bash -e

#   Copyright (c) 2012-2013 Pacman Development Team <pacman-dev@archlinux.org>
#   Copyright (c) 2012-2013 Luke Shumaker <lukeshu@sbcglobal.net>
#
#   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/>.

. libremessages

usage() {
	echo "Usage: ${0##*/} SOURCE"
	echo "Downloads a source as configured in pbs-convert.conf"
}

main() {
	in_array '-h' "$@" && { usage; return 0; }
	[[ $# != 1 ]] && { usage; return 1; }
	local source=$1
	local url="$(pbs-plumb-config get "source.$source.url")"

	local cachedir="$(pbs-plumb-config get core.cachedir)"
	[[ -d "${cachedir}" ]] || mkdir -p "${cachedir}"

	if [[ ! -d "${cachedir}/${source}.git" ]]; then
		cd "${cachedir}"
		msg "$(gettext "Cloning %s")" "${cachedir}/${source}.git"
		if ! git clone --mirror "$url" "$source.git"; then
		    error "$(gettext "Failed to download source %s")" "$source"
		    exit 1
		fi
	else
		cd "${cachedir}/${source}.git"
		# Make sure we are fetching the right repo
		if [[ "$url" != "$(git config --get remote.origin.url)" ]] ; then
			error "$(gettext "%s is not a clone of %s")" "$source" "$url"
			plain "$(gettext "Aborting...")"
			exit 1
		fi
		msg "$(gettext "Updating %s")" "${cachedir}/${source}.git"
		if ! git fetch --all -p; then
		    error "$(gettext "Failed to update source %s")" "$source"
		    exit 1
		fi
	fi
}

main "$@"